// @ts-check import fs from 'fs'; import path from 'path'; import { Request, Response, Application } from 'express'; import { WebSocketServer } from 'ws'; import { Server as HttpServer } from 'http'; interface LogoutRouteParams { req: Request; res: Response; app?: Application; wss?: WebSocketServer; wssConsole?: WebSocketServer; Shellwss?: WebSocketServer; server?: HttpServer; } interface LogoutExpressRouteModule { method: "get" | "post" | "put" | "delete" | "patch" | "options" | "head" | "all"; path: string; install: (params: Pick) => Promise | void; } const ACC_FILE_PATH: string = path.resolve(__dirname, '../models/data/acc.json'); const ACC_DIR_PATH: string = path.dirname(ACC_FILE_PATH); export const modules: LogoutExpressRouteModule[] = [ { method: 'post', path: '/logout', install: async ({ req, res }: Pick): Promise => { const html: string = ` Logout

You have been logged out. localStorage items 'exocore-token' and 'exocore-cookies' have been cleared.

{
  "status": "success"
}
`; res.setHeader('Content-Type', 'text/html'); res.send(html); try { if (!fs.existsSync(ACC_DIR_PATH)) { await fs.promises.mkdir(ACC_DIR_PATH, { recursive: true }); } await fs.promises.writeFile(ACC_FILE_PATH, JSON.stringify({}, null, 2)); } catch (fileError: unknown) { const errMsg = fileError instanceof Error ? fileError.message : String(fileError); console.error(`Failed to clear or write acc.json during logout: ${errMsg}`, fileError); } }, }, ];