summary refs log tree commit diff
path: root/cdn/src/util/FileStorage.ts
diff options
context:
space:
mode:
authoruurgothat <cckhmck@gmail.com>2021-10-17 21:49:46 +0300
committeruurgothat <cckhmck@gmail.com>2021-10-17 21:49:46 +0300
commitdb3d6e116a3b49669103abdf5f2d156b2c78c3c4 (patch)
tree1a1a5f4d03ca5d0b94ca5f47456e7cd536ba21e7 /cdn/src/util/FileStorage.ts
parentMerge branch 'master' of https://github.com/fosscord/fosscord-server (diff)
parentUpdate README.md (diff)
downloadserver-db3d6e116a3b49669103abdf5f2d156b2c78c3c4.tar.xz
Merge branch 'master' of https://github.com/fosscord/fosscord-server
Diffstat (limited to 'cdn/src/util/FileStorage.ts')
-rw-r--r--cdn/src/util/FileStorage.ts14
1 files changed, 11 insertions, 3 deletions
diff --git a/cdn/src/util/FileStorage.ts b/cdn/src/util/FileStorage.ts

index e0b24a84..84ecf556 100644 --- a/cdn/src/util/FileStorage.ts +++ b/cdn/src/util/FileStorage.ts
@@ -13,16 +13,24 @@ function getPath(path: string) { const root = process.env.STORAGE_LOCATION || "../"; var filename = join(root, path); - if (path.indexOf("\0") !== -1 || !filename.startsWith(root)) throw new Error("invalid path"); + if (path.indexOf("\0") !== -1 || !filename.startsWith(root)) + throw new Error("invalid path"); return filename; } export class FileStorage implements Storage { async get(path: string): Promise<Buffer | null> { + path = getPath(path); try { - return fs.readFileSync(getPath(path)); + return fs.readFileSync(path); } catch (error) { - return null; + try { + const files = fs.readdirSync(path); + if (!files.length) return null; + return fs.readFileSync(join(path, files[0])); + } catch (error) { + return null; + } } }