|
|
@ -25,21 +25,39 @@ 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_UPLOAD_FILES = "uploadFiles";
|
|
|
|
export const TASK_UPLOAD_FILES = "uploadFiles";
|
|
|
|
|
|
|
|
//** API STATUS **//
|
|
|
|
|
|
|
|
export const API_ACCESS_GOOD = "apiUseAuthorized";
|
|
|
|
|
|
|
|
export const API_ACCESS_BAD = "apiUseNotAuthorized";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* A tub of methods for creating/restoring installs, resetting passwords and uploading images.
|
|
|
|
* A tub of methods for creating/restoring installs, resetting passwords and uploading images.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class FipamoUtilityAPI {
|
|
|
|
class MaintenanceManager {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @constructor
|
|
|
|
* @constructor
|
|
|
|
* @param {string} baseURL - url of site; uses local when empty
|
|
|
|
* @param {string} baseURL - url of site; uses local when empty
|
|
|
|
* @param {string} key - user api key
|
|
|
|
* @param {string} key - user api key
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
constructor(baseURL = null, key = null) {
|
|
|
|
constructor(baseURL = null, key = null) {
|
|
|
|
|
|
|
|
this.percentComplete = 0; //for later
|
|
|
|
|
|
|
|
this.token = null;
|
|
|
|
this.baseURL = null;
|
|
|
|
this.baseURL = null;
|
|
|
|
this.key = null;
|
|
|
|
this.key = null;
|
|
|
|
if (key) this.key = key;
|
|
|
|
if (key) this.key = key;
|
|
|
|
if (baseURL) this.baseURL = baseURL;
|
|
|
|
if (baseURL) this.baseURL = baseURL;
|
|
|
|
|
|
|
|
//if key is valid, checks to see if a session is active and returns
|
|
|
|
|
|
|
|
this._request(
|
|
|
|
|
|
|
|
this.baseURL
|
|
|
|
|
|
|
|
? this.baseURL + API_STATUS + "?key=" + this.key
|
|
|
|
|
|
|
|
: API_STATUS + "?key=" + this.key
|
|
|
|
|
|
|
|
).then((response) => {
|
|
|
|
|
|
|
|
if (response.type === API_ACCESS_GOOD) {
|
|
|
|
|
|
|
|
this.token = response.token;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//don't set token
|
|
|
|
|
|
|
|
//console.log("NO TOKEN");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -248,18 +266,14 @@ class FipamoUtilityAPI {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
|
|
|
|
if (requestType == REQUEST_TYPE_PUT || requestType == REQUEST_TYPE_POST) {
|
|
|
|
|
|
|
|
if (eventType === TASK_UPLOAD_FILES)
|
|
|
|
|
|
|
|
request.setRequestHeader("fipamo-access-token", self.token);
|
|
|
|
switch (contentType) {
|
|
|
|
switch (contentType) {
|
|
|
|
case CONTENT_TYPE_JSON:
|
|
|
|
case CONTENT_TYPE_JSON:
|
|
|
|
request.setRequestHeader(
|
|
|
|
request.setRequestHeader(
|
|
|
|
"Content-type",
|
|
|
|
"Content-type",
|
|
|
|
"application/" + contentType
|
|
|
|
"application/" + contentType
|
|
|
|
);
|
|
|
|
);
|
|
|
|
/**
|
|
|
|
|
|
|
|
request.setRequestHeader(
|
|
|
|
|
|
|
|
"Access-Control-Allow-Origin",
|
|
|
|
|
|
|
|
self.baseURL
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
request.send(JSON.stringify(requestData));
|
|
|
|
request.send(JSON.stringify(requestData));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case CONTENT_TYPE_FORM:
|
|
|
|
case CONTENT_TYPE_FORM:
|
|
|
@ -281,4 +295,4 @@ class FipamoUtilityAPI {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export { FipamoUtilityAPI as default };
|
|
|
|
export { MaintenanceManager as default };
|
|
|
|