clean up API, re-connected API to front end, base template tweak
parent
083faa7c1d
commit
5ad1118244
@ -0,0 +1,70 @@
|
|||||||
|
{
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 7,
|
||||||
|
"sourceType": "module",
|
||||||
|
"ecmaFeatures": {}
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"constructor-super": 2,
|
||||||
|
"for-direction": 2,
|
||||||
|
"getter-return": 2,
|
||||||
|
"no-case-declarations": 2,
|
||||||
|
"no-class-assign": 2,
|
||||||
|
"no-compare-neg-zero": 2,
|
||||||
|
"no-cond-assign": 2,
|
||||||
|
"no-console": 1,
|
||||||
|
"no-const-assign": 2,
|
||||||
|
"no-constant-condition": 2,
|
||||||
|
"no-control-regex": 1,
|
||||||
|
"no-debugger": 2,
|
||||||
|
"no-delete-var": 2,
|
||||||
|
"no-dupe-args": 2,
|
||||||
|
"no-dupe-class-members": 2,
|
||||||
|
"no-dupe-keys": 2,
|
||||||
|
"no-duplicate-case": 2,
|
||||||
|
"no-empty": 2,
|
||||||
|
"no-empty-character-class": 2,
|
||||||
|
"no-empty-pattern": 2,
|
||||||
|
"no-ex-assign": 2,
|
||||||
|
"no-extra-boolean-cast": 2,
|
||||||
|
"no-extra-semi": 2,
|
||||||
|
"no-fallthrough": 2,
|
||||||
|
"no-func-assign": 2,
|
||||||
|
"no-global-assign": 2,
|
||||||
|
"no-inner-declarations": 2,
|
||||||
|
"no-invalid-regexp": 2,
|
||||||
|
"no-irregular-whitespace": 2,
|
||||||
|
"no-mixed-spaces-and-tabs": 2,
|
||||||
|
"no-new-symbol": 2,
|
||||||
|
"no-obj-calls": 2,
|
||||||
|
"no-octal": 2,
|
||||||
|
"no-redeclare": 2,
|
||||||
|
"no-regex-spaces": 2,
|
||||||
|
"no-self-assign": 2,
|
||||||
|
"no-sparse-arrays": 2,
|
||||||
|
"no-this-before-super": 2,
|
||||||
|
"no-undef": 2,
|
||||||
|
"no-unexpected-multiline": 2,
|
||||||
|
"no-unreachable": 2,
|
||||||
|
"no-unsafe-finally": 2,
|
||||||
|
"no-unsafe-negation": 2,
|
||||||
|
"no-unused-labels": 2,
|
||||||
|
"no-unused-vars": 2,
|
||||||
|
"no-useless-escape": 1,
|
||||||
|
"require-yield": 2,
|
||||||
|
"use-isnan": 2,
|
||||||
|
"valid-typeof": 2,
|
||||||
|
"no-duplicate-imports": 2
|
||||||
|
},
|
||||||
|
"env": {
|
||||||
|
"node": true,
|
||||||
|
"browser": true,
|
||||||
|
"es6": true
|
||||||
|
},
|
||||||
|
"globals": {
|
||||||
|
"_": false,
|
||||||
|
"hljs": false,
|
||||||
|
"Sortable": false,
|
||||||
|
"Prism": false
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
import Base from './Base';
|
import Base from "./Base";
|
||||||
|
|
||||||
document.addEventListener(
|
document.addEventListener(
|
||||||
'DOMContentLoaded',
|
"DOMContentLoaded",
|
||||||
function () {
|
function () {
|
||||||
new Base();
|
new Base();
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
|
@ -1,121 +1,138 @@
|
|||||||
export const REQUEST_TYPE_POST = 'POST';
|
export const REQUEST_TYPE_POST = "POST";
|
||||||
export const REQUEST_TYPE_GET = 'GET';
|
export const REQUEST_TYPE_GET = "GET";
|
||||||
export const REQUEST_TYPE_PUT = 'PUT';
|
export const REQUEST_TYPE_PUT = "PUT";
|
||||||
export const REQUEST_TYPE_DELETE = 'DELETE';
|
export const REQUEST_TYPE_DELETE = "DELETE";
|
||||||
export const CONTENT_TYPE_JSON = 'json';
|
export const CONTENT_TYPE_JSON = "json";
|
||||||
export const CONTENT_TYPE_FORM = 'x-www-form-urlencoded';
|
export const CONTENT_TYPE_FORM = "x-www-form-urlencoded";
|
||||||
export const API_STATUS = '/api/v1/auth/status';
|
export const API_STATUS = "/api/v1/status";
|
||||||
export const API_INIT = '/api/v1/auth/init';
|
export const API_INIT = "/api/v1/init";
|
||||||
export const API_LOGIN = '/api/v1/auth/login';
|
export const API_LOGIN = "/api/v1/login";
|
||||||
export const API_GET_PAGES = '/api/v1/page/published';
|
export const API_GET_PAGES = "/api/v1/page/published";
|
||||||
export const API_GET_PAGE = '/api/v1/page/single';
|
export const API_GET_PAGE = "/api/v1/page/single";
|
||||||
import * as DataEvent from '../com/events/DataEvent';
|
import * as DataEvent from "../com/events/DataEvent";
|
||||||
export default class APIUtils {
|
export default class APIUtils {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// constructor
|
// constructor
|
||||||
//--------------------------
|
//--------------------------
|
||||||
constructor() {}
|
constructor() {}
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// public
|
// public
|
||||||
//--------------------------
|
//--------------------------
|
||||||
login(data) {
|
login(data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._request(
|
this._request(
|
||||||
API_LOGIN,
|
API_LOGIN,
|
||||||
DataEvent.AUTH_STATUS,
|
DataEvent.AUTH_STATUS,
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_JSON,
|
CONTENT_TYPE_JSON,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
.then(result => {
|
.then((result) => {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
init(data) {
|
init(data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._request(API_INIT, DataEvent.API_INIT, REQUEST_TYPE_POST, CONTENT_TYPE_JSON, data)
|
this._request(
|
||||||
.then(result => {
|
API_INIT,
|
||||||
resolve(result);
|
DataEvent.API_INIT,
|
||||||
})
|
REQUEST_TYPE_POST,
|
||||||
.catch(err => {
|
CONTENT_TYPE_JSON,
|
||||||
reject(err);
|
data
|
||||||
});
|
)
|
||||||
});
|
.then((result) => {
|
||||||
}
|
resolve(result);
|
||||||
getPages(num) {
|
})
|
||||||
let pageNum = num;
|
.catch((err) => {
|
||||||
if (pageNum === null || pageNum === '' || !pageNum) pageNum = 1;
|
reject(err);
|
||||||
return new Promise((resolve, reject) => {
|
});
|
||||||
this._request(API_GET_PAGES + '/' + pageNum, DataEvent.API_GET_PAGES, REQUEST_TYPE_GET)
|
});
|
||||||
.then(result => {
|
}
|
||||||
resolve(result);
|
getPages(num) {
|
||||||
})
|
let pageNum = num;
|
||||||
.catch(err => {
|
if (pageNum === null || pageNum === "" || !pageNum) pageNum = 1;
|
||||||
reject(err);
|
return new Promise((resolve, reject) => {
|
||||||
});
|
this._request(
|
||||||
});
|
API_GET_PAGES + "/" + pageNum,
|
||||||
}
|
DataEvent.API_GET_PAGES,
|
||||||
|
REQUEST_TYPE_GET
|
||||||
|
)
|
||||||
|
.then((result) => {
|
||||||
|
resolve(result);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
getPage(id) {
|
getPage(id) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._request(API_GET_PAGE + '/' + id, DataEvent.API_GET_PAGES, REQUEST_TYPE_GET)
|
this._request(
|
||||||
.then(result => {
|
API_GET_PAGE + "/" + id,
|
||||||
resolve(result);
|
DataEvent.API_GET_PAGES,
|
||||||
})
|
REQUEST_TYPE_GET
|
||||||
.catch(err => {
|
)
|
||||||
reject(err);
|
.then((result) => {
|
||||||
});
|
resolve(result);
|
||||||
});
|
})
|
||||||
}
|
.catch((err) => {
|
||||||
//--------------------------
|
reject(err);
|
||||||
// private
|
});
|
||||||
//--------------------------
|
});
|
||||||
_request(
|
}
|
||||||
requestURL,
|
//--------------------------
|
||||||
eventType,
|
// private
|
||||||
requestType = REQUEST_TYPE_GET,
|
//--------------------------
|
||||||
contentType = CONTENT_TYPE_JSON,
|
_request(
|
||||||
requestData = null
|
requestURL,
|
||||||
) {
|
eventType,
|
||||||
var self = this;
|
requestType = REQUEST_TYPE_GET,
|
||||||
return new Promise(function (resolve, reject) {
|
contentType = CONTENT_TYPE_JSON,
|
||||||
var request = new XMLHttpRequest();
|
requestData = null
|
||||||
request.upload.onprogress = self.handleLoadProgress;
|
) {
|
||||||
request.open(requestType, requestURL, true);
|
var self = this;
|
||||||
request.onload = () => {
|
return new Promise(function (resolve, reject) {
|
||||||
if (request.status == 200) {
|
var request = new XMLHttpRequest();
|
||||||
let response = JSON.parse(request['response']);
|
request.upload.onprogress = self.handleLoadProgress;
|
||||||
resolve(response);
|
request.open(requestType, requestURL, true);
|
||||||
} else {
|
request.onload = () => {
|
||||||
let error = JSON.parse(request['response']);
|
if (request.status == 200) {
|
||||||
reject(error);
|
let response = JSON.parse(request["response"]);
|
||||||
}
|
resolve(response);
|
||||||
};
|
} else {
|
||||||
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
|
let error = JSON.parse(request["response"]);
|
||||||
switch (contentType) {
|
reject(error);
|
||||||
case CONTENT_TYPE_JSON:
|
}
|
||||||
request.setRequestHeader('Content-type', 'application/' + contentType);
|
};
|
||||||
request.send(JSON.stringify(requestData));
|
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
|
||||||
break;
|
switch (contentType) {
|
||||||
case CONTENT_TYPE_FORM:
|
case CONTENT_TYPE_JSON:
|
||||||
request.send(requestData);
|
request.setRequestHeader(
|
||||||
break;
|
"Content-type",
|
||||||
}
|
"application/" + contentType
|
||||||
} else {
|
);
|
||||||
request.send();
|
request.send(JSON.stringify(requestData));
|
||||||
}
|
break;
|
||||||
});
|
case CONTENT_TYPE_FORM:
|
||||||
}
|
request.send(requestData);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
request.send();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// event handlers
|
// event handlers
|
||||||
//--------------------------
|
//--------------------------
|
||||||
handleLoadProgress(e) {
|
handleLoadProgress(e) {
|
||||||
this.percentComplete = Math.ceil((e.loaded / e.total) * 100);
|
this.percentComplete = Math.ceil((e.loaded / e.total) * 100);
|
||||||
//pass element to display request progress
|
//pass element to display request progress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,325 +1,328 @@
|
|||||||
export const REQUEST_TYPE_POST = 'POST';
|
export const REQUEST_TYPE_POST = "POST";
|
||||||
export const REQUEST_TYPE_GET = 'GET';
|
export const REQUEST_TYPE_GET = "GET";
|
||||||
export const REQUEST_TYPE_PUT = 'PUT';
|
export const REQUEST_TYPE_PUT = "PUT";
|
||||||
export const REQUEST_TYPE_DELETE = 'DELETE';
|
export const REQUEST_TYPE_DELETE = "DELETE";
|
||||||
export const TASK_PAGE_CREATE = 'createNewPage';
|
export const TASK_PAGE_CREATE = "createNewPage";
|
||||||
export const TASK_PAGE_EDIT = 'editPage';
|
export const TASK_PAGE_EDIT = "editPage";
|
||||||
export const TASK_PAGE_DELETE = 'deletePage';
|
export const TASK_PAGE_DELETE = "deletePage";
|
||||||
export const CONTENT_TYPE_JSON = 'json';
|
export const CONTENT_TYPE_JSON = "json";
|
||||||
export const CONTENT_TYPE_FORM = 'x-www-form-urlencoded';
|
export const CONTENT_TYPE_FORM = "x-www-form-urlencoded";
|
||||||
export const API_STATUS = '/api/v1/auth/status';
|
export const API_STATUS = "/api/v1/status";
|
||||||
export const API_GET_NAV = '/api/settings/nav';
|
export const API_GET_NAV = "/api/settings/nav";
|
||||||
export const API_NEW_PAGE = '/api/v1/page/write/new';
|
export const API_NEW_PAGE = "/api/v1/page/write/new";
|
||||||
export const API_EDIT_PAGE = '/api/v1/page/write';
|
export const API_EDIT_PAGE = "/api/v1/page/write";
|
||||||
export const API_DELETE_PAGE = '/api/v1/page/delete';
|
export const API_DELETE_PAGE = "/api/v1/page/delete";
|
||||||
export const API_IMAGE_UPLOAD = '/api/v1/page/add-post-image';
|
export const API_IMAGE_UPLOAD = "/api/v1/page/add-post-image";
|
||||||
export const API_SETTINGS_SYNC = '/api/v1/settings/sync';
|
export const API_SETTINGS_SYNC = "/api/v1/settings/sync";
|
||||||
export const API_UPLOAD_AVATAR = '/api/v1/settings/add-avatar';
|
export const API_UPLOAD_AVATAR = "/api/v1/settings/add-avatar";
|
||||||
export const API_UPLOAD_BACKGROUND = '/api/v1/settings/add-feature-background';
|
export const API_UPLOAD_BACKGROUND = "/api/v1/settings/add-feature-background";
|
||||||
export const API_PUBLISH_PAGES = '/api/v1/settings/publish-pages';
|
export const API_PUBLISH_PAGES = "/api/v1/settings/publish-pages";
|
||||||
export const API_NAV_SYNC = '/api/v1/settings/nav-sync';
|
export const API_NAV_SYNC = "/api/v1/settings/nav-sync";
|
||||||
export const API_REINDEX_PAGES = '/api/v1/settings/reindex';
|
export const API_REINDEX_PAGES = "/api/v1/settings/reindex";
|
||||||
export const API_CREATE_BACKUP = '/api/v1/backup/create';
|
export const API_CREATE_BACKUP = "/api/v1/backup/create";
|
||||||
export const API_DOWNLOAD_BACKUP = '/api/v1/backup/download';
|
export const API_DOWNLOAD_BACKUP = "/api/v1/backup/download";
|
||||||
export const API_RESTORE_BACKUP = '/api/v1/backup/restore';
|
export const API_RESTORE_BACKUP = "/api/v1/backup/restore";
|
||||||
export const API_INIT_RESTORE_BACKUP = '/api/v1/backup/init-restore';
|
export const API_INIT_RESTORE_BACKUP = "/api/v1/backup/init-restore";
|
||||||
export const API_SEND_MAIL = '/api/v1/mailer';
|
export const API_SEND_MAIL = "/api/v1/mailer";
|
||||||
import * as DataEvent from '../com/events/DataEvent';
|
import * as DataEvent from "../com/events/DataEvent";
|
||||||
export default class APIUtils {
|
export default class APIUtils {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// constructor
|
// constructor
|
||||||
//--------------------------
|
//--------------------------
|
||||||
constructor() {
|
constructor() {
|
||||||
this.percentComplete = 0;
|
this.percentComplete = 0;
|
||||||
this.token = null;
|
this.token = null;
|
||||||
//checks backend to see if user is logged in
|
//checks backend to see if user is logged in
|
||||||
//and requests encrypted token for api calls
|
//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) {
|
if (response.type === DataEvent.API_REQUEST_GOOD) {
|
||||||
this.token = response.token;
|
this.token = response.token;
|
||||||
} else {
|
} else {
|
||||||
//don't set token
|
//don't set token
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// public
|
// public
|
||||||
//--------------------------
|
//--------------------------
|
||||||
syncSettings(data) {
|
syncSettings(data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._request(
|
this._request(
|
||||||
API_SETTINGS_SYNC,
|
API_SETTINGS_SYNC,
|
||||||
DataEvent.API_SETTINGS_WRITE,
|
DataEvent.API_SETTINGS_WRITE,
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_JSON,
|
CONTENT_TYPE_JSON,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
.then(result => {
|
.then((result) => {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
imageUpload(type, files) {
|
imageUpload(type, files) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let url = '';
|
let url = "";
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'avatar-upload':
|
case "avatar-upload":
|
||||||
url = API_UPLOAD_AVATAR;
|
url = API_UPLOAD_AVATAR;
|
||||||
break;
|
break;
|
||||||
case 'background-upload':
|
case "background-upload":
|
||||||
url = API_UPLOAD_BACKGROUND;
|
url = API_UPLOAD_BACKGROUND;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
url = API_IMAGE_UPLOAD;
|
url = API_IMAGE_UPLOAD;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var imageData = new FormData();
|
var imageData = new FormData();
|
||||||
for (var i = 0; i < files.length; i++) {
|
for (var i = 0; i < files.length; i++) {
|
||||||
var file = files[i];
|
var file = files[i];
|
||||||
// Check the file type.
|
// Check the file type.
|
||||||
if (!file.type.match('image.*')) {
|
if (!file.type.match("image.*")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (type === 'avatar-upload') {
|
if (type === "avatar-upload") {
|
||||||
imageData.append('avatar_upload', file, file.name);
|
imageData.append("avatar_upload", file, file.name);
|
||||||
} else if (type === 'background-upload') {
|
} else if (type === "background-upload") {
|
||||||
imageData.append('background_upload', file, file.name);
|
imageData.append("background_upload", file, file.name);
|
||||||
} else {
|
} else {
|
||||||
imageData.append('post_image', file, file.name);
|
imageData.append("post_image", file, file.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._request(
|
this._request(
|
||||||
url,
|
url,
|
||||||
DataEvent.API_IMAGES_UPLOAD,
|
DataEvent.API_IMAGES_UPLOAD,
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_FORM,
|
CONTENT_TYPE_FORM,
|
||||||
imageData
|
imageData
|
||||||
)
|
)
|
||||||
.then(r => {
|
.then((r) => {
|
||||||
resolve(r);
|
resolve(r);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
publishSite(data) {
|
publishSite(data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._request(
|
this._request(
|
||||||
API_PUBLISH_PAGES,
|
API_PUBLISH_PAGES,
|
||||||
DataEvent.API_RENDER_PAGES,
|
DataEvent.API_RENDER_PAGES,
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_JSON,
|
CONTENT_TYPE_JSON,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
.then(result => {
|
.then((result) => {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pageActions(task, data) {
|
pageActions(task, data) {
|
||||||
let url, event, content;
|
let url, event, content;
|
||||||
switch (task) {
|
switch (task) {
|
||||||
case TASK_PAGE_CREATE:
|
case TASK_PAGE_CREATE:
|
||||||
url = API_NEW_PAGE;
|
url = API_NEW_PAGE;
|
||||||
event = DataEvent.API_PAGE_WRITE;
|
event = DataEvent.API_PAGE_WRITE;
|
||||||
content = CONTENT_TYPE_FORM;
|
content = CONTENT_TYPE_FORM;
|
||||||
break;
|
break;
|
||||||
case TASK_PAGE_EDIT:
|
case TASK_PAGE_EDIT:
|
||||||
url = API_EDIT_PAGE;
|
url = API_EDIT_PAGE;
|
||||||
event = DataEvent.API_PAGE_WRITE;
|
event = DataEvent.API_PAGE_WRITE;
|
||||||
content = CONTENT_TYPE_FORM;
|
content = CONTENT_TYPE_FORM;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TASK_PAGE_DELETE:
|
case TASK_PAGE_DELETE:
|
||||||
url = API_DELETE_PAGE;
|
url = API_DELETE_PAGE;
|
||||||
event = DataEvent.API_PAGE_DELETE;
|
event = DataEvent.API_PAGE_DELETE;
|
||||||
content = CONTENT_TYPE_JSON;
|
content = CONTENT_TYPE_JSON;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._request(url, event, REQUEST_TYPE_POST, content, data)
|
this._request(url, event, REQUEST_TYPE_POST, content, data)
|
||||||
.then(result => {
|
.then((result) => {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
syncNav(data) {
|
syncNav(data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._request(
|
this._request(
|
||||||
API_NAV_SYNC,
|
API_NAV_SYNC,
|
||||||
DataEvent.API_SETTINGS_WRITE,
|
DataEvent.API_SETTINGS_WRITE,
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_JSON,
|
CONTENT_TYPE_JSON,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
.then(result => {
|
.then((result) => {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
sendMail(message) {
|
sendMail(message) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._request(
|
this._request(
|
||||||
API_SEND_MAIL,
|
API_SEND_MAIL,
|
||||||
DataEvent.SEND_MAIL,
|
DataEvent.SEND_MAIL,
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_JSON,
|
CONTENT_TYPE_JSON,
|
||||||
message
|
message
|
||||||
)
|
)
|
||||||
.then(result => {
|
.then((result) => {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
handleBackup(id, files) {
|
handleBackup(id, files) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var url, event, method, type, data;
|
var url, event, method, type, data;
|
||||||
|
|
||||||
if (id === 'create-backup') {
|
if (id === "create-backup") {
|
||||||
url = API_CREATE_BACKUP;
|
url = API_CREATE_BACKUP;
|
||||||
event = DataEvent.API_BACKUP_CREATE;
|
event = DataEvent.API_BACKUP_CREATE;
|
||||||
method = REQUEST_TYPE_POST;
|
method = REQUEST_TYPE_POST;
|
||||||
type = CONTENT_TYPE_JSON;
|
type = CONTENT_TYPE_JSON;
|
||||||
data = { task: 'create_backup' };
|
data = { task: "create_backup" };
|
||||||
} else {
|
} else {
|
||||||
url = API_RESTORE_BACKUP;
|
url = API_RESTORE_BACKUP;
|
||||||
event = DataEvent.API_BACKUP_RESTORE;
|
event = DataEvent.API_BACKUP_RESTORE;
|
||||||
method = REQUEST_TYPE_POST;
|
method = REQUEST_TYPE_POST;
|
||||||
type = CONTENT_TYPE_FORM;
|
type = CONTENT_TYPE_FORM;
|
||||||
data = new FormData();
|
data = new FormData();
|
||||||
for (var i = 0; i < files.length; i++) {
|
for (var i = 0; i < files.length; i++) {
|
||||||
var file = files[i];
|
var file = files[i];
|
||||||
// Check the file type.
|
// Check the file type.
|
||||||
if (!file.type.match('application.zip')) {
|
if (!file.type.match("application.zip")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
data.append('backup_upload', file, file.name);
|
data.append("backup_upload", file, file.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._request(url, event, method, type, data)
|
this._request(url, event, method, type, data)
|
||||||
.then(result => {
|
.then((result) => {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
handleInitRestore(form) {
|
handleInitRestore(form) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
var url, event, method, type, data;
|
var url, event, method, type, data;
|
||||||
|
|
||||||
url = API_INIT_RESTORE_BACKUP;
|
url = API_INIT_RESTORE_BACKUP;
|
||||||
event = DataEvent.API_BACKUP_RESTORE;
|
event = DataEvent.API_BACKUP_RESTORE;
|
||||||
method = REQUEST_TYPE_POST;
|
method = REQUEST_TYPE_POST;
|
||||||
type = CONTENT_TYPE_FORM;
|
type = CONTENT_TYPE_FORM;
|
||||||
data = new FormData(form);
|
data = new FormData(form);
|
||||||
this._request(url, event, method, type, data)
|
this._request(url, event, method, type, data)
|
||||||
.then(result => {
|
.then((result) => {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleReindex(data) {
|
handleReindex(data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this._request(
|
this._request(
|
||||||
API_REINDEX_PAGES,
|
API_REINDEX_PAGES,
|
||||||
DataEvent.API_REINDEX_PAGES,
|
DataEvent.API_REINDEX_PAGES,
|
||||||
REQUEST_TYPE_POST,
|
REQUEST_TYPE_POST,
|
||||||
CONTENT_TYPE_JSON,
|
CONTENT_TYPE_JSON,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
.then(result => {
|
.then((result) => {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// private
|
// private
|
||||||
//--------------------------
|
//--------------------------
|
||||||
_request(
|
_request(
|
||||||
requestURL,
|
requestURL,
|
||||||
eventType,
|
eventType,
|
||||||
requestType = REQUEST_TYPE_GET,
|
requestType = REQUEST_TYPE_GET,
|
||||||
contentType = CONTENT_TYPE_JSON,
|
contentType = CONTENT_TYPE_JSON,
|
||||||
requestData = null
|
requestData = null
|
||||||
) {
|
) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
request.upload.onprogress = self.handleLoadProgress;
|
request.upload.onprogress = self.handleLoadProgress;
|
||||||
request.open(requestType, requestURL, true);
|
request.open(requestType, requestURL, true);
|
||||||
request.onload = () => {
|
request.onload = () => {
|
||||||
if (request.status == 200) {
|
if (request.status == 200) {
|
||||||
let response = JSON.parse(request['response']);
|
let response = JSON.parse(request["response"]);
|
||||||
resolve(response);
|
resolve(response);
|
||||||
} else {
|
} else {
|
||||||
let error = JSON.parse(request['response']);
|
let error = JSON.parse(request["response"]);
|
||||||
reject(error);
|
reject(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
|
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
|
||||||
if (
|
if (
|
||||||
eventType === DataEvent.API_PAGE_WRITE ||
|
eventType === DataEvent.API_PAGE_WRITE ||
|
||||||
eventType === DataEvent.API_IMAGES_UPLOAD ||
|
eventType === DataEvent.API_IMAGES_UPLOAD ||
|
||||||
eventType === DataEvent.API_SETTINGS_WRITE ||
|
eventType === DataEvent.API_SETTINGS_WRITE ||
|
||||||
eventType === DataEvent.API_PAGE_DELETE ||
|
eventType === DataEvent.API_PAGE_DELETE ||
|
||||||
eventType === DataEvent.API_RENDER_PAGES ||
|
eventType === DataEvent.API_RENDER_PAGES ||
|
||||||
eventType === DataEvent.API_BACKUP_CREATE ||
|
eventType === DataEvent.API_BACKUP_CREATE ||
|
||||||
eventType === DataEvent.API_BACKUP_RESTORE ||
|
eventType === DataEvent.API_BACKUP_RESTORE ||
|
||||||
eventType === DataEvent.API_REINDEX_PAGES
|
eventType === DataEvent.API_REINDEX_PAGES
|
||||||
)
|
)
|
||||||
request.setRequestHeader('x-access-token', self.token);
|
request.setRequestHeader("x-access-token", self.token);
|
||||||
|
|
||||||
switch (contentType) {
|
switch (contentType) {
|
||||||
case CONTENT_TYPE_JSON:
|
case CONTENT_TYPE_JSON:
|
||||||
request.setRequestHeader('Content-type', 'application/' + contentType);
|
request.setRequestHeader(
|
||||||
request.send(JSON.stringify(requestData));
|
"Content-type",
|
||||||
break;
|
"application/" + contentType
|
||||||
case CONTENT_TYPE_FORM:
|
);
|
||||||
request.send(requestData);
|
request.send(JSON.stringify(requestData));
|
||||||
break;
|
break;
|
||||||
}
|
case CONTENT_TYPE_FORM:
|
||||||
} else {
|
request.send(requestData);
|
||||||
request.send();
|
break;
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
}
|
request.send();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------
|
//--------------------------
|
||||||
// event handlers
|
// event handlers
|
||||||
//--------------------------
|
//--------------------------
|
||||||
handleLoadProgress(e) {
|
handleLoadProgress(e) {
|
||||||
this.percentComplete = Math.ceil((e.loaded / e.total) * 100);
|
this.percentComplete = Math.ceil((e.loaded / e.total) * 100);
|
||||||
//pass element to display request progress
|
//pass element to display request progress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "codekit-project",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"lockfileVersion": 1,
|
||||||
|
"requires": true,
|
||||||
|
"dependencies": {
|
||||||
|
"animejs": {
|
||||||
|
"version": "3.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/animejs/-/animejs-3.2.1.tgz",
|
||||||
|
"integrity": "sha512-sWno3ugFryK5nhiDm/2BKeFCpZv7vzerWUcUPyAZLDhMek3+S/p418ldZJbJXo5ZUOpfm2kP2XRO4NJcULMy9A=="
|
||||||
|
},
|
||||||
|
"caret-pos": {
|
||||||
|
"version": "2.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/caret-pos/-/caret-pos-2.0.0.tgz",
|
||||||
|
"integrity": "sha512-cOIiBS1SjzXg+LXSiQAzGg89dHDKq/y4c30+tB5hkVN7GbtXh1BNypOmjti4LwAWQrvP4y+bNG7RJFxLGoL3bA=="
|
||||||
|
},
|
||||||
|
"sortablejs": {
|
||||||
|
"version": "1.13.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/sortablejs/-/sortablejs-1.13.0.tgz",
|
||||||
|
"integrity": "sha512-RBJirPY0spWCrU5yCmWM1eFs/XgX2J5c6b275/YyxFRgnzPhKl/TDeU2hNR8Dt7ITq66NRPM4UlOt+e5O4CFHg=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "fipamo-dash",
|
||||||
|
"version": "1.2.4",
|
||||||
|
"description": "Front end script for the most chill blog framework ever.",
|
||||||
|
"scripts": {},
|
||||||
|
"author": "Are0h",
|
||||||
|
"license": "UNLICENSED",
|
||||||
|
"repository": "https://code.playvicio.us/Are0h/Fipamo",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"animejs": "^3.2.1",
|
||||||
|
"caret-pos": "^2.0.0",
|
||||||
|
"sortablejs": "^1.13.0"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue