UNPKG

@opengis/fastify-table

Version:

core-plugins

26 lines (18 loc) 944 B
import path from 'node:path'; import config from '../../../../config.js'; function getPath(filepath, options = {}) { if (typeof filepath !== 'string') return null; // 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;