diff --git a/backend/package.json b/backend/package.json index bdf669e..95b4a26 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.19.2", + "version": "2.19.3", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/restful/collections.js b/backend/src/restful/collections.js index edffbd4..1169984 100644 --- a/backend/src/restful/collections.js +++ b/backend/src/restful/collections.js @@ -1,5 +1,5 @@ import { deleteByName, findByName, updateByName } from '@/utils/database'; -import { COLLECTIONS_KEY, ARTIFACTS_KEY } from '@/constants'; +import { COLLECTIONS_KEY, ARTIFACTS_KEY, FILES_KEY } from '@/constants'; import { failed, success } from '@/restful/response'; import $ from '@/core/app'; import { RequestInvalidError, ResourceNotFoundError } from '@/restful/errors'; @@ -106,7 +106,18 @@ function updateCollection(req, res) { artifact.source = newCol.name; } } + // update all files referring this collection + const allFiles = $.read(FILES_KEY) || []; + for (const file of allFiles) { + if ( + file.sourceType === 'collection' && + file.sourceName === oldCol.name + ) { + file.sourceName = newCol.name; + } + } $.write(allArtifacts, ARTIFACTS_KEY); + $.write(allFiles, FILES_KEY); } updateByName(allCols, name, newCol); diff --git a/backend/src/restful/file.js b/backend/src/restful/file.js index 9d0f2b2..2c207c1 100644 --- a/backend/src/restful/file.js +++ b/backend/src/restful/file.js @@ -1,6 +1,6 @@ import { deleteByName, findByName, updateByName } from '@/utils/database'; import { getFlowHeaders, normalizeFlowHeader } from '@/utils/flow'; -import { FILES_KEY } from '@/constants'; +import { FILES_KEY, ARTIFACTS_KEY } from '@/constants'; import { failed, success } from '@/restful/response'; import $ from '@/core/app'; import { @@ -245,6 +245,20 @@ function updateFile(req, res) { }; $.info(`正在更新文件:${name}...`); + if (name !== newFile.name) { + // update all artifacts referring this collection + const allArtifacts = $.read(ARTIFACTS_KEY) || []; + for (const artifact of allArtifacts) { + if ( + artifact.type === 'file' && + artifact.source === oldFile.name + ) { + artifact.source = newFile.name; + } + } + $.write(allArtifacts, ARTIFACTS_KEY); + } + updateByName(allFiles, name, newFile); $.write(allFiles, FILES_KEY); success(res, newFile); diff --git a/backend/src/restful/subscriptions.js b/backend/src/restful/subscriptions.js index 9eb733f..0e6d363 100644 --- a/backend/src/restful/subscriptions.js +++ b/backend/src/restful/subscriptions.js @@ -5,7 +5,12 @@ import { RequestInvalidError, } from './errors'; import { deleteByName, findByName, updateByName } from '@/utils/database'; -import { SUBS_KEY, COLLECTIONS_KEY, ARTIFACTS_KEY } from '@/constants'; +import { + SUBS_KEY, + COLLECTIONS_KEY, + ARTIFACTS_KEY, + FILES_KEY, +} from '@/constants'; import { getFlowHeaders, parseFlowHeaders, @@ -320,9 +325,20 @@ function updateSubscription(req, res) { artifact.source = sub.name; } } + // update all files referring this subscription + const allFiles = $.read(FILES_KEY) || []; + for (const file of allFiles) { + if ( + file.sourceType === 'subscription' && + file.sourceName == name + ) { + file.sourceName = sub.name; + } + } $.write(allCols, COLLECTIONS_KEY); $.write(allArtifacts, ARTIFACTS_KEY); + $.write(allFiles, FILES_KEY); } updateByName(allSubs, name, newSub); $.write(allSubs, SUBS_KEY);