|
|
@ -14,6 +14,7 @@ import catchError, { NcError } from '../helpers/catchError'; |
|
|
|
import NcPluginMgrv2 from '../helpers/NcPluginMgrv2'; |
|
|
|
import NcPluginMgrv2 from '../helpers/NcPluginMgrv2'; |
|
|
|
import Local from '../../v1-legacy/plugins/adapters/storage/Local'; |
|
|
|
import Local from '../../v1-legacy/plugins/adapters/storage/Local'; |
|
|
|
import { NC_ATTACHMENT_FIELD_SIZE } from '../../constants'; |
|
|
|
import { NC_ATTACHMENT_FIELD_SIZE } from '../../constants'; |
|
|
|
|
|
|
|
import { getCacheMiddleware } from './helpers'; |
|
|
|
|
|
|
|
|
|
|
|
const isUploadAllowed = async (req: Request, _res: Response, next: any) => { |
|
|
|
const isUploadAllowed = async (req: Request, _res: Response, next: any) => { |
|
|
|
if (!req['user']?.id) { |
|
|
|
if (!req['user']?.id) { |
|
|
@ -161,32 +162,36 @@ export async function fileRead(req, res) { |
|
|
|
|
|
|
|
|
|
|
|
const router = Router({ mergeParams: true }); |
|
|
|
const router = Router({ mergeParams: true }); |
|
|
|
|
|
|
|
|
|
|
|
router.get(/^\/dl\/([^/]+)\/([^/]+)\/(.+)$/, async (req, res) => { |
|
|
|
router.get( |
|
|
|
try { |
|
|
|
/^\/dl\/([^/]+)\/([^/]+)\/(.+)$/, |
|
|
|
// const type = mimetypes[path.extname(req.params.fileName).slice(1)] || 'text/plain';
|
|
|
|
getCacheMiddleware(), |
|
|
|
const type = |
|
|
|
async (req, res) => { |
|
|
|
mimetypes[path.extname(req.params[2]).split('/').pop().slice(1)] || |
|
|
|
try { |
|
|
|
'text/plain'; |
|
|
|
// const type = mimetypes[path.extname(req.params.fileName).slice(1)] || 'text/plain';
|
|
|
|
|
|
|
|
const type = |
|
|
|
const storageAdapter = await NcPluginMgrv2.storageAdapter(); |
|
|
|
mimetypes[path.extname(req.params[2]).split('/').pop().slice(1)] || |
|
|
|
// const img = await this.storageAdapter.fileRead(slash(path.join('nc', req.params.projectId, req.params.dbAlias, 'uploads', req.params.fileName)));
|
|
|
|
'text/plain'; |
|
|
|
const img = await storageAdapter.fileRead( |
|
|
|
|
|
|
|
slash( |
|
|
|
const storageAdapter = await NcPluginMgrv2.storageAdapter(); |
|
|
|
path.join( |
|
|
|
// const img = await this.storageAdapter.fileRead(slash(path.join('nc', req.params.projectId, req.params.dbAlias, 'uploads', req.params.fileName)));
|
|
|
|
'nc', |
|
|
|
const img = await storageAdapter.fileRead( |
|
|
|
req.params[0], |
|
|
|
slash( |
|
|
|
req.params[1], |
|
|
|
path.join( |
|
|
|
'uploads', |
|
|
|
'nc', |
|
|
|
...req.params[2].split('/') |
|
|
|
req.params[0], |
|
|
|
|
|
|
|
req.params[1], |
|
|
|
|
|
|
|
'uploads', |
|
|
|
|
|
|
|
...req.params[2].split('/') |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
); |
|
|
|
); |
|
|
|
res.writeHead(200, { 'Content-Type': type }); |
|
|
|
res.writeHead(200, { 'Content-Type': type }); |
|
|
|
res.end(img, 'binary'); |
|
|
|
res.end(img, 'binary'); |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
res.status(404).send('Not found'); |
|
|
|
res.status(404).send('Not found'); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
export function sanitizeUrlPath(paths) { |
|
|
|
export function sanitizeUrlPath(paths) { |
|
|
|
return paths.map((url) => url.replace(/[/.?#]+/g, '_')); |
|
|
|
return paths.map((url) => url.replace(/[/.?#]+/g, '_')); |
|
|
@ -217,6 +222,6 @@ router.post( |
|
|
|
] |
|
|
|
] |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
router.get(/^\/download\/(.+)$/, catchError(fileRead)); |
|
|
|
router.get(/^\/download\/(.+)$/, getCacheMiddleware(), catchError(fileRead)); |
|
|
|
|
|
|
|
|
|
|
|
export default router; |
|
|
|
export default router; |
|
|
|