Skip to content

Commit

Permalink
feat: transfer file manaully
Browse files Browse the repository at this point in the history
  • Loading branch information
sdjdd committed Mar 30, 2024
1 parent 6213e86 commit 58fd4a4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
6 changes: 2 additions & 4 deletions next/api/src/response/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions next/api/src/response/reply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions next/api/src/response/ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down

0 comments on commit 58fd4a4

Please sign in to comment.