Skip to content

Commit

Permalink
feat: Added replaceSubscriptions, replaceCollection API
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Aug 15, 2023
1 parent c5746f6 commit 0483442
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
9 changes: 8 additions & 1 deletion backend/src/restful/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export default function register($app) {

$app.route('/api/collections')
.get(getAllCollections)
.post(createCollection);
.post(createCollection)
.put(replaceCollection);
}

// collection API
Expand Down Expand Up @@ -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);
}
15 changes: 12 additions & 3 deletions backend/src/restful/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -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);
}

0 comments on commit 0483442

Please sign in to comment.