From 048344268ceac1ae05a320b5494d3bdbe4da7bb0 Mon Sep 17 00:00:00 2001 From: xream Date: Tue, 15 Aug 2023 15:48:57 +0800 Subject: [PATCH] feat: Added replaceSubscriptions, replaceCollection API --- backend/package.json | 2 +- backend/src/restful/collections.js | 9 ++++++++- backend/src/restful/subscriptions.js | 15 ++++++++++++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/backend/package.json b/backend/package.json index 40c77cf..b625cea 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.9", + "version": "2.14.10", "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 7f3c436..ee14926 100644 --- a/backend/src/restful/collections.js +++ b/backend/src/restful/collections.js @@ -14,7 +14,8 @@ export default function register($app) { $app.route('/api/collections') .get(getAllCollections) - .post(createCollection); + .post(createCollection) + .put(replaceCollection); } // collection API @@ -111,3 +112,9 @@ function getAllCollections(req, res) { const allCols = $.read(COLLECTIONS_KEY); success(res, allCols); } + +function replaceCollection(req, res) { + const allCols = req.body; + $.write(allCols, COLLECTIONS_KEY); + success(res); +} diff --git a/backend/src/restful/subscriptions.js b/backend/src/restful/subscriptions.js index e192111..62d4f71 100644 --- a/backend/src/restful/subscriptions.js +++ b/backend/src/restful/subscriptions.js @@ -20,7 +20,10 @@ export default function register($app) { .patch(updateSubscription) .delete(deleteSubscription); - $app.route('/api/subs').get(getAllSubscriptions).post(createSubscription); + $app.route('/api/subs') + .get(getAllSubscriptions) + .post(createSubscription) + .put(replaceSubscriptions); } // subscriptions API @@ -66,10 +69,10 @@ async function getFlowInfo(req, res) { } // unit is KB - const uploadMatch = flowHeaders.match(/upload=(-?)(\d+)/) + const uploadMatch = flowHeaders.match(/upload=(-?)(\d+)/); const upload = Number(uploadMatch[1] + uploadMatch[2]); - const downloadMatch = flowHeaders.match(/download=(-?)(\d+)/) + const downloadMatch = flowHeaders.match(/download=(-?)(\d+)/); const download = Number(downloadMatch[1] + downloadMatch[2]); const total = Number(flowHeaders.match(/total=(\d+)/)[1]); @@ -202,3 +205,9 @@ function getAllSubscriptions(req, res) { const allSubs = $.read(SUBS_KEY); success(res, allSubs); } + +function replaceSubscriptions(req, res) { + const allSubs = req.body; + $.write(allSubs, SUBS_KEY); + success(res); +}