From e071a7f253ae2bcf450b905b83a6ce2b85eaa2ab Mon Sep 17 00:00:00 2001 From: xream Date: Mon, 30 Dec 2024 21:21:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=84=E5=90=88=E8=AE=A2=E9=98=85?= =?UTF-8?q?=E5=92=8C=E6=96=87=E4=BB=B6=E7=9A=84=E5=AF=BC=E5=87=BA=E5=AF=BC?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/restful/collections.js | 12 +++++++++++- backend/src/restful/file.js | 12 +++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/backend/package.json b/backend/package.json index d864c92..a812e99 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.15.11", + "version": "2.15.12", "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 e929846..f6ff1b3 100644 --- a/backend/src/restful/collections.js +++ b/backend/src/restful/collections.js @@ -50,11 +50,21 @@ function createCollection(req, res) { function getCollection(req, res) { let { name } = req.params; + let { raw } = req.query; name = decodeURIComponent(name); const allCols = $.read(COLLECTIONS_KEY); const collection = findByName(allCols, name); if (collection) { - success(res, collection); + if (raw) { + res.set('content-type', 'application/json') + .set( + 'content-disposition', + `attachment; filename="${encodeURIComponent(name)}.json"`, + ) + .send(JSON.stringify(collection)); + } else { + success(res, collection); + } } else { failed( res, diff --git a/backend/src/restful/file.js b/backend/src/restful/file.js index 87d7abc..cdac66c 100644 --- a/backend/src/restful/file.js +++ b/backend/src/restful/file.js @@ -197,11 +197,21 @@ async function getFile(req, res) { } function getWholeFile(req, res) { let { name } = req.params; + let { raw } = req.query; name = decodeURIComponent(name); const allFiles = $.read(FILES_KEY); const file = findByName(allFiles, name); if (file) { - success(res, file); + if (raw) { + res.set('content-type', 'application/json') + .set( + 'content-disposition', + `attachment; filename="${encodeURIComponent(name)}.json"`, + ) + .send(JSON.stringify(file)); + } else { + success(res, file); + } } else { failed( res,