|
|
@ -12,12 +12,9 @@ import NcPluginMgrv2 from '../helpers/NcPluginMgrv2'; |
|
|
|
|
|
|
|
|
|
|
|
// const storageAdapter = new Local();
|
|
|
|
// const storageAdapter = new Local();
|
|
|
|
export async function upload(req: Request, res: Response) { |
|
|
|
export async function upload(req: Request, res: Response) { |
|
|
|
const filePath = sanitizeUrlPath([ |
|
|
|
const filePath = sanitizeUrlPath( |
|
|
|
req.params.orgs, |
|
|
|
req.query?.path?.toString()?.split('/') || [''] |
|
|
|
req.params.projectName, |
|
|
|
); |
|
|
|
req.params.tableName, |
|
|
|
|
|
|
|
req.params.columnName |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
const destPath = path.join('nc', 'uploads', ...filePath); |
|
|
|
const destPath = path.join('nc', 'uploads', ...filePath); |
|
|
|
|
|
|
|
|
|
|
|
const storageAdapter = await NcPluginMgrv2.storageAdapter(); |
|
|
|
const storageAdapter = await NcPluginMgrv2.storageAdapter(); |
|
|
@ -31,9 +28,9 @@ export async function upload(req: Request, res: Response) { |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (!url) { |
|
|
|
if (!url) { |
|
|
|
url = `${ |
|
|
|
url = `${(req as any).ncSiteUrl}/download/${filePath.join( |
|
|
|
(req as any).ncSiteUrl |
|
|
|
'/' |
|
|
|
}/api/v1/db/data-attachment/${filePath.join('/')}/${fileName}`;
|
|
|
|
)}/${fileName}`;
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
@ -53,11 +50,11 @@ export async function upload(req: Request, res: Response) { |
|
|
|
export async function fileRead(req, res) { |
|
|
|
export async function fileRead(req, res) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const storageAdapter = await NcPluginMgrv2.storageAdapter(); |
|
|
|
const storageAdapter = await NcPluginMgrv2.storageAdapter(); |
|
|
|
// const type = mimetypes[path.extname(req.params.fileName).slice(1)] || 'text/plain';
|
|
|
|
// const type = mimetypes[path.extname(req.s.fileName).slice(1)] || 'text/plain';
|
|
|
|
const type = |
|
|
|
const type = |
|
|
|
mimetypes[ |
|
|
|
mimetypes[ |
|
|
|
path |
|
|
|
path |
|
|
|
.extname(req.params.fileName) |
|
|
|
.extname(req.params?.[0]) |
|
|
|
.split('/') |
|
|
|
.split('/') |
|
|
|
.pop() |
|
|
|
.pop() |
|
|
|
.slice(1) |
|
|
|
.slice(1) |
|
|
@ -68,11 +65,10 @@ export async function fileRead(req, res) { |
|
|
|
path.join( |
|
|
|
path.join( |
|
|
|
'nc', |
|
|
|
'nc', |
|
|
|
'uploads', |
|
|
|
'uploads', |
|
|
|
req.params.orgs, |
|
|
|
req.params?.[0] |
|
|
|
req.params.projectName, |
|
|
|
?.split('/') |
|
|
|
req.params.tableName, |
|
|
|
.filter(p => p !== '..') |
|
|
|
req.params.columnName, |
|
|
|
.join('/') |
|
|
|
req.params.fileName |
|
|
|
|
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
); |
|
|
|
); |
|
|
@ -122,15 +118,12 @@ export function sanitizeUrlPath(paths) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
router.post( |
|
|
|
router.post( |
|
|
|
'/api/v1/db/data-attachment/:orgs/:projectName/:tableName/:columnName', |
|
|
|
'/api/v1/db/storage/upload', |
|
|
|
multer({ |
|
|
|
multer({ |
|
|
|
storage: multer.diskStorage({}) |
|
|
|
storage: multer.diskStorage({}) |
|
|
|
}).any(), |
|
|
|
}).any(), |
|
|
|
ncMetaAclMw(upload, 'upload') |
|
|
|
ncMetaAclMw(upload, 'upload') |
|
|
|
); |
|
|
|
); |
|
|
|
router.get( |
|
|
|
router.get(/^\/download\/(.+)$/, catchError(fileRead)); |
|
|
|
'/api/v1/db/data-attachment/:orgs/:projectName/:tableName/:columnName/:fileName', |
|
|
|
|
|
|
|
catchError(fileRead) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default router; |
|
|
|
export default router; |
|
|
|