feat: api/daemon/{start,stop,restart,status}
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import type {
|
import type {
|
||||||
DefAPINamespace,
|
DefAPINamespace,
|
||||||
} from "@strpc/def";
|
} from "@strpc/def";
|
||||||
import { GET, POST } from '@strpc/def';
|
import { GET, POST } from '@strpc/def';
|
||||||
|
|
||||||
@@ -17,11 +17,17 @@ import type {
|
|||||||
|
|
||||||
|
|
||||||
export type {
|
export type {
|
||||||
InferResponse,
|
InferResponse,
|
||||||
InferError,
|
InferError,
|
||||||
InferQuery,
|
InferQuery,
|
||||||
} from "@strpc/def";
|
} from "@strpc/def";
|
||||||
export type * as def from './def/index.js';
|
export type * as def from './def/index.js';
|
||||||
|
|
||||||
export const structure = {
|
export const structure = {
|
||||||
|
daemon: {
|
||||||
|
status: GET<ValidResponse & { isRunning: boolean, lastExecuted?: string }>(),
|
||||||
|
start: POST<ValidResponse>(),
|
||||||
|
stop: POST<ValidResponse>(),
|
||||||
|
restart: POST<ValidResponse>(),
|
||||||
|
}
|
||||||
} satisfies DefAPINamespace;
|
} satisfies DefAPINamespace;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import type { APINamespace, APINamespaceType } from '@strpc/express';
|
||||||
|
import { status } from './status.js';
|
||||||
|
import { start } from './start.js';
|
||||||
|
import { stop } from './stop.js';
|
||||||
|
import { restart } from './restart.js';
|
||||||
|
import type { structure } from "@sammo/api_def";
|
||||||
|
|
||||||
|
export const daemon = {
|
||||||
|
status,
|
||||||
|
start,
|
||||||
|
stop,
|
||||||
|
restart,
|
||||||
|
} satisfies APINamespaceType<typeof structure['daemon']>;
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { getGameEngineController } from "@/GameEngineController.js";
|
||||||
|
import { ReqACL } from "@/procDecorator/ReqACL.js";
|
||||||
|
import { ReqLogin } from "@/procDecorator/ReqLogin.js";
|
||||||
|
import type { structure } from "@sammo/api_def";
|
||||||
|
import { StartSession } from "@sammo/server_util";
|
||||||
|
import { type APIReturnType, POST } from "@strpc/express";
|
||||||
|
import { declProcDecorators } from "@strpc/express/proc_decorator";
|
||||||
|
|
||||||
|
type BaseAPI = typeof structure.daemon.restart;
|
||||||
|
type RType = APIReturnType<BaseAPI>;
|
||||||
|
|
||||||
|
export const restart = POST<BaseAPI>()(declProcDecorators(
|
||||||
|
StartSession,
|
||||||
|
ReqLogin,
|
||||||
|
ReqACL('StopAndResumeServer'),
|
||||||
|
))
|
||||||
|
(async (query, ctx): RType => {
|
||||||
|
const controller = getGameEngineController();
|
||||||
|
|
||||||
|
await controller.restart();
|
||||||
|
return {
|
||||||
|
result: true,
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { getGameEngineController } from "@/GameEngineController.js";
|
||||||
|
import { ReqACL } from "@/procDecorator/ReqACL.js";
|
||||||
|
import { ReqLogin } from "@/procDecorator/ReqLogin.js";
|
||||||
|
import type { structure } from "@sammo/api_def";
|
||||||
|
import { StartSession } from "@sammo/server_util";
|
||||||
|
import { type APIReturnType, POST } from "@strpc/express";
|
||||||
|
import { declProcDecorators } from "@strpc/express/proc_decorator";
|
||||||
|
|
||||||
|
type BaseAPI = typeof structure.daemon.start;
|
||||||
|
type RType = APIReturnType<BaseAPI>;
|
||||||
|
|
||||||
|
export const start = POST<BaseAPI>()(declProcDecorators(
|
||||||
|
StartSession,
|
||||||
|
ReqLogin,
|
||||||
|
ReqACL('StopAndResumeServer'),
|
||||||
|
))
|
||||||
|
(async (query, ctx): RType => {
|
||||||
|
const controller = getGameEngineController();
|
||||||
|
|
||||||
|
if(controller.isRunning) {
|
||||||
|
return {
|
||||||
|
result: false,
|
||||||
|
reason: 'Already running',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await controller.start();
|
||||||
|
return {
|
||||||
|
result: true,
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { getGameEngineController } from "@/GameEngineController.js";
|
||||||
|
import { ReqACL } from "@/procDecorator/ReqACL.js";
|
||||||
|
import { ReqLogin } from "@/procDecorator/ReqLogin.js";
|
||||||
|
import type { structure } from "@sammo/api_def";
|
||||||
|
import { StartSession } from "@sammo/server_util";
|
||||||
|
import { GET, type APIReturnType } from "@strpc/express";
|
||||||
|
import { declProcDecorators } from "@strpc/express/proc_decorator";
|
||||||
|
|
||||||
|
type BaseAPI = typeof structure.daemon.status;
|
||||||
|
type RType = APIReturnType<BaseAPI>;
|
||||||
|
|
||||||
|
export const status = GET<BaseAPI>()(declProcDecorators(
|
||||||
|
StartSession,
|
||||||
|
ReqLogin,
|
||||||
|
))
|
||||||
|
(async (query, ctx): RType => {
|
||||||
|
const controller = getGameEngineController();
|
||||||
|
const isRunning = controller.isRunning
|
||||||
|
const lastExecuted = controller.lastExecuted?.toISOString() ?? undefined;
|
||||||
|
return {
|
||||||
|
result: true,
|
||||||
|
isRunning,
|
||||||
|
lastExecuted,
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { getGameEngineController } from "@/GameEngineController.js";
|
||||||
|
import { ReqACL } from "@/procDecorator/ReqACL.js";
|
||||||
|
import { ReqLogin } from "@/procDecorator/ReqLogin.js";
|
||||||
|
import type { structure } from "@sammo/api_def";
|
||||||
|
import { StartSession } from "@sammo/server_util";
|
||||||
|
import { type APIReturnType, POST } from "@strpc/express";
|
||||||
|
import { declProcDecorators } from "@strpc/express/proc_decorator";
|
||||||
|
|
||||||
|
type BaseAPI = typeof structure.daemon.stop;
|
||||||
|
type RType = APIReturnType<BaseAPI>;
|
||||||
|
|
||||||
|
export const stop = POST<BaseAPI>()(declProcDecorators(
|
||||||
|
StartSession,
|
||||||
|
ReqLogin,
|
||||||
|
ReqACL('StopAndResumeServer'),
|
||||||
|
))
|
||||||
|
(async (query, ctx): RType => {
|
||||||
|
const controller = getGameEngineController();
|
||||||
|
|
||||||
|
if(!controller.isRunning) {
|
||||||
|
return {
|
||||||
|
result: false,
|
||||||
|
reason: 'Already stopped',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await controller.stop();
|
||||||
|
return {
|
||||||
|
result: true,
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { structure } from "@sammo/api_def";
|
import type { structure } from "@sammo/api_def";
|
||||||
import type { APINamespaceType } from "@strpc/express";
|
import type { APINamespaceType } from "@strpc/express";
|
||||||
|
import { daemon } from "./daemon/index.js";
|
||||||
export const sammoAPI = {
|
export const sammoAPI = {
|
||||||
|
daemon,
|
||||||
} satisfies APINamespaceType<typeof structure>;
|
} satisfies APINamespaceType<typeof structure>;
|
||||||
Reference in New Issue
Block a user