|
|
|
@ -27,7 +27,7 @@ export default class APIUtils {
|
|
|
|
|
this.token = null;
|
|
|
|
|
//checks backend to see if user is logged in
|
|
|
|
|
//and requests encrypted token for api calls
|
|
|
|
|
this.request(API_STATUS).then(response => {
|
|
|
|
|
this._request(API_STATUS).then(response => {
|
|
|
|
|
if (response.type === DataEvent.API_REQUEST_GOOD) {
|
|
|
|
|
this.token = response.token;
|
|
|
|
|
} else {
|
|
|
|
@ -36,10 +36,163 @@ export default class APIUtils {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//--------------------------
|
|
|
|
|
// methods
|
|
|
|
|
// public
|
|
|
|
|
//--------------------------
|
|
|
|
|
//TODO: Make 'private' class
|
|
|
|
|
request(
|
|
|
|
|
login(data) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(
|
|
|
|
|
API_LOGIN,
|
|
|
|
|
DataEvent.AUTH_STATUS,
|
|
|
|
|
REQUEST_TYPE_POST,
|
|
|
|
|
CONTENT_TYPE_JSON,
|
|
|
|
|
data
|
|
|
|
|
)
|
|
|
|
|
.then(result => {
|
|
|
|
|
resolve(result);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
init(data) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(API_INIT, DataEvent.API_INIT, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, data)
|
|
|
|
|
.then(result => {
|
|
|
|
|
resolve(result);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
syncSettings(data) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(
|
|
|
|
|
API_SETTINGS_SYNC,
|
|
|
|
|
DataEvent.API_SETTINGS_WRITE,
|
|
|
|
|
REQUEST_TYPE_POST,
|
|
|
|
|
CONTENT_TYPE_JSON,
|
|
|
|
|
data
|
|
|
|
|
)
|
|
|
|
|
.then(result => {
|
|
|
|
|
resolve(result);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
settingsImageUpload(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);
|
|
|
|
|
var imageData = new FormData();
|
|
|
|
|
for (var i = 0; i < files.length; i++) {
|
|
|
|
|
var file = files[i];
|
|
|
|
|
// Check the file type.
|
|
|
|
|
if (!file.type.match('image.*')) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
type == 'avatar-upload'
|
|
|
|
|
? imageData.append('avatar_upload', file, file.name)
|
|
|
|
|
: imageData.append('background_upload', file, file.name);
|
|
|
|
|
}
|
|
|
|
|
this._request(url, eventType, REQUEST_TYPE_POST, CONTENT_TYPE_FORM, imageData)
|
|
|
|
|
.then(r => {
|
|
|
|
|
resolve(r);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
publishSite(data) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(
|
|
|
|
|
API_PUBLISH_PAGES,
|
|
|
|
|
DataEvent.API_RENDER_PAGES,
|
|
|
|
|
REQUEST_TYPE_POST,
|
|
|
|
|
CONTENT_TYPE_JSON,
|
|
|
|
|
data
|
|
|
|
|
)
|
|
|
|
|
.then(result => {
|
|
|
|
|
resolve(result);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(
|
|
|
|
|
API_IMAGE_UPLOAD,
|
|
|
|
|
DataEvent.API_IMAGES_UPLOAD,
|
|
|
|
|
REQUEST_TYPE_POST,
|
|
|
|
|
CONTENT_TYPE_FORM,
|
|
|
|
|
file
|
|
|
|
|
)
|
|
|
|
|
.then(result => {
|
|
|
|
|
resolve(result);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
syncNav(data) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
this._request(
|
|
|
|
|
API_NAV_SYNC,
|
|
|
|
|
DataEvent.API_SETTINGS_WRITE,
|
|
|
|
|
REQUEST_TYPE_POST,
|
|
|
|
|
CONTENT_TYPE_JSON,
|
|
|
|
|
data
|
|
|
|
|
)
|
|
|
|
|
.then(result => {
|
|
|
|
|
resolve(result);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
//--------------------------
|
|
|
|
|
// private
|
|
|
|
|
//--------------------------
|
|
|
|
|
_request(
|
|
|
|
|
requestURL,
|
|
|
|
|
eventType,
|
|
|
|
|
requestType = REQUEST_TYPE_GET,
|
|
|
|
|