import { RequestHandler, RequestType } from "../../RequestHandler"; import { FastifyRequest, FastifyReply } from 'fastify'; import { UserIsLoggedIn } from "../../requirements/user/UserIsLoggedIn"; import { UserCanUseApp } from "./UserCanUseApp"; import { FilesSync } from "../../../files/FilesSync"; import { Files } from "../../../files/Files"; export class AppsLoadHandler extends RequestHandler { static url = "/apps/load"; constructor() { super( RequestType.POST, AppsLoadHandler.url, [ new UserIsLoggedIn(), new UserCanUseApp() ] ); } async _handle( request:FastifyRequest, reply:FastifyReply ) { let requestBody = request.body; let appData = requestBody as { appData: any, appID:string }; let user = await this.getUser(); let filePath = Files.joinPaths( [ this._ums._settings.appsPath, appData.appID, user.id + ".json" ] ); let exists = await Files.exists( filePath ); if ( ! exists ) { return this.sendInfo( "No data saved" ); } let data = await Files.loadJSON( filePath ); return this.sendDataInfo( "Data loaded", data ); } }