more commenting for API classess, edited constructor for Admin and Util, updated backend API, added jsdoc

This commit is contained in:
Ro 2021-06-25 14:53:37 -07:00
parent ebdda2c089
commit b9056b64df
9 changed files with 253 additions and 43 deletions

View file

@ -8,13 +8,21 @@ class InitAPI
public static function handleInitTasks($task, $request)
{
switch ($task) {
case "init":
$result = Setup::init($request);
break;
case "restore":
$result = Setup::restore($request);
break;
//check if a site config already exists. if it does, deny set up request
//restore to previous version of site while a config exists is only accessible
//through settings.
if (Setup::status()) {
$result = ["type" => "blogInitFail", "message" => "Site already set up"];
} else {
switch ($task) {
case "init":
$result = Setup::init($request);
break;
case "restore":
$result = Setup::restore($request);
break;
}
}
return $result;

View file

@ -117,7 +117,21 @@ class APIControl
}
break;
case "login": //move to 'api/auth'
$result = AuthAPI::login($body);
//check if request is remote and if so, verify token
if ($body["remote"] || $body["remote"] == "true") {
if (Member::verifyKey($body["key"])) {
$result = AuthAPI::login($body);
} else {
$result = [
"message" => "API access denied, homie",
"type" => "API_ERROR",
];
}
} else {
//request is local, so it's cool
$result = AuthAPI::login($body);
}
break;
case "logout": //move to 'api/auth'
$result = AuthAPI::logout($body);

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,5 @@
import SettingsActions from "../actions/SettingsActions";
import FipamoAdminAPI from "../../libraries/FipamoAdminAPI";
import FipamoUtilityAPI from "../../libraries/FipamoUtilityAPI";
import * as DataEvent from "../../../src/com/events/DataEvent";
import Mailer from "../actions/Mailer";
import Notifications from "../ui/Notifications";

View file

@ -33,18 +33,21 @@ export const API_ACCESS_BAD = "apiNotConnected";
/**
* Fipamo Administration API
* Class for handling Fipamo dashboard tasks
* A pocket full of methods used to edit install settings, navigation pages.
*/
export default class FipamoAdminAPI {
class FipamoAdminAPI {
/**
* @constructor
*/
constructor() {
this.percentComplete = 0;
constructor(baseURL = null, key = null) {
this.percentComplete = 0; //for later
this.token = null;
//checks backend to see if user is logged in
//and requests encrypted token for api calls
this.baseURL = null;
this.key = null;
if (key) this.key = key;
if (baseURL) this.baseURL = baseURL;
//checks backend to see if user is logged in and requests encrypted token for api calls
this._request(API_STATUS).then((response) => {
if (response.type === API_ACCESS_GOOD) {
this.token = response.token;
@ -55,12 +58,18 @@ export default class FipamoAdminAPI {
}
/**
* Method for retrieving user authorizing user login
* @param {object} data - json object that contains data for set up
* @property {string} handle - handle for site user
* @property {string} password - password for site user
* @param {object} data - json object that contains data for set up
*/
login(data) {
return new Promise((resolve, reject) => {
if (this.baseURL) {
data.key = this.key;
data.remote = true;
} else {
data.remote = false;
}
this._request(
this.baseURL ? this.baseURL + API_LOGIN : API_LOGIN,
AUTH_STATUS,
@ -319,3 +328,5 @@ export default class FipamoAdminAPI {
//pass element to display request progress
}
}
export { FipamoAdminAPI as default };

View file

@ -20,13 +20,15 @@ export const TASK_GET_CONTENT = "retrieveContent";
/**
* Fipamo Content API
* class for retrieving page data from install
* A bag of methods for getting page info from an install.
* To use remotely, include url of install and user key found in settings.
*/
export default class FipamoAPI {
class FipamoContentAPI {
/**
* @constructor
* @param {string} baseURL - url of site; uses local when empty
* @param {string} key - user api key
* @author Ro
*/
constructor(baseURL = null, key = null) {
this.baseURL = null;
@ -34,13 +36,16 @@ export default class FipamoAPI {
if (key) this.key = key;
if (baseURL) this.baseURL = baseURL;
}
//--------------------------
// methods
//--------------------------
/**
* Method for retrieving page data
* @param {string} type - type of pages being retrieved; defaults to published
* Promise method for retrieving page data
* @param {string} type - type of pages being retrieved; null value defaults to published
* @example
* api.pages('published').then(pages=>{
* console.log("Pages Object", pages);
* })
* @returns {object} json object that contains pages of requested type
*
*/
pages(type = null) {
//set url based on request type
@ -71,8 +76,13 @@ export default class FipamoAPI {
});
}
/**
* Method for retrieving single page
* Promise method for retrieving single page
* @param {string} id - uuid of desired page
* @example
* api.page("a-uuid-for-a-page").then(page=>{
console.log("Page Object", page);
* })
* @returns {object} json object that contains data for requested page
*/
page(id) {
return new Promise((resolve, reject) => {
@ -93,7 +103,12 @@ export default class FipamoAPI {
}
/**
* Method for retrieving all tags used by pages
* Promise method for retrieving all tags used by pages
* @example
* api.tags().then(tags=>{
console.log("Tags Object", tags);
* })
* @returns {object} json object that contains tags used by pages
*/
tags() {
return new Promise((resolve, reject) => {
@ -164,3 +179,5 @@ export default class FipamoAPI {
//pass element to display request progress
}
}
export { FipamoContentAPI as default };

View file

@ -28,16 +28,23 @@ export const TASK_UPLOAD_FILES = "uploadFiles";
/**
* Fipamo Utility API
* Maintenance methods
* A tub of methods for creating/restoring installs, resetting passwords and uploading images.
*/
export default class FipamoUtilityAPI {
class FipamoUtilityAPI {
/**
* @constructor
* @param {string} baseURL - url of site; uses local when empty
* @param {string} key - user api key
*/
constructor() {}
constructor(baseURL = null, key = null) {
this.baseURL = null;
this.key = null;
if (key) this.key = key;
if (baseURL) this.baseURL = baseURL;
}
/**
* Method used create new site
* Promise method used create new site from scratch. For local use only.
* @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
@ -62,7 +69,7 @@ export default class FipamoUtilityAPI {
});
}
/**
* Method for restoring site from backup
* Promise method for restoring site from a previous back up. For local use only.
* @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
@ -87,7 +94,7 @@ export default class FipamoUtilityAPI {
});
}
/**
* Method for creating a backup zip
* Promise method for creating a zip back up of current site. For local use only.
*/
backup() {
@ -111,7 +118,7 @@ export default class FipamoUtilityAPI {
}
/**
* Method for retrieving user secret key
* Promise method for retrieving user secret key. For local use only.
* @param {object} data - json object that contains data for set up
* @property {string} email - email for site user
*/
@ -134,7 +141,7 @@ export default class FipamoUtilityAPI {
});
}
/**
* Method for resetting password for user
* Promise method for resetting password for user. For local use only.
* @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
@ -160,7 +167,7 @@ export default class FipamoUtilityAPI {
}
/**
* Method for uploading images [todo: change to uploading files]
* Promise method for uploading images [todo: change to uploading files]
* @param {string} type - type of upload
* @param {input} files - form input containing files
*/
@ -179,6 +186,14 @@ export default class FipamoUtilityAPI {
break;
}
var imageData = new FormData();
if (this.baseURL) {
imageData.append("key", this.key);
imageData.append("remote", true);
} else {
imageData.append("remote", false);
}
for (var i = 0; i < files.length; i++) {
var file = files[i];
// Check the file type.
@ -266,3 +281,5 @@ export default class FipamoUtilityAPI {
//pass element to display request progress
}
}
export { FipamoUtilityAPI as default };

152
src/package-lock.json generated
View file

@ -374,7 +374,6 @@
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
"integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
"dev": true,
"requires": {
"sprintf-js": "~1.0.2"
}
@ -391,6 +390,11 @@
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"dev": true
},
"bluebird": {
"version": "3.7.2",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz",
"integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg=="
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
@ -434,6 +438,14 @@
"resolved": "https://registry.npmjs.org/caret-pos/-/caret-pos-2.0.0.tgz",
"integrity": "sha512-cOIiBS1SjzXg+LXSiQAzGg89dHDKq/y4c30+tB5hkVN7GbtXh1BNypOmjti4LwAWQrvP4y+bNG7RJFxLGoL3bA=="
},
"catharsis": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/catharsis/-/catharsis-0.9.0.tgz",
"integrity": "sha512-prMTQVpcns/tzFgFVkVp6ak6RykZyWb3gu8ckUpd6YkTlacOd3DXGJjIpD4Q6zJirizvaiAjSSHlOsA+6sNh2A==",
"requires": {
"lodash": "^4.17.15"
}
},
"chalk": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.1.tgz",
@ -571,6 +583,11 @@
"ansi-colors": "^4.1.1"
}
},
"entities": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/entities/-/entities-2.0.3.tgz",
"integrity": "sha512-MyoZ0jgnLvB2X3Lg5HqpFmn1kybDiIfEQmKzTb5apr51Rb+T3KdmMiqa70T+bhGnyv7bQ6WMj2QMHpGMmlrUYQ=="
},
"escalade": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
@ -835,6 +852,11 @@
"type-fest": "^0.20.2"
}
},
"graceful-fs": {
"version": "4.2.6",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.6.tgz",
"integrity": "sha512-nTnJ528pbqxYanhpDYsi4Rd8MAeaBA67+RZ10CM1m3bTAVFEDcd5AuA4a6W5YkGZ1iNXHzZz8T6TBKLeBuNriQ=="
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
@ -920,6 +942,42 @@
"esprima": "^4.0.0"
}
},
"js2xmlparser": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/js2xmlparser/-/js2xmlparser-4.0.1.tgz",
"integrity": "sha512-KrPTolcw6RocpYjdC7pL7v62e55q7qOMHvLX1UCLc5AAS8qeJ6nukarEJAF2KL2PZxlbGueEbINqZR2bDe/gUw==",
"requires": {
"xmlcreate": "^2.0.3"
}
},
"jsdoc": {
"version": "3.6.7",
"resolved": "https://registry.npmjs.org/jsdoc/-/jsdoc-3.6.7.tgz",
"integrity": "sha512-sxKt7h0vzCd+3Y81Ey2qinupL6DpRSZJclS04ugHDNmRUXGzqicMJ6iwayhSA0S0DwwX30c5ozyUthr1QKF6uw==",
"requires": {
"@babel/parser": "^7.9.4",
"bluebird": "^3.7.2",
"catharsis": "^0.9.0",
"escape-string-regexp": "^2.0.0",
"js2xmlparser": "^4.0.1",
"klaw": "^3.0.0",
"markdown-it": "^10.0.0",
"markdown-it-anchor": "^5.2.7",
"marked": "^2.0.3",
"mkdirp": "^1.0.4",
"requizzle": "^0.2.3",
"strip-json-comments": "^3.1.0",
"taffydb": "2.6.2",
"underscore": "~1.13.1"
},
"dependencies": {
"escape-string-regexp": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz",
"integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w=="
}
}
},
"jsesc": {
"version": "2.5.2",
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz",
@ -945,6 +1003,14 @@
"minimist": "^1.2.5"
}
},
"klaw": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/klaw/-/klaw-3.0.0.tgz",
"integrity": "sha512-0Fo5oir+O9jnXu5EefYbVK+mHMBeEVEy2cmctR1O1NECcCkPRreJKrS6Qt/j3KC2C148Dfo9i3pCmCMsdqGr0g==",
"requires": {
"graceful-fs": "^4.1.9"
}
},
"levn": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz",
@ -955,6 +1021,19 @@
"type-check": "~0.4.0"
}
},
"linkify-it": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-2.2.0.tgz",
"integrity": "sha512-GnAl/knGn+i1U/wjBz3akz2stz+HrHLsxMwHQGofCDfPvlf+gDKN58UtfmUquTY4/MXeE2x7k19KQmeoZi94Iw==",
"requires": {
"uc.micro": "^1.0.1"
}
},
"lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"lodash.clonedeep": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
@ -982,6 +1061,38 @@
"yallist": "^4.0.0"
}
},
"markdown-it": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-10.0.0.tgz",
"integrity": "sha512-YWOP1j7UbDNz+TumYP1kpwnP0aEa711cJjrAQrzd0UXlbJfc5aAq0F/PZHjiioqDC1NKgvIMX+o+9Bk7yuM2dg==",
"requires": {
"argparse": "^1.0.7",
"entities": "~2.0.0",
"linkify-it": "^2.0.0",
"mdurl": "^1.0.1",
"uc.micro": "^1.0.5"
}
},
"markdown-it-anchor": {
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/markdown-it-anchor/-/markdown-it-anchor-5.3.0.tgz",
"integrity": "sha512-/V1MnLL/rgJ3jkMWo84UR+K+jF1cxNG1a+KwqeXqTIJ+jtA8aWSHuigx8lTzauiIjBDbwF3NcWQMotd0Dm39jA=="
},
"marked": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/marked/-/marked-2.1.2.tgz",
"integrity": "sha512-ueJhIvklJJw04qxQbGIAu63EXwwOCYc7yKMBjgagTM4rjC5QtWyqSNgW7jCosV1/Km/1TUfs5qEpAqcGG0Mo5g=="
},
"mdurl": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz",
"integrity": "sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4="
},
"minami": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/minami/-/minami-1.2.3.tgz",
"integrity": "sha1-mbbc37LwpU2hycj3qjoyd4eq+fg="
},
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
@ -996,6 +1107,11 @@
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
"integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
},
"mkdirp": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz",
"integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw=="
},
"ms": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
@ -1086,6 +1202,14 @@
"integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
"dev": true
},
"requizzle": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/requizzle/-/requizzle-0.2.3.tgz",
"integrity": "sha512-YanoyJjykPxGHii0fZP0uUPEXpvqfBDxWV7s6GKAiiOsiqhX6vHNyW3Qzdmqp/iq/ExbhaGbVrjB4ruEVSM4GQ==",
"requires": {
"lodash": "^4.17.14"
}
},
"resolve-from": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz",
@ -1180,8 +1304,7 @@
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=",
"dev": true
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
},
"string-width": {
"version": "4.2.2",
@ -1206,8 +1329,7 @@
"strip-json-comments": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
"integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==",
"dev": true
"integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig=="
},
"supports-color": {
"version": "5.5.0",
@ -1251,6 +1373,11 @@
}
}
},
"taffydb": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/taffydb/-/taffydb-2.6.2.tgz",
"integrity": "sha1-fLy2S1oUG2ou/CxdLGe04VCyomg="
},
"text-table": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
@ -1277,6 +1404,16 @@
"integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==",
"dev": true
},
"uc.micro": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz",
"integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA=="
},
"underscore": {
"version": "1.13.1",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.1.tgz",
"integrity": "sha512-hzSoAVtJF+3ZtiFX0VgfFPHEDRm7Y/QPjGyNo4TVdnDTdft3tr8hEkD25a1jC+TjTuE7tkHGKkhwCgs9dgBB2g=="
},
"uri-js": {
"version": "4.4.1",
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz",
@ -1313,6 +1450,11 @@
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"dev": true
},
"xmlcreate": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/xmlcreate/-/xmlcreate-2.0.3.tgz",
"integrity": "sha512-HgS+X6zAztGa9zIK3Y3LXuJes33Lz9x+YyTxgrkIdabu2vqcGOWwdfCpf1hWLRrd553wd4QCDf6BBO6FfdsRiQ=="
},
"yallist": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",

View file

@ -13,6 +13,8 @@
"animejs": "^3.2.1",
"bulma": "^0.9.2",
"caret-pos": "^2.0.0",
"jsdoc": "^3.6.7",
"minami": "^1.2.3",
"sortablejs": "^1.13.0"
},
"devDependencies": {