feat(loop): aynı torrent için birden fazla iş desteği ekle
Aynı torrent hash'i için oluşturulan yeni loop işleri, mevcut aktif işleri otomatik olarak durdurur. Stop-by-hash endpoint'i tüm ilgili işleri durduracak şekilde güncellendi. TorrentTable bileşeni çoklu işleri doğru şekilde işleyecek ve profil adını en güncel aktif işten alacak şekilde yeniden yazıldı. LoopJob arayüzüne createdAt ve updatedAt alanları eklendi.
This commit is contained in:
@@ -66,6 +66,16 @@ export const createLoopJob = async (
|
||||
updatedAt: now,
|
||||
};
|
||||
const db = await readDb();
|
||||
const active = db.loopJobs.filter((j) => j.torrentHash === job.torrentHash && j.status !== "COMPLETED" && j.status !== "STOPPED");
|
||||
for (const existing of active) {
|
||||
existing.status = "STOPPED";
|
||||
existing.nextRunAt = undefined;
|
||||
existing.currentRun = undefined;
|
||||
existing.updatedAt = nowIso();
|
||||
}
|
||||
if (active.length) {
|
||||
await writeDb(db);
|
||||
}
|
||||
db.loopJobs.push(job);
|
||||
await writeDb(db);
|
||||
await logJob(job.id, "INFO", `Loop job started for ${job.name}`, "JOB_STARTED");
|
||||
|
||||
@@ -91,18 +91,24 @@ router.post("/stop-by-hash", async (req, res) => {
|
||||
return res.status(400).json({ error: "Missing hash" });
|
||||
}
|
||||
const db = await readDb();
|
||||
const job = db.loopJobs.find((j) => j.torrentHash === hash);
|
||||
if (!job) {
|
||||
const jobs = db.loopJobs.filter((j) => j.torrentHash === hash);
|
||||
if (!jobs.length) {
|
||||
return res.status(404).json({ error: "Job not found" });
|
||||
}
|
||||
const stopped = await stopLoopJob(job.id);
|
||||
const stopped = [] as any[];
|
||||
for (const job of jobs) {
|
||||
const result = await stopLoopJob(job.id);
|
||||
if (result) {
|
||||
stopped.push(result);
|
||||
}
|
||||
}
|
||||
try {
|
||||
const qbit = getQbitClient();
|
||||
await qbit.deleteTorrent(hash, true);
|
||||
} catch (error) {
|
||||
// Best-effort delete
|
||||
}
|
||||
res.json(stopped);
|
||||
res.json({ ok: true, stopped });
|
||||
});
|
||||
|
||||
router.post("/dry-run", async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user