|
| 1 | +import _ from 'lodash'; |
1 | 2 | import express from '@/vendor/express'; |
2 | 3 | import $ from '@/core/app'; |
3 | 4 | import migrate from '@/utils/migration'; |
@@ -304,6 +305,7 @@ export default function serve() { |
304 | 305 | const path = eval(`require("path")`); |
305 | 306 | const fs = eval(`require("fs")`); |
306 | 307 | const data_url = eval('process.env.SUB_STORE_DATA_URL'); |
| 308 | + const data_url_post = eval('process.env.SUB_STORE_DATA_URL_POST'); |
307 | 309 | const fe_be_path = eval('process.env.SUB_STORE_FRONTEND_BACKEND_PATH'); |
308 | 310 | const fe_port = eval('process.env.SUB_STORE_FRONTEND_PORT') || 3001; |
309 | 311 | const fe_host = |
@@ -424,10 +426,30 @@ export default function serve() { |
424 | 426 | if (data_url) { |
425 | 427 | $.info(`[BACKEND] downloading data from ${data_url}`); |
426 | 428 | download(data_url) |
427 | | - .then((content) => { |
428 | | - $.write(content, '#sub-store'); |
| 429 | + .then(async (content) => { |
| 430 | + try { |
| 431 | + content = JSON.parse(content); |
| 432 | + if (Object.keys(content.settings).length === 0) { |
| 433 | + throw new Error( |
| 434 | + '备份文件应该至少包含 settings 字段', |
| 435 | + ); |
| 436 | + } |
| 437 | + } catch (err) { |
| 438 | + $.error( |
| 439 | + `Gist 备份文件校验失败, 无法还原\nReason: ${ |
| 440 | + err.message ?? err |
| 441 | + }`, |
| 442 | + ); |
| 443 | + throw new Error('Gist 备份文件校验失败, 无法还原'); |
| 444 | + } |
| 445 | + if (data_url_post) { |
| 446 | + $.info('[BACKEND] executing post-processing script'); |
| 447 | + eval(data_url_post); |
| 448 | + } |
| 449 | + |
| 450 | + $.write(JSON.stringify(content, null, ` `), '#sub-store'); |
429 | 451 |
|
430 | | - $.cache = JSON.parse(content); |
| 452 | + $.cache = content; |
431 | 453 | $.persistCache(); |
432 | 454 |
|
433 | 455 | migrate(); |
|
0 commit comments