edited and commented methods for Utility API, removed DataEvents class

pull/84/head
Ro 3 years ago
parent 8101b16cf9
commit f7e3b3b55e

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_UPLOAD_BACKGROUND = "/api/v1/settings/add-feature-background";
export const API_IMAGE_UPLOAD = "/api/v1/page/add-entry-image"; export const API_IMAGE_UPLOAD = "/api/v1/page/add-entry-image";
//** API TASKS **// //** API TASKS **//
export const AUTH_STATUS = "getAuthStatus";
export const TASK_SITE_INIT = "blogInit"; 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_GET_SECRET = "retrieveSecret";
export const TASK_RESET_PASS = "resetPassword"; export const TASK_RESET_PASS = "resetPassword";
export const TASK_GET_CONTENT = "retrieveContent"; export const TASK_UPLOAD_FILES = "uploadFiles";
import * as DataEvent from "../com/events/DataEvent";
/** /**
* FipamoUtilityAPI * Fipamo Utility API
* Maintenance methods
*/ */
export default class FipamoUtilityAPI { export default class FipamoUtilityAPI {
//--------------------------
// constructor
//--------------------------
/** /**
* @constructor * @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) { create(data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this._request( 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) { restore(form) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var url, event, method, type, data; 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) => { return new Promise((resolve, reject) => {
var url, event, method, type, data; var url, event, method, type, data;
if (id === "create-backup") { url = API_CREATE_BACKUP;
url = API_CREATE_BACKUP; event = TASK_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 {
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) this._request(url, event, method, type, data)
.then((result) => { .then((result) => {
resolve(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) { secret(data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this._request( 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) { newPass(data) {
return new Promise((resolve, reject) => { 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) { imageUpload(type, files) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let url = ""; let url = "";
@ -185,7 +195,7 @@ export default class FipamoUtilityAPI {
} }
this._request( this._request(
url, url,
DataEvent.API_IMAGES_UPLOAD, TASK_UPLOAD_FILES,
REQUEST_TYPE_POST, REQUEST_TYPE_POST,
CONTENT_TYPE_FORM, CONTENT_TYPE_FORM,
imageData imageData

Loading…
Cancel
Save