feat: add Toolset service for temp0/ watching and GFF change detection
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
import { Router } from "express";
|
||||
import {
|
||||
startToolsetWatcher,
|
||||
stopToolsetWatcher,
|
||||
isWatcherActive,
|
||||
getPendingChanges,
|
||||
getChange,
|
||||
applyChange,
|
||||
applyAllChanges,
|
||||
discardChange,
|
||||
discardAllChanges,
|
||||
} from "../services/toolset.service.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get("/status", (_req, res) => {
|
||||
res.json({
|
||||
active: isWatcherActive(),
|
||||
pendingCount: getPendingChanges().length,
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/start", (_req, res) => {
|
||||
startToolsetWatcher();
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
router.post("/stop", (_req, res) => {
|
||||
stopToolsetWatcher();
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
router.get("/changes", (_req, res) => {
|
||||
const changes = getPendingChanges().map((c) => ({
|
||||
filename: c.filename,
|
||||
gffType: c.gffType,
|
||||
repoPath: c.repoPath,
|
||||
timestamp: c.timestamp,
|
||||
}));
|
||||
res.json(changes);
|
||||
});
|
||||
|
||||
router.get("/changes/:filename", (req, res) => {
|
||||
const change = getChange(req.params.filename);
|
||||
if (!change) return res.status(404).json({ error: "change not found" });
|
||||
res.json(change);
|
||||
});
|
||||
|
||||
router.post("/apply", async (req, res) => {
|
||||
const { files } = req.body;
|
||||
if (!files || !Array.isArray(files))
|
||||
return res.status(400).json({ error: "files array required" });
|
||||
const results = [];
|
||||
for (const f of files) {
|
||||
results.push({ file: f, applied: await applyChange(f) });
|
||||
}
|
||||
res.json(results);
|
||||
});
|
||||
|
||||
router.post("/apply-all", async (_req, res) => {
|
||||
const applied = await applyAllChanges();
|
||||
res.json({ applied });
|
||||
});
|
||||
|
||||
router.post("/discard", (req, res) => {
|
||||
const { files } = req.body;
|
||||
if (!files || !Array.isArray(files))
|
||||
return res.status(400).json({ error: "files array required" });
|
||||
for (const f of files) discardChange(f);
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
router.post("/discard-all", (_req, res) => {
|
||||
discardAllChanges();
|
||||
res.json({ ok: true });
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user