From 58fd4a4572bfe2cb6ff0133be80c13abffd3d574 Mon Sep 17 00:00:00 2001 From: sdjdd Date: Sun, 31 Mar 2024 02:19:07 +0800 Subject: [PATCH] feat: transfer file manaully --- next/api/src/response/file.ts | 6 ++---- next/api/src/response/reply.ts | 4 ++-- next/api/src/response/ticket.ts | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/next/api/src/response/file.ts b/next/api/src/response/file.ts index af41b78a5..1d0bd842c 100644 --- a/next/api/src/response/file.ts +++ b/next/api/src/response/file.ts @@ -50,10 +50,8 @@ const getThumbnailURL = (file: File) => { return url; }; -const ENABLE_FILE_TRANSFER = process.env.ENABLE_FILE_TRANSFER; - export class FileResponse { - constructor(readonly file: File) {} + constructor(readonly file: File, private transfer = false) {} toJSON() { const { id, name, mime, url, metaData } = this.file; @@ -66,7 +64,7 @@ export class FileResponse { metaData, url: needSignature ? sign(url) - : ENABLE_FILE_TRANSFER + : this.transfer ? `${config.host}/api/2/files/${id}/content` : url, thumbnailUrl: needSignature ? sign(thumbnailURL) : thumbnailURL, diff --git a/next/api/src/response/reply.ts b/next/api/src/response/reply.ts index f84d32f60..041fec376 100644 --- a/next/api/src/response/reply.ts +++ b/next/api/src/response/reply.ts @@ -4,7 +4,7 @@ import { FileResponse } from './file'; import { UserResponse } from './user'; export class ReplyResponse { - constructor(readonly reply: Reply) {} + constructor(readonly reply: Reply, private transferFile = false) {} toJSON() { return { @@ -13,7 +13,7 @@ export class ReplyResponse { contentSafeHTML: sanitize(this.reply.contentHTML), author: this.reply.author && new UserResponse(this.reply.author).toJSON(), isCustomerService: this.reply.isCustomerService, - files: this.reply.files?.map((file) => new FileResponse(file).toJSON()), + files: this.reply.files?.map((file) => new FileResponse(file, this.transferFile).toJSON()), internal: this.reply.internal, edited: this.reply.edited, createdAt: this.reply.createdAt.toISOString(), diff --git a/next/api/src/response/ticket.ts b/next/api/src/response/ticket.ts index 45779aa20..75772153b 100644 --- a/next/api/src/response/ticket.ts +++ b/next/api/src/response/ticket.ts @@ -12,7 +12,7 @@ export interface TicketResponseOptions { } class BaseTicketResponse { - constructor(readonly ticket: Ticket) {} + constructor(readonly ticket: Ticket, private transferFile = false) {} toJSON({ includeMetaKeys = [], includePrivateTags, includeTags }: TicketResponseOptions = {}) { return { @@ -29,7 +29,7 @@ class BaseTicketResponse { assignee: this.ticket.assignee ? new UserResponse(this.ticket.assignee) : undefined, groupId: this.ticket.groupId, group: this.ticket.group ? new GroupResponse(this.ticket.group) : undefined, - files: this.ticket.files?.map((file) => new FileResponse(file)), + files: this.ticket.files?.map((file) => new FileResponse(file, this.transferFile)), status: this.ticket.status, evaluation: this.ticket.evaluation, replyCount: this.ticket.replyCount,