29 lines
740 B
JavaScript
29 lines
740 B
JavaScript
const config = require('./config.js');
|
|
const path = require('path');
|
|
const fs = require('fs-extra');
|
|
|
|
module.exports = {
|
|
async write(stream, options) {
|
|
const storage = config.storage[options.type];
|
|
|
|
if (!storage) return;
|
|
|
|
const src = path.join(storage.root, options.path);
|
|
const fileSrc = path.join(src, options.fileName);
|
|
|
|
await fs.mkdir(src, {recursive: true});
|
|
|
|
const writeStream = fs.createWriteStream(fileSrc);
|
|
writeStream.on('open', () => writeStream.write(stream));
|
|
writeStream.on('finish', () => writeStream.end());
|
|
|
|
return new Promise(resolve => {
|
|
writeStream.on('close', () => resolve());
|
|
});
|
|
},
|
|
|
|
load(type, data) {
|
|
|
|
}
|
|
};
|