Browse Source

feat: Add table name and column name in attachment path

re #426

Signed-off-by: Pranav C <61551451+pranavxc@users.noreply.github.com>
pull/441/head
Pranav C 3 years ago
parent
commit
0d5c3000a0
  1. 2
      packages/nc-gui/components/project/spreadsheet/components/editableCell.vue
  2. 15
      packages/nc-gui/components/project/spreadsheet/components/editableCell/editableAttachmentCell.vue
  3. 20
      packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts
  4. 3
      packages/nocodb/src/lib/utils/mimeTypes.ts

2
packages/nc-gui/components/project/spreadsheet/components/editableCell.vue

@ -11,6 +11,8 @@
v-model="localState"
:active="active"
:db-alias="dbAlias"
:meta="meta"
:column="column"
v-on="$listeners"
/>

15
packages/nc-gui/components/project/spreadsheet/components/editableCell/editableAttachmentCell.vue

@ -212,7 +212,7 @@ import { isImage } from '@/components/project/spreadsheet/helpers/imageExt'
export default {
name: 'EditableAttachmentCell',
props: ['dbAlias', 'value', 'active', 'isLocked'],
props: ['dbAlias', 'value', 'active', 'isLocked', 'meta', 'column'],
data: () => ({
carousel: null,
uploading: false,
@ -265,7 +265,9 @@ export default {
this.showImage = true
},
addFile() {
if (!this.isLocked) { this.$refs.file.click() }
if (!this.isLocked) {
this.$refs.file.click()
}
},
async onFileSelection() {
if (!this.$refs.file.files || !this.$refs.file.files.length) {
@ -276,7 +278,10 @@ export default {
try {
const item = await this.$store.dispatch('sqlMgr/ActUpload', [{
dbAlias: this.dbAlias
}, 'xcAttachmentUpload', {}, file])
}, 'xcAttachmentUpload', {
appendPath: [this.meta.tn],
prependName: [this.column.cn]
}, file])
this.localState.push(item)
} catch (e) {
this.$toast.error((e.message) || 'Some internal error occurred').goAway(3000)
@ -295,7 +300,9 @@ export default {
this.$emit('update')
},
onArrowDown(e) {
if (!this.showImage) { return }
if (!this.showImage) {
return
}
e = e || window.event
// eslint-disable-next-line eqeqeq
if (e.keyCode == '37') {

20
packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

@ -92,10 +92,12 @@ export default class NcMetaMgr {
// todo: acl
router.get('/dl/:projectId/:dbAlias/:fileName', async (req, res) => {
router.get(/^\/dl\/([^/]+)\/([^/]+)\/(.+)$/, async (req, res) => {
try {
const type = mimetypes[path.extname(req.params.fileName).slice(1)] || 'text/plain';
const img = await this.storageAdapter.fileRead(slash(path.join('nc', req.params.projectId, req.params.dbAlias, 'uploads', req.params.fileName)));
// const type = mimetypes[path.extname(req.params.fileName).slice(1)] || 'text/plain';
const type = mimetypes[path.extname(req.params[2]).split('/').pop().slice(1)] || 'text/plain';
// const img = await this.storageAdapter.fileRead(slash(path.join('nc', req.params.projectId, req.params.dbAlias, 'uploads', req.params.fileName)));
const img = await this.storageAdapter.fileRead(slash(path.join('nc', req.params[0], req.params[1], 'uploads', ...req.params[2].split('/'))));
res.writeHead(200, {'Content-Type': type});
res.end(img, 'binary');
} catch (e) {
@ -942,19 +944,21 @@ export default class NcMetaMgr {
public async xcAttachmentUpload(req, args, file) {
try {
const fileName = `${nanoid(6)}${path.extname(file.originalname)}`
const appendPath = args.args.appendPath || [];
const prependName = args.args.prependName?.length ? args.args.prependName.join('_') + '_' : '';
const fileName = `${prependName}${nanoid(6)}_${file.originalname}`
let destPath;
if (args?.args?.public) {
destPath = path.join('nc', 'public', 'files', 'uploads');
destPath = path.join('nc', 'public', 'files', 'uploads', ...appendPath);
} else {
destPath = path.join('nc', this.getProjectId(args), this.getDbAlias(args), 'uploads');
destPath = path.join('nc', this.getProjectId(args), this.getDbAlias(args), 'uploads', ...appendPath);
}
let url = await this.storageAdapter.fileCreate(slash(path.join(destPath, fileName)), file);
if (!url) {
if (args?.args?.public) {
url = `${req.ncSiteUrl}/dl/public/files/${fileName}`;
url = `${req.ncSiteUrl}/dl/public/files/${appendPath?.length ? appendPath.join('/') + '/' : ''}${fileName}`;
} else {
url = `${req.ncSiteUrl}/dl/${this.getProjectId(args)}/${this.getDbAlias(args)}/${fileName}`;
url = `${req.ncSiteUrl}/dl/${this.getProjectId(args)}/${this.getDbAlias(args)}/${appendPath?.length ? appendPath.join('/') + '/' : ''}${fileName}`;
}
}
return {

3
packages/nocodb/src/lib/utils/mimeTypes.ts

@ -268,7 +268,8 @@ export default {
"json": "application/json",
"joda": "application/vnd.joost.joda-archive",
"jpm": "video/jpm",
"jpeg, .jpg": "image/x-citrix-jpeg",
"jpeg": "image/x-citrix-jpeg",
"jpg": "image/x-citrix-jpeg",
"pjpeg": "image/pjpeg",
"jpgv": "video/jpeg",
"ktz": "application/vnd.kahootz",

Loading…
Cancel
Save