bin/helpers/content/index.js

26 lines
586 B
JavaScript
Raw Normal View History

2023-03-04 02:31:07 +01:00
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
const root = path.join(process.cwd(), '/usercontent');
console.log(root);
const make_id = () => {
return crypto.randomBytes(8).toString('hex');
};
async function get(id) {
2023-03-04 02:39:59 +01:00
return fs.readFileSync(path.join(root, id)).toString();
2023-03-04 02:31:07 +01:00
}
async function write(fname, data) {
2023-03-04 02:39:59 +01:00
return fs.writeFile(path.join(root, fname), data, () => {});
2023-03-04 02:31:07 +01:00
}
async function create(data) {
const id = make_id();
2023-03-04 02:39:59 +01:00
await write(id, data);
2023-03-04 02:31:07 +01:00
return id;
}
module.exports = { get, write, create, make_id };