fixed image upload request that required token authorization

This commit is contained in:
Ro 2021-08-02 15:13:46 -07:00
parent 7d3f2d13a4
commit cad32ace74
4 changed files with 34 additions and 15 deletions

View file

@ -146,5 +146,5 @@
{% endblock %}
{% block javascripts %}
<script src="/assets/scripts/dash.min.js" type="text/javascript"></script>
<script src="/assets/scripts/dash.min.js?" type="text/javascript"></script>
{% endblock %}

File diff suppressed because one or more lines are too long

View file

@ -25,21 +25,39 @@ export const TASK_BACKUP_CREATE = "createBackup";
export const TASK_GET_SECRET = "retrieveSecret";
export const TASK_RESET_PASS = "resetPassword";
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.
*/
class FipamoUtilityAPI {
class MaintenanceManager {
/**
* @constructor
* @param {string} baseURL - url of site; uses local when empty
* @param {string} key - user api key
*/
constructor(baseURL = null, key = null) {
this.percentComplete = 0; //for later
this.token = null;
this.baseURL = null;
this.key = null;
if (key) this.key = key;
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 (eventType === TASK_UPLOAD_FILES)
request.setRequestHeader("fipamo-access-token", self.token);
switch (contentType) {
case CONTENT_TYPE_JSON:
request.setRequestHeader(
"Content-type",
"application/" + contentType
);
/**
request.setRequestHeader(
"Access-Control-Allow-Origin",
self.baseURL
);
**/
request.send(JSON.stringify(requestData));
break;
case CONTENT_TYPE_FORM:
@ -281,4 +295,4 @@ class FipamoUtilityAPI {
}
}
export { FipamoUtilityAPI as default };
export { MaintenanceManager as default };

View file

@ -18,6 +18,10 @@ export default class SettingsIndex {
null,
"fe79df250470815bf32dcea70221384c89163cad3a827a9c3da25d87159ed55a"
);
this.mm = new Maintenance(
null,
"fe79df250470815bf32dcea70221384c89163cad3a827a9c3da25d87159ed55a"
);
}
//--------------------------
// methods
@ -173,8 +177,9 @@ export default class SettingsIndex {
}
handleImageUpload(type, files) {
notify.alert("Uploading Image... ", null);
let mm = new Maintenance();
mm.imageUpload(type, files)
this.mm
.imageUpload(type, files)
.then((r) => {
if (r.type == DataEvent.AVATAR_UPLOADED) {
notify.alert(r.message, true);