refactor: Migrate to API v2

- Added auto schema migration
- Refactored /api/subs, /api/collections, /api/artifacts. Now these APIs will return array instead of object. This enables sorting items in the future.
This commit is contained in:
Peng-YM
2022-07-05 10:59:40 +08:00
parent b1151859b3
commit 84b4dba425
19 changed files with 335 additions and 277 deletions

View File

@@ -1,8 +1,9 @@
import { InternalServerError, NetworkError } from './errors';
import { ProxyUtils } from '@/core/proxy-utils';
import { findByName } from '@/utils/database';
import { success, failed } from './response';
import download from '@/utils/download';
import { SUBS_KEY } from './constants';
import { SUBS_KEY } from '@/constants';
import $ from '@/core/app';
export default function register($app) {
@@ -53,12 +54,12 @@ async function compareSub(req, res) {
async function compareCollection(req, res) {
const allSubs = $.read(SUBS_KEY);
const collection = req.body;
const subnames = collection['subscriptions'];
const subnames = collection.subscriptions;
const results = {};
await Promise.all(
subnames.map(async (name) => {
const sub = allSubs[name];
const sub = findByName(allSubs, name);
try {
let raw;
if (sub.source === 'local') {