diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-11 15:13:16 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-10-11 15:13:16 +0200 |
commit | 4a34792be6a8b53d05d4359fc75064449db75eef (patch) | |
tree | 66091b07cac6d0485f2dbb4784dcad7bada34425 /cdn/src/util/FileStorage.ts | |
parent | Implement GIFs (diff) | |
parent | Merge pull request #435 from TheArcaneBrony/change-enums-to-number (diff) | |
download | server-4a34792be6a8b53d05d4359fc75064449db75eef.tar.xz |
Merge branch 'master' into pr/Thesourtimes/430
Diffstat (limited to 'cdn/src/util/FileStorage.ts')
-rw-r--r-- | cdn/src/util/FileStorage.ts | 14 |
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; + } } } |