|
|
|
@ -2,6 +2,9 @@ export const REQUEST_TYPE_POST = 'POST';
|
|
|
|
|
export const REQUEST_TYPE_GET = 'GET';
|
|
|
|
|
export const REQUEST_TYPE_PUT = 'PUT';
|
|
|
|
|
export const REQUEST_TYPE_DELETE = 'DELETE';
|
|
|
|
|
export const TASK_PAGE_CREATE = 'createNewPage';
|
|
|
|
|
export const TASK_PAGE_EDIT = 'editPage';
|
|
|
|
|
export const TASK_PAGE_DELETE = 'deletePage';
|
|
|
|
|
export const CONTENT_TYPE_JSON = 'json';
|
|
|
|
|
export const CONTENT_TYPE_FORM = 'x-www-form-urlencoded';
|
|
|
|
|
export const API_STATUS = '/api/v1/auth/status';
|
|
|
|
@ -83,11 +86,20 @@ export default class APIUtils {
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
settingsImageUpload(type, files) {
|
|
|
|
|
imageUpload(type, files) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
let url = '';
|
|
|
|
|
let eventType = DataEvent.API_IMAGES_UPLOAD;
|
|
|
|
|
type == 'avatar-upload' ? (url = API_UPLOAD_AVATAR) : (url = API_UPLOAD_BACKGROUND);
|
|
|
|
|
switch (type) {
|
|
|
|
|
case 'avatar-upload':
|
|
|
|
|
url = API_UPLOAD_AVATAR;
|
|
|
|
|
break;
|
|
|
|
|
case 'background-upload':
|
|
|
|
|
url = API_UPLOAD_BACKGROUND;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
url = API_IMAGE_UPLOAD;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
var imageData = new FormData();
|
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
|
|
|
var file = files[i];
|
|
|
|
@ -95,11 +107,21 @@ export default class APIUtils {
|
|
|
|
|
if (!file.type.match('image.*')) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
type == 'avatar-upload'
|
|
|
|
|
? imageData.append('avatar_upload', file, file.name)
|
|
|
|
|
: imageData.append('background_upload', file, file.name);
|
|
|
|
|
if (type === 'avatar-upload') {
|
|
|
|
|
imageData.append('avatar_upload', file, file.name);
|
|
|
|
|
} else if (type === 'background-upload') {
|
|
|
|
|
imageData.append('background_upload', file, file.name);
|
|
|
|
|
} else {
|
|
|
|
|
imageData.append('post_image', file, file.name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this._request(url, eventType, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, imageData)
|
|
|
|
|
this._request(
|
|
|
|
|
url,
|
|
|
|
|
DataEvent.API_IMAGES_UPLOAD,
|
|
|
|
|
REQUEST_TYPE_POST,
|
|
|
|
|
CONTENT_TYPE_FORM,
|
|
|
|
|
imageData
|
|
|
|
|
)
|
|
|
|
|
.then(r => {
|
|
|
|
|
resolve(r);
|
|
|
|
|
})
|
|
|
|
@ -126,43 +148,32 @@ export default class APIUtils {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pageEdit(url, data) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(url, DataEvent.API_PAGE_WRITE, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, data)
|
|
|
|
|
.then(result => {
|
|
|
|
|
resolve(result);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
pageDelete(data) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(
|
|
|
|
|
API_DELETE_PAGE,
|
|
|
|
|
DataEvent.API_PAGE_DELETE,
|
|
|
|
|
REQUEST_TYPE_POST,
|
|
|
|
|
CONTENT_TYPE_JSON,
|
|
|
|
|
data
|
|
|
|
|
)
|
|
|
|
|
.then(result => {
|
|
|
|
|
resolve(result);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
pageImageUpload(file) {
|
|
|
|
|
pageActions(task, data) {
|
|
|
|
|
let url, event, content;
|
|
|
|
|
switch (task) {
|
|
|
|
|
case TASK_PAGE_CREATE:
|
|
|
|
|
url = API_NEW_PAGE;
|
|
|
|
|
event = DataEvent.API_PAGE_WRITE;
|
|
|
|
|
content = CONTENT_TYPE_FORM;
|
|
|
|
|
break;
|
|
|
|
|
case TASK_PAGE_EDIT:
|
|
|
|
|
url = API_EDIT_PAGE;
|
|
|
|
|
event = DataEvent.API_PAGE_WRITE;
|
|
|
|
|
content = CONTENT_TYPE_FORM;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TASK_PAGE_DELETE:
|
|
|
|
|
url = API_DELETE_PAGE;
|
|
|
|
|
event = DataEvent.API_PAGE_DELETE;
|
|
|
|
|
content = CONTENT_TYPE_JSON;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(
|
|
|
|
|
API_IMAGE_UPLOAD,
|
|
|
|
|
DataEvent.API_IMAGES_UPLOAD,
|
|
|
|
|
REQUEST_TYPE_POST,
|
|
|
|
|
CONTENT_TYPE_FORM,
|
|
|
|
|
file
|
|
|
|
|
)
|
|
|
|
|
this._request(url, event, REQUEST_TYPE_POST, content, data)
|
|
|
|
|
.then(result => {
|
|
|
|
|
resolve(result);
|
|
|
|
|
})
|
|
|
|
|