merge master into develop - CscListRForm.jsp FAQ 아코디언 버그 수정
This commit is contained in:
48
build/resources/main/static/ckeditor/uploadAdapter.js
Normal file
48
build/resources/main/static/ckeditor/uploadAdapter.js
Normal file
@@ -0,0 +1,48 @@
|
||||
class UploadAdapter {
|
||||
constructor(loader, url) {
|
||||
this.loader = loader;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
upload() {
|
||||
return this.loader.file.then( file => new Promise(((resolve, reject) => {
|
||||
this._initRequest();
|
||||
this._initListeners( resolve, reject, file );
|
||||
this._sendRequest( file );
|
||||
})))
|
||||
}
|
||||
|
||||
_initRequest() {
|
||||
const xhr = this.xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', this.url, true);
|
||||
xhr.responseType = 'json';
|
||||
}
|
||||
|
||||
_initListeners(resolve, reject, file) {
|
||||
const xhr = this.xhr;
|
||||
const loader = this.loader;
|
||||
const genericErrorText = '파일을 업로드 할 수 없습니다.'
|
||||
|
||||
xhr.addEventListener('error', () => {reject(genericErrorText)})
|
||||
xhr.addEventListener('abort', () => reject())
|
||||
xhr.addEventListener('load', () => {
|
||||
const response = xhr.response
|
||||
if(!response || response.error) {
|
||||
return reject( response && response.error ? response.error.message : genericErrorText );
|
||||
}
|
||||
|
||||
resolve({
|
||||
default: response.url
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
_sendRequest(file) {
|
||||
const data = new FormData()
|
||||
data.append('upload',file)
|
||||
this.xhr.send(data)
|
||||
}
|
||||
}
|
||||
function getDownloadUrl(item) {
|
||||
return encodeURI(`${API_ROOT_URL}/download/images/${item.linkId}`);
|
||||
}
|
||||
Reference in New Issue
Block a user