Browse Source

fix: minio related issues (#9205)

* fix: allow useSSL to be false fix: await upload

* fix: update types

* fix: update types

* fix: thumbnails upload failing on windows

* fix: base64 encoded images upload failing
pull/9225/head
Anbarasu 4 months ago committed by GitHub
parent
commit
eb8f4a8c6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      packages/nocodb/src/modules/jobs/jobs/thumbnail-generator/thumbnail-generator.processor.ts
  2. 4
      packages/nocodb/src/plugins/mino/Minio.ts
  3. 2
      packages/nocodb/src/plugins/mino/index.ts
  4. 17
      packages/nocodb/src/services/attachments.service.ts

3
packages/nocodb/src/modules/jobs/jobs/thumbnail-generator/thumbnail-generator.processor.ts

@ -3,6 +3,7 @@ import { Readable } from 'stream';
import { Process, Processor } from '@nestjs/bull'; import { Process, Processor } from '@nestjs/bull';
import { Job } from 'bull'; import { Job } from 'bull';
import { Logger } from '@nestjs/common'; import { Logger } from '@nestjs/common';
import slash from 'slash';
import type { IStorageAdapterV2 } from 'nc-plugin'; import type { IStorageAdapterV2 } from 'nc-plugin';
import type { AttachmentResType } from 'nocodb-sdk'; import type { AttachmentResType } from 'nocodb-sdk';
import type { ThumbnailGeneratorJobData } from '~/interface/Jobs'; import type { ThumbnailGeneratorJobData } from '~/interface/Jobs';
@ -102,7 +103,7 @@ export class ThumbnailGeneratorProcessor {
.toBuffer(); .toBuffer();
await (storageAdapter as any).fileCreateByStream( await (storageAdapter as any).fileCreateByStream(
thumbnailPath, slash(thumbnailPath),
Readable.from(resizedImage), Readable.from(resizedImage),
{ {
mimetype: 'image/jpeg', mimetype: 'image/jpeg',

4
packages/nocodb/src/plugins/mino/Minio.ts

@ -123,7 +123,7 @@ export default class Minio implements IStorageAdapterV2 {
}, },
}; };
const responseUrl = this.upload(uploadParams); const responseUrl = await this.upload(uploadParams);
return { return {
url: responseUrl, url: responseUrl,
@ -137,7 +137,7 @@ export default class Minio implements IStorageAdapterV2 {
metaData: { [key: string]: string | number }; metaData: { [key: string]: string | number };
}): Promise<any> { }): Promise<any> {
try { try {
this.minioClient.putObject( await this.minioClient.putObject(
this.input.bucket, this.input.bucket,
uploadParams.Key, uploadParams.Key,
uploadParams.Body, uploadParams.Body,

2
packages/nocodb/src/plugins/mino/index.ts

@ -55,7 +55,7 @@ const config: XcPluginConfig = {
label: 'Use SSL', label: 'Use SSL',
placeholder: 'Use SSL', placeholder: 'Use SSL',
type: XcType.Checkbox, type: XcType.Checkbox,
required: true, required: false,
}, },
], ],
actions: [ actions: [

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

@ -198,8 +198,18 @@ export class AttachmentsService {
param.urls?.map?.((urlMeta) => async () => { param.urls?.map?.((urlMeta) => async () => {
try { try {
const { url, fileName: _fileName } = urlMeta; const { url, fileName: _fileName } = urlMeta;
const response = await axios.head(url, { maxRedirects: 5 });
const finalUrl = response.request.res.responseUrl || url; let mimeType,
response,
size,
finalUrl = url;
if (!url.startsWith('data:')) {
response = await axios.head(url, { maxRedirects: 5 });
mimeType = response.headers['content-type']?.split(';')[0];
size = response.headers['content-length'];
finalUrl = response.request.res.responseUrl;
}
const parsedUrl = Url.parse(finalUrl, true); const parsedUrl = Url.parse(finalUrl, true);
const decodedPath = decodeURIComponent(parsedUrl.pathname); const decodedPath = decodeURIComponent(parsedUrl.pathname);
@ -209,9 +219,6 @@ export class AttachmentsService {
5, 5,
)}${path.extname(fileNameWithExt)}`; )}${path.extname(fileNameWithExt)}`;
let mimeType = response.headers['content-type']?.split(';')[0];
const size = response.headers['content-length'];
if (!mimeType) { if (!mimeType) {
mimeType = mimetypes[path.extname(fileNameWithExt).slice(1)]; mimeType = mimetypes[path.extname(fileNameWithExt).slice(1)];
} }

Loading…
Cancel
Save