import Controller from "./Controller"; import type DashboardViewModel from "../models/home/DashboardViewModel"; import UserService from "../services/UserService"; import DomainService from "../services/DomainService"; import ArrayUtility from "../utilities/ArrayUtility"; export default class HomeController extends Controller { public async Index_Get_AllowAnonymous() { if (this.session) { const dashboardViewModel: DashboardViewModel = { recentUploads: await UserService.GetRecentUploads(this.session.userId), domains: ArrayUtility.ToIdKeyedDict(await DomainService.LoadDomains()) } return this.view("dashboard",dashboardViewModel); } return this.view(); } public async ImageList_Get() { return this.view(); } public async Upload_Post_AllowAnonymous() { const data = await this.req.file(); if (data && data.type === "file") { let uploadKey: string = ""; let host: string = ""; //console.log(this.req.headers); if ("upload-key" in this.req.headers) { // @ts-ignore uploadKey = this.req.headers["upload-key"]; } else { return this.unauthorised("Upload key invalid or missing."); } if ("host" in this.req.headers) { // @ts-ignore host = this.req.headers["host"]; } else { return this.badRequest("Host header missing?!"); } const user = await UserService.GetByUploadKey(uploadKey); if (!user) { return this.unauthorised("Upload key invalid or missing."); } const fileUrl = await UserService.UploadMedia(user.Id, host, data); if (!fileUrl) { return this.badRequest("This domain is not registered to your EUS account."); } return this.ok(fileUrl); } return this.badRequest(); } }