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">
import { iconMap } from '#imports'
interface Props {
srcs: string[]
alt?: string

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

@ -193,7 +193,7 @@ onUnmounted(() => {
`nc-cell-${(column?.uidt || 'default').toLowerCase()}`,
{ 'text-blue-600': isPrimary(column) && !props.virtual && !isForm },
{ '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.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 res: string[] = []
if (item?.data) res.push(item.data)
if (item?.path) res.push(`${appInfo.value.ncSiteUrl}/${item.path}`)
if (item?.url) res.push(item.url)
return res

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

@ -7905,7 +7905,7 @@ export class Api<
*/
dataCreate: (
sharedViewUuid: string,
data: object,
data: any,
params: RequestParams = {}
) =>
this.request<
@ -7918,7 +7918,7 @@ export class Api<
path: `/api/v1/db/public/shared-view/${sharedViewUuid}/rows`,
method: 'POST',
body: data,
type: ContentType.Json,
type: ContentType.FormData,
format: 'json',
...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,
body: req.body?.data,
siteUrl: (req as any).ncSiteUrl,
// req.files is enriched by multer
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) {
// then store the attachement path only
// url will be constructued in `useAttachmentCell`
// then store the attachment path only
// url will be constructed in `useAttachmentCell`
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 filePath = sanitizeUrlPath([
'v1',
'noco',
project.title,
model.title,
fieldName,
@ -243,18 +243,25 @@ export async function dataInsert(param: {
if (fieldName in fields && fields[fieldName].uidt === UITypes.Attachment) {
attachments[fieldName] = attachments[fieldName] || [];
const fileName = `${nanoid(6)}_${file.originalname}`;
let url = await storageAdapter.fileCreate(
const fileName = `${nanoid(18)}${path.extname(file.originalname)}`;
const url = await storageAdapter.fileCreate(
slash(path.join('nc', 'uploads', ...filePath, fileName)),
file
);
let attachmentPath;
// if `url` is null, then it is local attachment
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({
url,
...(url ? { url } : {}),
...(attachmentPath ? { path: attachmentPath } : {}),
title: file.originalname,
mimetype: file.mimetype,
size: file.size,

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

@ -10886,20 +10886,7 @@
},
"requestBody": {
"content": {
"application/json": {
"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"
}
}
}
}
"multipart/form-data": {}
},
"description": ""
},

Loading…
Cancel
Save