import Inject from "@entity-access/entity-access/dist/di/di.js"; import { TempFileResult } from "@entity-access/server-pages/dist/Content.js"; import Page from "@entity-access/server-pages/dist/Page.js"; import WebSiteContentService from "../../server/services/files/WebSiteContentService.js"; export default class extends Page { @Inject private siteContentService: WebSiteContentService; async run() { const { forceDownload } = this.query; const file = this.childPath[0]; // check if the host name is part of any website.. const host = this.request.hostName; const webSite = await this.siteContentService.getCurrentSnapshotFolder(host); if (webSite) { // this is a static web site... // if path is empty... load /index.html.... let path = this.childPath; if (!file) { path = ["index.html"]; } const appFile = await this.siteContentService.getSnapshotFile(webSite, path); if (!appFile) { return this.notFound(); } return new TempFileResult( appFile, { contentDisposition: forceDownload ? "attachment" : "inline", etag: false } ); } // check if it has `draft-` prefix... // if (!/^draft\-/i.test(host)) { // return this.notFound(); // } // host = host.substring(6); // const draft = await this.websiteService.getDraftFolder(host); // if (draft) { // // deliver file... without caching... // let path = this.childPath; // if (!file) { // path = ["index.html"]; // } // const appFile = await this.websiteService.folderContent(draft.appFileID, path); // if (!appFile) { // return this.notFound(); // } // delete appFile.fileContent; // const tfs = ServiceProvider.resolve(this, TempFileService); // const localFile = await tfs.downloadAppFile(appFile); // return new TempFileResult( // localFile, // { // contentDisposition: forceDownload // ? "attachment" // : "inline", // etag: false // } // ); // } return this.notFound(); } }