edited and commented methods for Utility API, removed DataEvents class
This commit is contained in:
parent
8101b16cf9
commit
f7e3b3b55e
2 changed files with 53 additions and 43 deletions
8
public/assets/scripts/dash.min.js
vendored
8
public/assets/scripts/dash.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -19,33 +19,31 @@ export const API_UPLOAD_AVATAR = "/api/v1/settings/add-avatar";
|
|||
export const API_UPLOAD_BACKGROUND = "/api/v1/settings/add-feature-background";
|
||||
export const API_IMAGE_UPLOAD = "/api/v1/page/add-entry-image";
|
||||
//** API TASKS **//
|
||||
export const AUTH_STATUS = "getAuthStatus";
|
||||
export const TASK_SITE_INIT = "blogInit";
|
||||
export const TASK_BACKUP_RESTORE = "downloadBackup";
|
||||
export const TASK_BACKUP_RESTORE = "restoreBackup";
|
||||
export const TASK_BACKUP_CREATE = "createBackup";
|
||||
export const TASK_GET_SECRET = "retrieveSecret";
|
||||
export const TASK_RESET_PASS = "resetPassword";
|
||||
export const TASK_GET_CONTENT = "retrieveContent";
|
||||
|
||||
import * as DataEvent from "../com/events/DataEvent";
|
||||
export const TASK_UPLOAD_FILES = "uploadFiles";
|
||||
|
||||
/**
|
||||
* Fipamo Utility API
|
||||
* Maintenance methods
|
||||
*/
|
||||
export default class FipamoUtilityAPI {
|
||||
//--------------------------
|
||||
// constructor
|
||||
//--------------------------
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
constructor() {}
|
||||
//--------------------------
|
||||
// methods
|
||||
//--------------------------
|
||||
|
||||
//** MEMBER AUTH METHODS **//
|
||||
|
||||
/**
|
||||
* Method used create new site
|
||||
* @param {object} data - json object that contains data for set up
|
||||
* @property {string} new_member_handle - handle for new user
|
||||
* @property {string} new_member_email - email for new user
|
||||
* @property {string} new_member_pass - password for new user
|
||||
* @property {string} new_member_title - title for new user
|
||||
*/
|
||||
create(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this._request(
|
||||
|
@ -63,7 +61,13 @@ export default class FipamoUtilityAPI {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for restoring site from backup
|
||||
* @param {object} form - form object that contains restore data and files
|
||||
* @property {string} restore_member_handle - handle for site user
|
||||
* @property {string} restore_member_pass - password for site user
|
||||
* @property {file} backup-upload - backup zip file
|
||||
*/
|
||||
restore(form) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var url, event, method, type, data;
|
||||
|
@ -82,32 +86,20 @@ export default class FipamoUtilityAPI {
|
|||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Method for creating a backup zip
|
||||
*/
|
||||
|
||||
backup(id, files) {
|
||||
backup() {
|
||||
return new Promise((resolve, reject) => {
|
||||
var url, event, method, type, data;
|
||||
|
||||
if (id === "create-backup") {
|
||||
url = API_CREATE_BACKUP;
|
||||
event = DataEvent.API_BACKUP_CREATE;
|
||||
event = TASK_BACKUP_CREATE;
|
||||
method = REQUEST_TYPE_POST;
|
||||
type = CONTENT_TYPE_JSON;
|
||||
data = { task: "create_backup" };
|
||||
} else {
|
||||
url = API_RESTORE_BACKUP;
|
||||
event = DataEvent.API_BACKUP_RESTORE;
|
||||
method = REQUEST_TYPE_POST;
|
||||
type = CONTENT_TYPE_FORM;
|
||||
data = new FormData();
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
var file = files[i];
|
||||
// Check the file type.
|
||||
if (!file.type.match("application.zip")) {
|
||||
continue;
|
||||
}
|
||||
data.append("backup_upload", file, file.name);
|
||||
}
|
||||
}
|
||||
|
||||
this._request(url, event, method, type, data)
|
||||
.then((result) => {
|
||||
resolve(result);
|
||||
|
@ -118,6 +110,12 @@ export default class FipamoUtilityAPI {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for retrieving user secret key
|
||||
* @param {object} data - json object that contains data for set up
|
||||
* @property {string} email - email for site user
|
||||
*/
|
||||
|
||||
secret(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this._request(
|
||||
|
@ -135,6 +133,13 @@ export default class FipamoUtilityAPI {
|
|||
});
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Method for resetting password for user
|
||||
* @param {object} data - json object that contains data for set up
|
||||
* @property {string} new_password - password for user
|
||||
* @property {string} new_password2 - confirm password for user
|
||||
* @property {string} secret - secret key for user
|
||||
*/
|
||||
|
||||
newPass(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -154,6 +159,11 @@ export default class FipamoUtilityAPI {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for uploading images [todo: change to uploading files]
|
||||
* @param {string} type - type of upload
|
||||
* @param {input} files - form input containing files
|
||||
*/
|
||||
imageUpload(type, files) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let url = "";
|
||||
|
@ -185,7 +195,7 @@ export default class FipamoUtilityAPI {
|
|||
}
|
||||
this._request(
|
||||
url,
|
||||
DataEvent.API_IMAGES_UPLOAD,
|
||||
TASK_UPLOAD_FILES,
|
||||
REQUEST_TYPE_POST,
|
||||
CONTENT_TYPE_FORM,
|
||||
imageData
|
||||
|
|
Loading…
Reference in a new issue