diff --git a/backend/package.json b/backend/package.json index a21c6e2f..66ac941d 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.21.40", + "version": "2.21.42", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/restful/sort.js b/backend/src/restful/sort.js index 03240e05..3a8a9493 100644 --- a/backend/src/restful/sort.js +++ b/backend/src/restful/sort.js @@ -3,6 +3,7 @@ import { COLLECTIONS_KEY, SUBS_KEY, FILES_KEY, + TOKENS_KEY, } from '@/constants'; import $ from '@/core/app'; import { success } from '@/restful/response'; @@ -12,6 +13,7 @@ export default function register($app) { $app.post('/api/sort/collections', sortCollections); $app.post('/api/sort/artifacts', sortArtifacts); $app.post('/api/sort/files', sortFiles); + $app.post('/api/sort/tokens', sortTokens); } function sortSubs(req, res) { @@ -47,3 +49,15 @@ function sortFiles(req, res) { $.write(allFiles, FILES_KEY); success(res, allFiles); } + +function sortTokens(req, res) { + const orders = req.body; + const allTokens = $.read(TOKENS_KEY); + allTokens.sort( + (a, b) => + orders.indexOf(`${a.type}-${a.name}-${a.token}`) - + orders.indexOf(`${b.type}-${b.name}-${b.token}`), + ); + $.write(allTokens, TOKENS_KEY); + success(res, allTokens); +} diff --git a/backend/src/restful/token.js b/backend/src/restful/token.js index 02460885..df94586c 100644 --- a/backend/src/restful/token.js +++ b/backend/src/restful/token.js @@ -1,4 +1,3 @@ -import { deleteByName } from '@/utils/database'; import { ENV } from '@/vendor/open-api'; import { TOKENS_KEY, SUBS_KEY, FILES_KEY, COLLECTIONS_KEY } from '@/constants'; import { failed, success } from '@/restful/response';