first commit

This commit is contained in:
2026-01-02 15:49:01 +03:00
commit 4348f76a7c
80 changed files with 10133 additions and 0 deletions

View 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;

View 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;
};