Merge pull request #68 from tycrek/new-data-engine-injection

pull/69/head
Josh Moore 3 years ago committed by GitHub
commit 7419498ea4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -347,34 +347,7 @@ ass is intended to provide a strong backend for developers to build their own fr
A Papito data engine implements support for one type of database (or file, such as JSON or YAML). This lets ass server hosts pick their database of choice, because all they'll have to do is enter the connection/authentication details, and ass will handle the rest, using the resource ID as the key.
The only engine ass comes with by default is **JSON**. If you find or create an engine you like, you can use it by installing it with `npm i <package-name>` then changing the contents of [`data.js`]. The engines own README file should also instruct how to use it. At this time, a modified `data.js` might look like this:
```js
/**
* Used for global data management
*/
//const { JsonStorageEngine } = require('@tycrek/papito');
const { CustomStorageEngine } = require('my-custom-papito');
//const data = new JsonStorageEngine();
// StorageEngines may take no parameters...
const data1 = new CustomStorageEngine();
// multiple parameters...
const data2 = new CustomStorageEngine('Parameters!!', 420);
// or object-based parameters, depending on what the StorageEngine dev decides on.
const data3 = new CustomStorageEngine({ key1: 'value1', key2: { key3: 44 } });
module.exports = data1;
```
As long as the engine properly implements `GET`/`PUT`/`DEL`/`HAS` StorageFunctions, replacing the file/database system is just that easy.
**For a detailed walkthrough on developing engines, [consult the wiki][ctw2].**
**~~For a detailed walkthrough on developing engines, [consult the wiki][ctw2].~~ Outdated!**
[`data.js`]: https://github.com/tycrek/ass/blob/master/data.js
[ctw2]: https://github.com/tycrek/ass/wiki/Writing-a-StorageEngine

@ -2,6 +2,11 @@
* Used for global data management
*/
// Old data
const { JsonDataEngine } = require('@tycrek/papito');
const data = new JsonDataEngine();
module.exports = data;
// Actual data engine
const { dataEngine } = require('./config.json');
const { _ENGINE_ } = require(dataEngine);
module.exports = _ENGINE_(new JsonDataEngine());

14
package-lock.json generated

@ -12,7 +12,7 @@
"@tycrek/express-nofavicon": "^1.0.2",
"@tycrek/isprod": "^2.0.2",
"@tycrek/log": ">=0.5.x",
"@tycrek/papito": "^0.3.1",
"@tycrek/papito": "^0.3.4",
"any-shell-escape": "^0.1.1",
"aws-sdk": "^2.930.0",
"check-node-version": "^4.1.0",
@ -598,9 +598,9 @@
}
},
"node_modules/@tycrek/papito": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/@tycrek/papito/-/papito-0.3.1.tgz",
"integrity": "sha512-hhUMqe+rLIMeLEDERq8LoL20wAaEJMF3RH2nONpiz4ihkUjzLyuRwc6DDayyJkrzIdJVohLWcSK3vV3icJ2RCw==",
"version": "0.3.4",
"resolved": "https://registry.npmjs.org/@tycrek/papito/-/papito-0.3.4.tgz",
"integrity": "sha512-P5sQAJQOeirCzpphU6tXqjiCUmJf+A8T/1iJkpWu/uLq30lHyKjIoOeCXnW92b3hdDDxO1ruanxX2muJZTPQdA==",
"dependencies": {
"fs-extra": "^10.0.0"
},
@ -4109,9 +4109,9 @@
}
},
"@tycrek/papito": {
"version": "0.3.1",
"resolved": "https://registry.npmjs.org/@tycrek/papito/-/papito-0.3.1.tgz",
"integrity": "sha512-hhUMqe+rLIMeLEDERq8LoL20wAaEJMF3RH2nONpiz4ihkUjzLyuRwc6DDayyJkrzIdJVohLWcSK3vV3icJ2RCw==",
"version": "0.3.4",
"resolved": "https://registry.npmjs.org/@tycrek/papito/-/papito-0.3.4.tgz",
"integrity": "sha512-P5sQAJQOeirCzpphU6tXqjiCUmJf+A8T/1iJkpWu/uLq30lHyKjIoOeCXnW92b3hdDDxO1ruanxX2muJZTPQdA==",
"requires": {
"fs-extra": "^10.0.0"
},

@ -38,7 +38,7 @@
"@tycrek/express-nofavicon": "^1.0.2",
"@tycrek/isprod": "^2.0.2",
"@tycrek/log": ">=0.5.x",
"@tycrek/papito": "^0.3.1",
"@tycrek/papito": "^0.3.4",
"any-shell-escape": "^0.1.1",
"aws-sdk": "^2.930.0",
"check-node-version": "^4.1.0",

@ -12,6 +12,7 @@ const config = {
spaceReplace: '_',
mediaStrict: false,
viewDirect: false,
dataEngine: '@tycrek/papito',
frontendName: 'ass-x',
indexFile: '',
s3enabled: false,
@ -159,6 +160,12 @@ function doSetup() {
default: config.viewDirect,
required: false
},
dataEngine: {
description: 'Data engine to use (must match an NPM package name. If unsure, leave blank)',
type: 'string',
default: config.dataEngine,
required: false
},
frontendName: {
description: 'Name of your frontend (leave blank if not using frontends)',
type: 'string',

Loading…
Cancel
Save