mirror of
https://github.com/spacebarchat/server.git
synced 2026-08-29 07:39:00 +00:00
use async io for CDN file storage
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
import { Storage } from "./Storage";
|
||||
import fs from "fs";
|
||||
import fsp from "fs/promises";
|
||||
import { join, dirname } from "path";
|
||||
import { Readable } from "stream";
|
||||
import ExifTransformer from "exif-be-gone";
|
||||
@@ -37,12 +38,12 @@ export class FileStorage implements Storage {
|
||||
async get(path: string): Promise<Buffer | null> {
|
||||
path = getPath(path);
|
||||
try {
|
||||
return fs.readFileSync(path);
|
||||
return await fsp.readFile(path);
|
||||
} catch (error) {
|
||||
try {
|
||||
const files = fs.readdirSync(path);
|
||||
if (!files.length) return null;
|
||||
return fs.readFileSync(join(path, files[0]));
|
||||
return await fsp.readFile(join(path, files[0]));
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user