From 59859177150c058d789cb04eee6c953f6818ac6d Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Sun, 10 Oct 2021 14:09:18 +0200 Subject: :bug: fix cdn route not working without hash --- cdn/src/util/FileStorage.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'cdn/src/util/FileStorage.ts') 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 { + 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; + } } } -- cgit 1.5.1