library-ts/node/users/handlers/apps/load.ts

36 lines
1.1 KiB
TypeScript
Raw Normal View History

2025-11-15 18:58:30 +00:00
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<any>( filePath );
return this.sendDataInfo( "Data loaded", data );
}
}