diff --git a/apps/frontend/src/composables/servers/modrinth-servers.ts b/apps/frontend/src/composables/servers/modrinth-servers.ts index 8c79cc62d..5bf8704aa 100644 --- a/apps/frontend/src/composables/servers/modrinth-servers.ts +++ b/apps/frontend/src/composables/servers/modrinth-servers.ts @@ -11,6 +11,7 @@ import { WSModule, FSModule, } from "./modules/index.ts"; +import { ScheudlingModule } from "./modules/scheduling.ts"; export function handleError(err: any) { if (err instanceof ModrinthServerError && err.v1Error) { @@ -40,6 +41,7 @@ export class ModrinthServer { readonly startup: StartupModule; readonly ws: WSModule; readonly fs: FSModule; + readonly scheduling: ScheudlingModule; constructor(serverId: string) { this.serverId = serverId; @@ -51,6 +53,7 @@ export class ModrinthServer { this.startup = new StartupModule(this); this.ws = new WSModule(this); this.fs = new FSModule(this); + this.scheduling = new ScheudlingModule(this); } async createMissingFolders(path: string): Promise { @@ -192,7 +195,16 @@ export class ModrinthServer { const modulesToRefresh = modules.length > 0 ? modules - : (["general", "content", "backups", "network", "startup", "ws", "fs"] as ModuleName[]); + : ([ + "general", + "content", + "backups", + "network", + "startup", + "ws", + "fs", + "scheduling", + ] as ModuleName[]); for (const module of modulesToRefresh) { try { @@ -237,6 +249,8 @@ export class ModrinthServer { case "fs": await this.fs.fetch(); break; + case "scheduling": + await this.scheduling.fetch(); } } catch (error) { this.errors[module] = { diff --git a/apps/frontend/src/composables/servers/modules/scheduling.ts b/apps/frontend/src/composables/servers/modules/scheduling.ts new file mode 100644 index 000000000..1cc21a0ea --- /dev/null +++ b/apps/frontend/src/composables/servers/modules/scheduling.ts @@ -0,0 +1,26 @@ +import type { ScheduledTask } from "@modrinth/utils"; +import { useServersFetch } from "../servers-fetch.ts"; +import { ServerModule } from "./base.ts"; + +export class ScheudlingModule extends ServerModule { + tasks: ScheduledTask[] = []; + + async fetch(): Promise { + this.tasks = await useServersFetch( + `servers/${this.serverId}/options/schedules`, + { version: 1 }, + ); + } + + async deleteTask(_task: ScheduledTask): Promise { + // ... + } + + async createTask(_task: ScheduledTask): Promise { + return await 1; + } + + async editTask(_taskID: number, _task: Partial) { + // ... + } +} diff --git a/apps/frontend/src/pages/servers/manage/[id].vue b/apps/frontend/src/pages/servers/manage/[id].vue index 35fd28343..b5083c188 100644 --- a/apps/frontend/src/pages/servers/manage/[id].vue +++ b/apps/frontend/src/pages/servers/manage/[id].vue @@ -480,7 +480,7 @@ const loadModulesPromise = Promise.resolve().then(() => { if (server.general?.status === "suspended") { return; } - return server.refresh(["content", "backups", "network", "startup", "fs"]); + return server.refresh(["content", "backups", "network", "startup", "fs", "scheduling"]); }); provide("modulesLoaded", loadModulesPromise); diff --git a/apps/frontend/src/pages/servers/manage/[id]/options.vue b/apps/frontend/src/pages/servers/manage/[id]/options.vue index 519a2a149..f3c6b50a9 100644 --- a/apps/frontend/src/pages/servers/manage/[id]/options.vue +++ b/apps/frontend/src/pages/servers/manage/[id]/options.vue @@ -16,7 +16,7 @@ import { CardIcon, UserIcon, WrenchIcon, - CalendarSyncIcon + CalendarSyncIcon, } from "@modrinth/assets"; import { ModrinthServer } from "~/composables/servers/modrinth-servers.ts"; import type { BackupInProgressReason } from "~/pages/servers/manage/[id].vue"; @@ -36,7 +36,11 @@ useHead({ const navLinks = [ { icon: SettingsIcon, label: "General", href: `/servers/manage/${serverId}/options` }, { icon: WrenchIcon, label: "Platform", href: `/servers/manage/${serverId}/options/loader` }, - { icon: CalendarSyncIcon, label: "Task Scheduling", href: `/servers/manage/${serverId}/options/scheduling`}, + { + icon: CalendarSyncIcon, + label: "Task Scheduling", + href: `/servers/manage/${serverId}/options/scheduling`, + }, { icon: TextQuoteIcon, label: "Startup", href: `/servers/manage/${serverId}/options/startup` }, { icon: VersionIcon, label: "Network", href: `/servers/manage/${serverId}/options/network` }, { icon: ListIcon, label: "Properties", href: `/servers/manage/${serverId}/options/properties` }, diff --git a/apps/frontend/src/pages/servers/manage/[id]/options/scheduling.vue b/apps/frontend/src/pages/servers/manage/[id]/options/scheduling.vue index 4b70629fe..9559a3928 100644 --- a/apps/frontend/src/pages/servers/manage/[id]/options/scheduling.vue +++ b/apps/frontend/src/pages/servers/manage/[id]/options/scheduling.vue @@ -179,8 +179,7 @@ const props = defineProps<{ server: ModrinthServer; }>(); -const tasks = ref([]); - +const tasks = ref(props.server.scheduling.tasks); const selectedTasks = ref([]); const sortBy = ref("Name"); const descending = ref(false); diff --git a/packages/utils/servers/types/api.ts b/packages/utils/servers/types/api.ts index a9ba86f10..a8ec5fc9e 100644 --- a/packages/utils/servers/types/api.ts +++ b/packages/utils/servers/types/api.ts @@ -16,4 +16,12 @@ export interface ModuleError { timestamp: number } -export type ModuleName = 'general' | 'content' | 'backups' | 'network' | 'startup' | 'ws' | 'fs' +export type ModuleName = + | 'general' + | 'content' + | 'backups' + | 'network' + | 'startup' + | 'ws' + | 'fs' + | 'scheduling'