Fixed 267U.pre2

This commit is contained in:
2026-07-26 18:25:37 +09:00
parent 50bfaeafdf
commit 317d00a284
1286 changed files with 80222 additions and 1 deletions
@@ -0,0 +1,27 @@
import * as fs from "node:fs";
import * as Path from "node:path";
import { pipeline } from "node:stream/promises";
import config from "../../config/index.js";
export class InternalStorage {
static resolvePath = (key)=>Path.resolve(config.mediaDir, key);
static read(key) {
return fs.createReadStream(InternalStorage.resolvePath(key));
}
static async saveFromPath(key, srcPath) {
fs.mkdirSync(config.mediaDir, {
recursive: true
});
await pipeline(fs.createReadStream(srcPath), fs.createWriteStream(InternalStorage.resolvePath(key)));
return `${config.url}/files/${key}`;
}
static saveFromBuffer(key, data) {
fs.mkdirSync(config.mediaDir, {
recursive: true
});
fs.writeFileSync(InternalStorage.resolvePath(key), data);
return `${config.url}/files/${key}`;
}
static del(key) {
fs.unlink(InternalStorage.resolvePath(key), ()=>{});
}
}