Browse Source

Merge pull request #5454 from nocodb/fix/form-attachment

fix(nc-gui): form attachments
pull/5475/head
Raju Udava 2 years ago committed by GitHub
parent
commit
73c337a522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/nc-gui/components/cell/attachment/Image.vue
  2. 2
      packages/nc-gui/components/smartsheet/Cell.vue
  3. 1
      packages/nc-gui/composables/useAttachment.ts
  4. 4
      packages/nocodb-sdk/src/lib/Api.ts
  5. 1
      packages/nocodb/src/lib/controllers/publicControllers/publicData.ctl.ts
  6. 4
      packages/nocodb/src/lib/services/attachment.svc.ts
  7. 17
      packages/nocodb/src/lib/services/public/publicData.svc.ts
  8. 15
      packages/nocodb/src/schema/swagger.json

2
packages/nc-gui/components/cell/attachment/Image.vue

@ -1,4 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { iconMap } from '#imports'
interface Props { interface Props {
srcs: string[] srcs: string[]
alt?: string alt?: string

2
packages/nc-gui/components/smartsheet/Cell.vue

@ -193,7 +193,7 @@ onUnmounted(() => {
`nc-cell-${(column?.uidt || 'default').toLowerCase()}`, `nc-cell-${(column?.uidt || 'default').toLowerCase()}`,
{ 'text-blue-600': isPrimary(column) && !props.virtual && !isForm }, { 'text-blue-600': isPrimary(column) && !props.virtual && !isForm },
{ 'nc-grid-numeric-cell': isGrid && !isForm && isNumericField }, { 'nc-grid-numeric-cell': isGrid && !isForm && isNumericField },
{ 'h-[40px]': !props.editEnabled && isForm && !isSurveyForm }, { 'h-[40px]': !props.editEnabled && isForm && !isSurveyForm && !isAttachment(column) },
]" ]"
@keydown.enter.exact="navigate(NavigateDir.NEXT, $event)" @keydown.enter.exact="navigate(NavigateDir.NEXT, $event)"
@keydown.shift.enter.exact="navigate(NavigateDir.PREV, $event)" @keydown.shift.enter.exact="navigate(NavigateDir.PREV, $event)"

1
packages/nc-gui/composables/useAttachment.ts

@ -5,6 +5,7 @@ const useAttachment = () => {
const getPossibleAttachmentSrc = (item: Record<string, any>) => { const getPossibleAttachmentSrc = (item: Record<string, any>) => {
const res: string[] = [] const res: string[] = []
if (item?.data) res.push(item.data)
if (item?.path) res.push(`${appInfo.value.ncSiteUrl}/${item.path}`) if (item?.path) res.push(`${appInfo.value.ncSiteUrl}/${item.path}`)
if (item?.url) res.push(item.url) if (item?.url) res.push(item.url)
return res return res

4
packages/nocodb-sdk/src/lib/Api.ts

@ -7905,7 +7905,7 @@ export class Api<
*/ */
dataCreate: ( dataCreate: (
sharedViewUuid: string, sharedViewUuid: string,
data: object, data: any,
params: RequestParams = {} params: RequestParams = {}
) => ) =>
this.request< this.request<
@ -7918,7 +7918,7 @@ export class Api<
path: `/api/v1/db/public/shared-view/${sharedViewUuid}/rows`, path: `/api/v1/db/public/shared-view/${sharedViewUuid}/rows`,
method: 'POST', method: 'POST',
body: data, body: data,
type: ContentType.Json, type: ContentType.FormData,
format: 'json', format: 'json',
...params, ...params,
}), }),

1
packages/nocodb/src/lib/controllers/publicControllers/publicData.ctl.ts

@ -31,6 +31,7 @@ async function dataInsert(req: Request & { files: any[] }, res: Response) {
password: req.headers?.['xc-password'] as string, password: req.headers?.['xc-password'] as string,
body: req.body?.data, body: req.body?.data,
siteUrl: (req as any).ncSiteUrl, siteUrl: (req as any).ncSiteUrl,
// req.files is enriched by multer
files: req.files, files: req.files,
}); });

4
packages/nocodb/src/lib/services/attachment.svc.ts

@ -30,8 +30,8 @@ export async function upload(param: {
// if `url` is null, then it is local attachment // if `url` is null, then it is local attachment
if (!url) { if (!url) {
// then store the attachement path only // then store the attachment path only
// url will be constructued in `useAttachmentCell` // url will be constructed in `useAttachmentCell`
attachmentPath = `download/${filePath.join('/')}/${fileName}`; attachmentPath = `download/${filePath.join('/')}/${fileName}`;
} }

17
packages/nocodb/src/lib/services/public/publicData.svc.ts

@ -235,7 +235,7 @@ export async function dataInsert(param: {
const fieldName = file?.fieldname?.replace(/^_|\[\d*]$/g, ''); const fieldName = file?.fieldname?.replace(/^_|\[\d*]$/g, '');
const filePath = sanitizeUrlPath([ const filePath = sanitizeUrlPath([
'v1', 'noco',
project.title, project.title,
model.title, model.title,
fieldName, fieldName,
@ -243,18 +243,25 @@ export async function dataInsert(param: {
if (fieldName in fields && fields[fieldName].uidt === UITypes.Attachment) { if (fieldName in fields && fields[fieldName].uidt === UITypes.Attachment) {
attachments[fieldName] = attachments[fieldName] || []; attachments[fieldName] = attachments[fieldName] || [];
const fileName = `${nanoid(6)}_${file.originalname}`; const fileName = `${nanoid(18)}${path.extname(file.originalname)}`;
let url = await storageAdapter.fileCreate(
const url = await storageAdapter.fileCreate(
slash(path.join('nc', 'uploads', ...filePath, fileName)), slash(path.join('nc', 'uploads', ...filePath, fileName)),
file file
); );
let attachmentPath;
// if `url` is null, then it is local attachment
if (!url) { if (!url) {
url = `${param.siteUrl}/download/${filePath.join('/')}/${fileName}`; // then store the attachment path only
// url will be constructed in `useAttachmentCell`
attachmentPath = `download/${filePath.join('/')}/${fileName}`;
} }
attachments[fieldName].push({ attachments[fieldName].push({
url, ...(url ? { url } : {}),
...(attachmentPath ? { path: attachmentPath } : {}),
title: file.originalname, title: file.originalname,
mimetype: file.mimetype, mimetype: file.mimetype,
size: file.size, size: file.size,

15
packages/nocodb/src/schema/swagger.json

@ -10886,20 +10886,7 @@
}, },
"requestBody": { "requestBody": {
"content": { "content": {
"application/json": { "multipart/form-data": {}
"schema": {
"type": "object",
"description": "Data Object where the key is column and the value is the data value"
},
"examples": {
"Example 1": {
"value": {
"col1": "foo",
"col2": "bar"
}
}
}
}
}, },
"description": "" "description": ""
}, },

Loading…
Cancel
Save