first commit
This commit is contained in:
11
apps/server/src/status/status.routes.ts
Normal file
11
apps/server/src/status/status.routes.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Router } from "express";
|
||||
import { getStatusSnapshot } from "./status.service"
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get("/", async (_req, res) => {
|
||||
const snapshot = await getStatusSnapshot();
|
||||
res.json(snapshot);
|
||||
});
|
||||
|
||||
export default router;
|
||||
45
apps/server/src/status/status.service.ts
Normal file
45
apps/server/src/status/status.service.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { DbSchema, LoopJob } from "../types"
|
||||
import { QbitCapabilities, QbitTorrentInfo, QbitTransferInfo } from "../qbit/qbit.types"
|
||||
import { readDb } from "../storage/jsondb"
|
||||
|
||||
export interface StatusSnapshot {
|
||||
qbit: {
|
||||
ok: boolean;
|
||||
version?: string;
|
||||
capabilities?: QbitCapabilities;
|
||||
lastError?: string;
|
||||
};
|
||||
torrents: QbitTorrentInfo[];
|
||||
transfer?: QbitTransferInfo;
|
||||
jobs: LoopJob[];
|
||||
}
|
||||
|
||||
let snapshot: StatusSnapshot = {
|
||||
qbit: { ok: false },
|
||||
torrents: [],
|
||||
transfer: undefined,
|
||||
jobs: [],
|
||||
};
|
||||
|
||||
export const setQbitStatus = (status: StatusSnapshot["qbit"]) => {
|
||||
snapshot.qbit = status;
|
||||
};
|
||||
|
||||
export const setTorrentsStatus = (
|
||||
torrents: QbitTorrentInfo[],
|
||||
transfer?: QbitTransferInfo
|
||||
) => {
|
||||
snapshot.torrents = torrents;
|
||||
snapshot.transfer = transfer;
|
||||
};
|
||||
|
||||
export const refreshJobsStatus = async () => {
|
||||
const db: DbSchema = await readDb();
|
||||
snapshot.jobs = db.loopJobs;
|
||||
return snapshot.jobs;
|
||||
};
|
||||
|
||||
export const getStatusSnapshot = async (): Promise<StatusSnapshot> => {
|
||||
await refreshJobsStatus();
|
||||
return snapshot;
|
||||
};
|
||||
Reference in New Issue
Block a user