import Inject from "@entity-access/entity-access/dist/di/di.js"; import SocialMailContext from "../../../../../server/model/SocialMailContext.js"; import { TempFileResult } from "@entity-access/server-pages/dist/Content.js"; import Page from "@entity-access/server-pages/dist/Page.js"; import FileConversionService from "../../../../../server/services/convert/FileConversionService.js"; export default class extends Page { @Inject private db: SocialMailContext; @Inject private fcs: FileConversionService; async run() { const [type, _siteID, _assetID, fileContentID, fileName] = this.childPath as any[]; // draft is only visible to logged in user this.db.verifyFilters = false; this.db.raiseEvents = false; const appFile = await this.db.appFiles .where({ fileContentID }, (x, p) => x.fileContentID === p.fileContentID ) .include((x) => x.fileContent) .first(); if (!appFile) { return this.notFound(); } this.cacheControl = "public, max-age=2592000, immutable"; const file = await this.fcs.downloadConvertedFile({ type, fileContentID, appFile, fileName }); // let file = await this.tfs.downloadFileContent(fileContent, fileVersion.file); // // transform here... // if (/^(size|jpg|png|webp|gif|face\-circle)\(/i.test(type)) { // // resize... // const key = this.request.path; // const ttl = TimeSpan.fromDays(30); // file = await this.cacheService.get({ key, ttl, factory: async (ci) => { // try { // const ics = ServiceProvider.resolve(this, ImageConverterService); // return await ics.transform(type, file, this.childPath[this.childPath.length-1] ); // } catch { // ci.expiry = DateTime.now.addDays(7); // ci.slide = false; // return new LocalFile(ImagesFolder.file("lock/lock.png"), "lock.png", "image/png", () => void 0); // } // } // }); // } return new TempFileResult( file, { contentDisposition: "inline", immutable: true, etag: false } ); } }