Proxy local ZXDB/WoS mirror downloads through application API
- Created `src/app/api/zxdb/download/route.ts` to serve local files. - Updated `resolveLocalLink` in `src/server/repo/zxdb.ts` to return API-relative URLs with `source` and `path` parameters. - Encodes the relative subpath to ensure correct URL construction. - Includes security checks in the API route to prevent path traversal. - Updated `docs/ZXDB.md` to reflect the proxy mechanism. Signed-off: junie@lucy.xalior.com
This commit is contained in:
@@ -116,20 +116,25 @@ export interface EntryFacets {
|
||||
*/
|
||||
function resolveLocalLink(fileLink: string): string | null {
|
||||
let localPath: string | null = null;
|
||||
let source: "zxdb" | "wos" | null = null;
|
||||
let subPath: string | null = null;
|
||||
|
||||
const zxdbPrefix = env.ZXDB_FILE_PREFIX || "";
|
||||
const wosPrefix = env.WOS_FILE_PREFIX || "";
|
||||
|
||||
if (fileLink.startsWith(zxdbPrefix) && env.ZXDB_LOCAL_FILEPATH) {
|
||||
const sub = fileLink.slice(zxdbPrefix.replace(/\/$/, "").length);
|
||||
localPath = path.join(env.ZXDB_LOCAL_FILEPATH, sub);
|
||||
subPath = fileLink.slice(zxdbPrefix.replace(/\/$/, "").length);
|
||||
localPath = path.join(env.ZXDB_LOCAL_FILEPATH, subPath);
|
||||
source = "zxdb";
|
||||
} else if (fileLink.startsWith(wosPrefix) && env.WOS_LOCAL_FILEPATH) {
|
||||
const sub = fileLink.slice(wosPrefix.replace(/\/$/, "").length);
|
||||
localPath = path.join(env.WOS_LOCAL_FILEPATH, sub);
|
||||
subPath = fileLink.slice(wosPrefix.replace(/\/$/, "").length);
|
||||
localPath = path.join(env.WOS_LOCAL_FILEPATH, subPath);
|
||||
source = "wos";
|
||||
}
|
||||
|
||||
if (localPath && fs.existsSync(localPath)) {
|
||||
return localPath;
|
||||
if (localPath && fs.existsSync(localPath) && source && subPath) {
|
||||
// Return an application-relative URL instead of the absolute filesystem path
|
||||
return `/api/zxdb/download?source=${source}&path=${encodeURIComponent(subPath)}`;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user