import Inject from "@entity-access/entity-access/dist/di/di.js"; import Page from "@entity-access/server-pages/dist/Page.js"; import { Prepare } from "@entity-access/server-pages/dist/decorators/Prepare.js"; import EmailLogService from "../../../../../server/services/email-logs/EmailLogService.js"; @Prepare.authorize export default class extends Page { @Inject emailLogService: EmailLogService; async run() { const [logID, fileName] = this.childPath as any[]; if (logID === "null") { return this.content({ body: "", contentType: "text/plain" }); } this.sessionUser.ensureLoggedIn(); const tf = await this.emailLogService.load({ logID }); const body = await tf.readAsText(); this.cacheControl = "public, max-age=2592000, immutable"; if (fileName) { return this.content({ body, headers: { "content-disposition": `download;filename=${encodeURIComponent(fileName)}` }, contentType: "message/rfc822", compress: true }); } return this.content({ body, contentType: "text/plain", compress: true }); } }