@opengis/fastify-table
Version:
core-plugins
31 lines (30 loc) • 1.15 kB
JavaScript
import path from "node:path";
import config from "../../../../config.js";
function getPath(filepath, options = {}) {
// used at getValidData
if (typeof filepath !== "string" && options?.check) {
return null;
}
if (typeof filepath !== "string") {
throw new Error("invalid filepath type");
}
// full path support + windows drive
const relpath = filepath.replace(/\\/g, "/");
const isFull = relpath.substring(0, 14).includes("/data/local/") ||
Object.values(config.fileStorage || {}).find((el) => relpath.includes(el));
if (isFull)
return relpath;
const rootDir = config.root || `/data/local/${options.database || config.pg?.database}`;
const sufix = ["files", "/files"].find((el) => relpath.startsWith(el))
? ""
: "files";
const prefix = !relpath.toLowerCase().includes(rootDir.toLowerCase())
? rootDir
: "";
if (config.folder &&
!relpath.toLowerCase().includes(config.folder.toLowerCase())) {
return path.join(prefix, config.folder, sufix, relpath);
}
return path.join(prefix, relpath);
}
export default getPath;