Просмотр исходного кода

fix file path on storage for page bulk export

Futa Arai 1 год назад
Родитель
Сommit
cc90a8dfe2

+ 14 - 5
apps/app/src/server/service/file-uploader/aws/index.ts

@@ -12,7 +12,9 @@ import {
 import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
 import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
 import urljoin from 'url-join';
 import urljoin from 'url-join';
 
 
-import { FilePathOnStoragePrefix, ResponseMode, type RespondOptions } from '~/server/interfaces/attachment';
+import {
+  AttachmentType, FilePathOnStoragePrefix, ResponseMode, type RespondOptions,
+} from '~/server/interfaces/attachment';
 import type { IAttachmentDocument } from '~/server/models';
 import type { IAttachmentDocument } from '~/server/models';
 import loggerFactory from '~/utils/logger';
 import loggerFactory from '~/utils/logger';
 
 
@@ -79,14 +81,21 @@ const S3Factory = (): S3Client => {
   return new S3Client(config);
   return new S3Client(config);
 };
 };
 
 
-const getFilePathOnStorage = (attachment) => {
+const getFilePathOnStorage = (attachment: IAttachmentDocument) => {
   if (attachment.filePath != null) { // DEPRECATED: remains for backward compatibility for v3.3.x or below
   if (attachment.filePath != null) { // DEPRECATED: remains for backward compatibility for v3.3.x or below
     return attachment.filePath;
     return attachment.filePath;
   }
   }
 
 
-  const dirName = (attachment.page != null)
-    ? FilePathOnStoragePrefix.attachment
-    : FilePathOnStoragePrefix.user;
+  let dirName: string;
+  if (attachment.attachmentType === AttachmentType.PAGE_BULK_EXPORT) {
+    dirName = FilePathOnStoragePrefix.pageBulkExport;
+  }
+  else if (attachment.page != null) {
+    dirName = FilePathOnStoragePrefix.attachment;
+  }
+  else {
+    dirName = FilePathOnStoragePrefix.user;
+  }
   const filePath = urljoin(dirName, attachment.fileName);
   const filePath = urljoin(dirName, attachment.fileName);
 
 
   return filePath;
   return filePath;

+ 1 - 1
apps/app/src/server/service/file-uploader/azure.ts

@@ -62,7 +62,7 @@ async function getContainerClient(): Promise<ContainerClient> {
   return blobServiceClient.getContainerClient(containerName);
   return blobServiceClient.getContainerClient(containerName);
 }
 }
 
 
-function getFilePathOnStorage(attachment) {
+function getFilePathOnStorage(attachment: IAttachmentDocument) {
   const dirName = (attachment.page != null) ? FilePathOnStoragePrefix.attachment : FilePathOnStoragePrefix.user;
   const dirName = (attachment.page != null) ? FilePathOnStoragePrefix.attachment : FilePathOnStoragePrefix.user;
   return urljoin(dirName, attachment.fileName);
   return urljoin(dirName, attachment.fileName);
 }
 }

+ 1 - 1
apps/app/src/server/service/file-uploader/gcs.ts

@@ -32,7 +32,7 @@ function getGcsInstance() {
   return storage;
   return storage;
 }
 }
 
 
-function getFilePathOnStorage(attachment) {
+function getFilePathOnStorage(attachment: IAttachmentDocument) {
   const namespace = configManager.getConfig('crowi', 'gcs:uploadNamespace');
   const namespace = configManager.getConfig('crowi', 'gcs:uploadNamespace');
   // const namespace = null;
   // const namespace = null;
   const dirName = (attachment.page != null)
   const dirName = (attachment.page != null)

+ 1 - 1
apps/app/src/server/service/file-uploader/local.ts

@@ -99,7 +99,7 @@ module.exports = function(crowi) {
 
 
   const basePath = path.posix.join(crowi.publicDir, 'uploads');
   const basePath = path.posix.join(crowi.publicDir, 'uploads');
 
 
-  function getFilePathOnStorage(attachment) {
+  function getFilePathOnStorage(attachment: IAttachmentDocument) {
     const dirName = (attachment.page != null)
     const dirName = (attachment.page != null)
       ? FilePathOnStoragePrefix.attachment
       ? FilePathOnStoragePrefix.attachment
       : FilePathOnStoragePrefix.user;
       : FilePathOnStoragePrefix.user;

+ 2 - 0
packages/core/src/interfaces/attachment.ts

@@ -6,12 +6,14 @@ import type { IUser } from './user';
 export type IAttachment = {
 export type IAttachment = {
   page?: Ref<IPage>,
   page?: Ref<IPage>,
   creator?: Ref<IUser>,
   creator?: Ref<IUser>,
+  filePath?: string, // DEPRECATED: remains for backward compatibility for v3.3.x or below
   fileName: string,
   fileName: string,
   fileFormat: string,
   fileFormat: string,
   fileSize: number,
   fileSize: number,
   originalName: string,
   originalName: string,
   temporaryUrlCached?: string,
   temporaryUrlCached?: string,
   temporaryUrlExpiredAt?: Date,
   temporaryUrlExpiredAt?: Date,
+  attachmentType: string,
 
 
   createdAt: Date,
   createdAt: Date,