import Inject from "@entity-access/entity-access/dist/di/di.js"; import { Prepare } from "@entity-access/server-pages/dist/decorators/Prepare.js"; import SocialMailContext from "../../../../../../../server/model/SocialMailContext.js"; import Page from "@entity-access/server-pages/dist/Page.js"; import TempFileService from "../../../../../../../server/storage/TempFileService.js"; import { TempFileResult } from "@entity-access/server-pages/dist/Content.js"; import WebSiteChannelService from "../../../../../../../server/smtp/services/WebSiteChannelService.js"; import Sql from "@entity-access/entity-access/dist/sql/Sql.js"; @Prepare.authorize export default class extends Page { @Inject private db: SocialMailContext; @Inject private tfs: TempFileService; @Inject private wcs: WebSiteChannelService; async run() { const [channelID, emailID, messageID, fileID] = this.childPath as any[]; const host = this.request.host; const { mailboxes, domains } = await this.wcs.getChannelAssociations(host); const q = mailboxes ? this.db.appFiles .where({ fileID, emailID, messageID, channelID, mailboxes }, (x, p) => x.appFileID === p.fileID && x.emailID === p.emailID && x.email.headerMessageID === p.messageID && x.email.channelEmails.some((c) => Sql.in(c.mailboxID, p.mailboxes)) ) : this.db.appFiles .where({ fileID, emailID, messageID, channelID, domains }, (x, p) => x.appFileID === p.fileID && x.emailID === p.emailID && x.email.headerMessageID === p.messageID && x.email.channelEmails.some((c) => Sql.in(c.mailbox.domainID, p.domains)) ); // verify host ... const file = await q .first(); const body = await this.tfs.downloadAppFile(file); this.cacheControl = "public, max-age=2592000, immutable"; return new TempFileResult( body, { contentDisposition: "inline", immutable: true, etag: false } ); } }