Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
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
Expand Down