Implemented cascade deletion for removed sources
This commit is contained in:
@@ -3,6 +3,9 @@ name: Build and Publish Container Image
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
|
tags: [ 'v*' ]
|
||||||
|
release:
|
||||||
|
types: [ published ]
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -32,9 +35,11 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
images: ghcr.io/${{ github.repository_owner }}/nodecast-tv
|
images: ghcr.io/${{ github.repository_owner }}/nodecast-tv
|
||||||
tags: |
|
tags: |
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
type=sha
|
type=sha
|
||||||
type=ref,event=branch
|
type=ref,event=branch
|
||||||
type=raw,value=latest
|
type=raw,value=latest,enable={{is_default_branch}}
|
||||||
|
|
||||||
- name: Build and push Container image
|
- name: Build and push Container image
|
||||||
uses: docker/build-push-action@v5
|
uses: docker/build-push-action@v5
|
||||||
|
|||||||
+2
-1
@@ -144,8 +144,9 @@ const sources = {
|
|||||||
async delete(id) {
|
async delete(id) {
|
||||||
const db = await loadDb();
|
const db = await loadDb();
|
||||||
db.sources = db.sources.filter(s => s.id !== parseInt(id));
|
db.sources = db.sources.filter(s => s.id !== parseInt(id));
|
||||||
// Also delete related hidden items
|
// Also delete related hidden items and favorites
|
||||||
db.hiddenItems = db.hiddenItems.filter(h => h.source_id !== parseInt(id));
|
db.hiddenItems = db.hiddenItems.filter(h => h.source_id !== parseInt(id));
|
||||||
|
db.favorites = db.favorites.filter(f => f.source_id !== parseInt(id));
|
||||||
await saveDb(db);
|
await saveDb(db);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const { sources } = require('../db');
|
const { sources } = require('../db');
|
||||||
|
const { getDb } = require('../db/sqlite');
|
||||||
const xtreamApi = require('../services/xtreamApi');
|
const xtreamApi = require('../services/xtreamApi');
|
||||||
const syncService = require('../services/syncService');
|
const syncService = require('../services/syncService');
|
||||||
|
|
||||||
@@ -108,11 +109,29 @@ router.put('/:id', async (req, res) => {
|
|||||||
// Delete source
|
// Delete source
|
||||||
router.delete('/:id', async (req, res) => {
|
router.delete('/:id', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const existing = await sources.getById(req.params.id);
|
const sourceId = parseInt(req.params.id);
|
||||||
|
const existing = await sources.getById(sourceId);
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
return res.status(404).json({ error: 'Source not found' });
|
return res.status(404).json({ error: 'Source not found' });
|
||||||
}
|
}
|
||||||
await sources.delete(req.params.id);
|
|
||||||
|
// Cascade delete: Clean up SQLite data for this source
|
||||||
|
const db = getDb();
|
||||||
|
const deleteCategories = db.prepare('DELETE FROM categories WHERE source_id = ?');
|
||||||
|
const deleteItems = db.prepare('DELETE FROM playlist_items WHERE source_id = ?');
|
||||||
|
const deleteEpg = db.prepare('DELETE FROM epg_programs WHERE source_id = ?');
|
||||||
|
const deleteSyncStatus = db.prepare('DELETE FROM sync_status WHERE source_id = ?');
|
||||||
|
|
||||||
|
const catResult = deleteCategories.run(sourceId);
|
||||||
|
const itemResult = deleteItems.run(sourceId);
|
||||||
|
const epgResult = deleteEpg.run(sourceId);
|
||||||
|
deleteSyncStatus.run(sourceId);
|
||||||
|
|
||||||
|
console.log(`[Source] Cascade delete for source ${sourceId}: ${catResult.changes} categories, ${itemResult.changes} items, ${epgResult.changes} EPG programs`);
|
||||||
|
|
||||||
|
// Delete source config and related hidden items (favorites handled by db.js)
|
||||||
|
await sources.delete(sourceId);
|
||||||
|
|
||||||
res.json({ success: true });
|
res.json({ success: true });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error deleting source:', err);
|
console.error('Error deleting source:', err);
|
||||||
|
|||||||
Reference in New Issue
Block a user