From 69c6e98f0738beb398473d9d4babb72332b6842d Mon Sep 17 00:00:00 2001 From: Pavlo Kulyk Date: Thu, 26 Mar 2026 13:55:15 +0200 Subject: [PATCH] feat: add API for to determine our link or from a third-party source --- index.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/index.ts b/index.ts index f79afba..f38cad1 100644 --- a/index.ts +++ b/index.ts @@ -415,6 +415,26 @@ export default class AdminForthStorageAdapterLocalFilesystem implements StorageA } } + /** + * Checks if the URL belongs to this local filesystem storage instance. + * It checks if the URL starts with the base path registered in Express. + * * @param url - The URL to check + */ + async isInternalUrl(url: string): Promise { + if (url.startsWith(this.expressBase)) { + return true; + } + + try { + const normalizedUrl = url.startsWith('//') ? `https:${url}` : url; + const parsedUrl = new URL(normalizedUrl, 'http://localhost'); + + return parsedUrl.pathname.startsWith(this.expressBase); + } catch (e) { + return false; + } + } + /** * This method should return the key as a data URL (base64 encoded string). * @param key - The key of the file to be converted to a data URL