feat: Added replaceSubscriptions, replaceCollection API

This commit is contained in:
xream 2023-08-15 15:48:57 +08:00
parent c5746f6a6b
commit 048344268c
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
3 changed files with 21 additions and 5 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "sub-store", "name": "sub-store",
"version": "2.14.9", "version": "2.14.10",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js", "main": "src/main.js",
"scripts": { "scripts": {

View File

@ -14,7 +14,8 @@ export default function register($app) {
$app.route('/api/collections') $app.route('/api/collections')
.get(getAllCollections) .get(getAllCollections)
.post(createCollection); .post(createCollection)
.put(replaceCollection);
} }
// collection API // collection API
@ -111,3 +112,9 @@ function getAllCollections(req, res) {
const allCols = $.read(COLLECTIONS_KEY); const allCols = $.read(COLLECTIONS_KEY);
success(res, allCols); success(res, allCols);
} }
function replaceCollection(req, res) {
const allCols = req.body;
$.write(allCols, COLLECTIONS_KEY);
success(res);
}

View File

@ -20,7 +20,10 @@ export default function register($app) {
.patch(updateSubscription) .patch(updateSubscription)
.delete(deleteSubscription); .delete(deleteSubscription);
$app.route('/api/subs').get(getAllSubscriptions).post(createSubscription); $app.route('/api/subs')
.get(getAllSubscriptions)
.post(createSubscription)
.put(replaceSubscriptions);
} }
// subscriptions API // subscriptions API
@ -66,10 +69,10 @@ async function getFlowInfo(req, res) {
} }
// unit is KB // unit is KB
const uploadMatch = flowHeaders.match(/upload=(-?)(\d+)/) const uploadMatch = flowHeaders.match(/upload=(-?)(\d+)/);
const upload = Number(uploadMatch[1] + uploadMatch[2]); 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 download = Number(downloadMatch[1] + downloadMatch[2]);
const total = Number(flowHeaders.match(/total=(\d+)/)[1]); const total = Number(flowHeaders.match(/total=(\d+)/)[1]);
@ -202,3 +205,9 @@ function getAllSubscriptions(req, res) {
const allSubs = $.read(SUBS_KEY); const allSubs = $.read(SUBS_KEY);
success(res, allSubs); success(res, allSubs);
} }
function replaceSubscriptions(req, res) {
const allSubs = req.body;
$.write(allSubs, SUBS_KEY);
success(res);
}