Browse Source

fix: filter mimetypes to preview in browser

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/7162/head
mertmit 12 months ago
parent
commit
3dc46bdafb
  1. 4
      packages/nocodb/src/controllers/attachments-secure.controller.ts
  2. 12
      packages/nocodb/src/controllers/attachments.controller.ts
  3. 8
      packages/nocodb/src/services/attachments.service.ts

4
packages/nocodb/src/controllers/attachments-secure.controller.ts

@ -75,7 +75,11 @@ export class AttachmentsSecureController {
path: path.join('nc', 'uploads', fpath), path: path.join('nc', 'uploads', fpath),
}); });
if (this.attachmentsService.previewAvailable(file.type)) {
res.sendFile(file.path); res.sendFile(file.path);
} else {
res.download(file.path);
}
} catch (e) { } catch (e) {
res.status(404).send('Not found'); res.status(404).send('Not found');
} }

12
packages/nocodb/src/controllers/attachments.controller.ts

@ -68,7 +68,11 @@ export class AttachmentsController {
path: path.join('nc', 'uploads', filename), path: path.join('nc', 'uploads', filename),
}); });
if (this.attachmentsService.previewAvailable(file.type)) {
res.sendFile(file.path); res.sendFile(file.path);
} else {
res.download(file.path);
}
} catch (e) { } catch (e) {
res.status(404).send('Not found'); res.status(404).send('Not found');
} }
@ -94,7 +98,11 @@ export class AttachmentsController {
), ),
}); });
if (this.attachmentsService.previewAvailable(file.type)) {
res.sendFile(file.path); res.sendFile(file.path);
} else {
res.download(file.path);
}
} catch (e) { } catch (e) {
res.status(404).send('Not found'); res.status(404).send('Not found');
} }
@ -109,7 +117,11 @@ export class AttachmentsController {
path: path.join('nc', 'uploads', fpath), path: path.join('nc', 'uploads', fpath),
}); });
if (this.attachmentsService.previewAvailable(file.type)) {
res.sendFile(file.path); res.sendFile(file.path);
} else {
res.download(file.path);
}
} catch (e) { } catch (e) {
res.status(404).send('Not found'); res.status(404).send('Not found');
} }

8
packages/nocodb/src/services/attachments.service.ts

@ -161,6 +161,14 @@ export class AttachmentsService {
return { path: filePath, type }; return { path: filePath, type };
} }
previewAvailable(mimetype: string) {
const available = ['image', 'pdf', 'text/plain'];
if (available.some((type) => mimetype.includes(type))) {
return true;
}
return false;
}
sanitizeUrlPath(paths) { sanitizeUrlPath(paths) {
return paths.map((url) => url.replace(/[/.?#]+/g, '_')); return paths.map((url) => url.replace(/[/.?#]+/g, '_'));
} }

Loading…
Cancel
Save