Commit 045e05c1 authored by nano's avatar nano

fix mongoldb dot question

parent 7b89fae6
This diff is collapsed.
import * as path from 'path' import * as path from 'path';
let baseUrl = 'http://127.0.01:8001'
export default { export default {
upload_path: path.join(__dirname, "./test/upload"), upload_path: path.join(__dirname, './test/upload'),
download_path: path.join(__dirname, "./test/release/downloads") download_path: path.join(__dirname, './test/release/downloads'),
} new_apps_json: `${baseUrl}/v2/apps`,
\ No newline at end of file old_apps_json: 'https://api.moecube.com/apps.json',
new_app: (appId) => `${baseUrl}/v1/app/${appId}`,
old_metalinks: (package_id) => `https://cdn01.moecube.com/release/metalinks/${package_id}.meta4llf`,
new_metalinks: (package_id) => `${baseUrl}/${package_id}/meta`,
old_checksums: (package_id) => `https://cdn01.moecube.com/release/checksums/${package_id}`,
new_checksums: (package_id) => `${baseUrl}/${package_id}/checksum`,
};
import axios from 'axios';
import config from './config';
async function createApp(app) {
return await axios.post(config.new_app(app.id), {
id: app.id,
name: app.name,
author: '1',
});
}
async function updateApp(app) {
const {id, name, description, developers, publishers, released_at, category, tags, dependencies, references, homepage, actions, version, conference, icon, cover, background, news, ...other} = app;
return await axios.patch(config.new_app(app.id), {
id,
name,
description,
developers,
publishers,
released_at,
category,
tags,
dependencies,
references,
homepage,
homepage,
actions,
version,
conference,
icon,
cover,
background,
news: {}
...other,
});
}
async function main() {
let {data} = await axios.get(config.old_apps_json);
try {
for (let app of data) {
await createApp(app).catch(error => {});
await updateApp(app);
}
} catch (e) {
console.trace(e);
}
}
main();
...@@ -10,11 +10,13 @@ ...@@ -10,11 +10,13 @@
"pretest": "tsc" "pretest": "tsc"
}, },
"dependencies": { "dependencies": {
"@types/axios": "^0.14.0",
"@types/joi": "^10.3.0", "@types/joi": "^10.3.0",
"aliyun-oss-upload-stream": "^1.3.0", "aliyun-oss-upload-stream": "^1.3.0",
"aliyun-sdk": "^1.9.22", "aliyun-sdk": "^1.9.22",
"aria2": "^3.0.0", "aria2": "^3.0.0",
"async-busboy": "^0.4.0", "async-busboy": "^0.4.0",
"axios": "^0.16.1",
"bluebird": "^3.5.0", "bluebird": "^3.5.0",
"dotenv": "^4.0.0", "dotenv": "^4.0.0",
"fs-extra-promise": "^1.0.1", "fs-extra-promise": "^1.0.1",
......
export const dot = '__<DOT>__';
...@@ -24,6 +24,8 @@ interface File { ...@@ -24,6 +24,8 @@ interface File {
} }
export interface App { export interface App {
id: string; id: string;
status: string; status: string;
...@@ -41,7 +43,7 @@ export interface App { ...@@ -41,7 +43,7 @@ export interface App {
homepage?: string; homepage?: string;
locales?: string[]; locales?: string[];
actions?: Platform<{ [key: string]: { execuate: string, args: string[], env: { [key: string]: string } } }>; actions?: Platform<{ [key: string]: { execuate: string, args: string[], env: { [key: string]: string } } }>;
files?: { [key: string]: { sync: boolean } }; files?: { [key: string]: { sync: boolean, ignore: boolean } };
version?: Platform<string>; version?: Platform<string>;
news?: I18n<{ title: string, url: string, image: string }[]>; news?: I18n<{ title: string, url: string, image: string }[]>;
conference?: string; conference?: string;
...@@ -49,7 +51,6 @@ export interface App { ...@@ -49,7 +51,6 @@ export interface App {
icon?: string; icon?: string;
cover?: string; cover?: string;
background?: string; background?: string;
// packages?: Package[];
created_at?: Date; created_at?: Date;
} }
...@@ -89,7 +90,7 @@ export class AppSchema extends Instance<App, AppSchema> implements App { ...@@ -89,7 +90,7 @@ export class AppSchema extends Instance<App, AppSchema> implements App {
@Property(Object, false) @Property(Object, false)
actions?: Platform<{ [key: string]: { execuate: string, args: string[], env: { [key: string]: string } } }>; actions?: Platform<{ [key: string]: { execuate: string, args: string[], env: { [key: string]: string } } }>;
@Property(Object, false) @Property(Object, false)
files?: { [key: string]: { sync: boolean } }; files?: { [key: string]: { sync: boolean, ignore: boolean} };
@Property(Object, false) @Property(Object, false)
version?: Platform<string>; version?: Platform<string>;
@Property(Object, false) @Property(Object, false)
......
...@@ -4,8 +4,11 @@ import {App} from '../models/App'; ...@@ -4,8 +4,11 @@ import {App} from '../models/App';
import {Context} from 'koa'; import {Context} from 'koa';
import * as joi from 'joi'; import * as joi from 'joi';
import {promisify as py} from 'bluebird'; import {promisify as py} from 'bluebird';
import {dot} from '../utils';
const router = new Router(); const router = new Router();
const isTest = process.env['ENV'] !== 'production';
let validate: any = py(joi.validate); let validate: any = py(joi.validate);
router.get('/v2/apps', async (ctx: Context, next) => { router.get('/v2/apps', async (ctx: Context, next) => {
...@@ -19,10 +22,20 @@ router.get('/v1/apps', async (ctx: Context, next) => { ...@@ -19,10 +22,20 @@ router.get('/v1/apps', async (ctx: Context, next) => {
} }
let apps = {}; let apps = {};
if (payload.admin == 'true') { if (isTest || payload.admin == 'true') {
apps = await mongodb.Apps.find({}).toArray(); apps = await mongodb.Apps.find({}).map(app => {
if (app.files) {
app.files = Object.assign({}, ...Object.keys(app.files).map(key => ({[key.replace(new RegExp(dot, 'g'), '.')]: app.files![key]})));
}
return app;
});
} else { } else {
apps = await mongodb.Apps.find({author: payload.author}).toArray(); apps = await mongodb.Apps.find({author: payload.author}).map(app => {
if (app.files) {
app.files = Object.assign({}, ...Object.keys(app.files).map(key => ({[key.replace(new RegExp(dot, 'g'), '.')]: app.files![key]})));
}
return app;
});
} }
ctx.body = apps; ctx.body = apps;
}); });
...@@ -71,6 +84,9 @@ router.patch('/v1/app/:id', async (ctx: Context, next) => { ...@@ -71,6 +84,9 @@ router.patch('/v1/app/:id', async (ctx: Context, next) => {
return ctx.throw(e); return ctx.throw(e);
} }
} }
if (_app.files && Object.keys(_app.files).length > 0) {
_app.files = Object.assign({}, ...Object.keys(_app.files).map(key => ({[key.replace(new RegExp('\\.', 'g'), dot)]: _app.files[key]})));
}
app.handleUpdate(_app); app.handleUpdate(_app);
......
...@@ -18,6 +18,7 @@ router.get('/v2/packages', async (ctx: Context, next) => { ...@@ -18,6 +18,7 @@ router.get('/v2/packages', async (ctx: Context, next) => {
ctx.body = packs ctx.body = packs
}); });
router.get('/v2/package/:id/checksum', async (ctx: Context, next) => { router.get('/v2/package/:id/checksum', async (ctx: Context, next) => {
let pack = await mongodb.Packages.findOne({id: ctx.params.id, status: 'uploaded'}); let pack = await mongodb.Packages.findOne({id: ctx.params.id, status: 'uploaded'});
if (!pack) { if (!pack) {
......
import {URL} from 'url'; import {URL} from 'url';
import * as child_process from 'child_process'; import * as child_process from 'child_process';
export const dot = '__<DOT>__';
export const handleImg = (img) => { export const handleImg = (img) => {
if (img) { if (img) {
let url: URL; let url: URL;
......
...@@ -4,25 +4,17 @@ ...@@ -4,25 +4,17 @@
import * as fetch from 'isomorphic-fetch'; import * as fetch from 'isomorphic-fetch';
import * as _ from 'lodash'; import * as _ from 'lodash';
import {XmlDocument} from 'xmldoc'; import {XmlDocument} from 'xmldoc';
import config from './config';
// 配置
const old_apps_json = 'https://api.moecube.com/apps.json';
const new_apps_json = 'http://127.0.01:8001/v2/apps';
const old_metalinks = (package_id) => `https://cdn01.moecube.com/release/metalinks/${package_id}.meta4`;
const new_metalinks = (package_id) => `http://127.0.0.1:8001/v2/package/${package_id}/meta`; // 修改
const old_checksums = (package_id) => `https://cdn01.moecube.com/release/checksums/${package_id}`;
const new_checksums = (package_id) => `http://127.0.0.1:8001/v2/package/${package_id}/checksum`; // 修改
async function test_checksums() { async function test_checksums() {
const apps: any[] = (await (await fetch(new_apps_json)).json()) const apps: any[] = (await (await fetch(config.new_apps_json)).json())
.filter(i => !['ygopro', 'desmume'].includes(i.id)); // 排除 ygopro 和 desmume .filter(i => !['ygopro', 'desmume'].includes(i.id)); // 排除 ygopro 和 desmume
for (let app of _.sampleSize(apps, 5)) { for (let app of _.sampleSize(apps, 5)) {
console.log(`正在测试 ${app.id} 的 checksum`); console.log(`正在测试 ${app.id} 的 checksum`);
const old_checksum = await (await fetch(old_checksums(app.id))).text(); const old_checksum = await (await fetch(config.old_checksums(app.id))).text();
const new_checksum = await (await fetch(new_checksums(app.id))).text(); const new_checksum = await (await fetch(config.new_checksums(app.id))).text();
if (old_checksum !== new_checksum) { if (old_checksum !== new_checksum) {
console.log('', old_checksum); console.log('', old_checksum);
console.log('', new_checksum); console.log('', new_checksum);
...@@ -31,12 +23,12 @@ async function test_checksums() { ...@@ -31,12 +23,12 @@ async function test_checksums() {
} }
} }
async function test_download() { async function test_download() {
const apps: any[] = (await (await fetch(new_apps_json)).json()) const apps: any[] = (await (await fetch(config.new_apps_json)).json())
.filter(i => !['ygopro', 'desmume'].includes(i.id)); // 排除 ygopro 和 desmume .filter(i => !['ygopro', 'desmume'].includes(i.id)); // 排除 ygopro 和 desmume
const app: any = _.sample(apps); const app: any = _.sample(apps);
console.log(`正在测试 ${app.id} 的 下载`); console.log(`正在测试 ${app.id} 的 下载`);
const metalink = await (await fetch(new_metalinks(app.id))).text(); const metalink = await (await fetch(config.new_metalinks(app.id))).text();
const xml = new XmlDocument(metalink); const xml = new XmlDocument(metalink);
const url = xml.valueWithPath('file.url'); const url = xml.valueWithPath('file.url');
const response = await fetch(url, {method: 'HEAD'}); const response = await fetch(url, {method: 'HEAD'});
...@@ -49,13 +41,14 @@ async function test_update() { ...@@ -49,13 +41,14 @@ async function test_update() {
} }
async function test_apps_json() { async function test_apps_json() {
const old_apps = await (await fetch(old_apps_json)).json(); const old_apps = await (await fetch(config.old_apps_json)).json();
const new_apps = await (await fetch(new_apps_json)).json(); const new_apps = await (await fetch(config.new_apps_json)).json();
for (let new_app of new_apps) { for (let new_app of new_apps) {
let old_app = old_apps.find(i => i.id == new_app.id); let old_app = old_apps.find(i => i.id == new_app.id);
delete old_app.network;
delete old_app.author; delete old_app.author;
delete new_app.author; delete new_app.author;
delete old_app.news;
delete new_app.news;
if (!old_app) { if (!old_app) {
throw `应用 ${new_app.id} 在旧的列表不存在`; throw `应用 ${new_app.id} 在旧的列表不存在`;
} }
......
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
version "1.3.2" version "1.3.2"
resolved "https://registry.yarnpkg.com/@types/accepts/-/accepts-1.3.2.tgz#52897ad5a51f05ea2f57f8e8136085c7d1c385a5" resolved "https://registry.yarnpkg.com/@types/accepts/-/accepts-1.3.2.tgz#52897ad5a51f05ea2f57f8e8136085c7d1c385a5"
"@types/axios@^0.14.0":
version "0.14.0"
resolved "https://registry.yarnpkg.com/@types/axios/-/axios-0.14.0.tgz#ec2300fbe7d7dddd7eb9d3abf87999964cafce46"
dependencies:
axios "*"
"@types/bluebird@*", "@types/bluebird@^3.5.0", "@types/bluebird@^3.5.2": "@types/bluebird@*", "@types/bluebird@^3.5.0", "@types/bluebird@^3.5.2":
version "3.5.2" version "3.5.2"
resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.2.tgz#ecf1104217495e50fe0b588d538146cd6f733b89" resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.2.tgz#ecf1104217495e50fe0b588d538146cd6f733b89"
...@@ -303,6 +309,12 @@ aws4@^1.2.1: ...@@ -303,6 +309,12 @@ aws4@^1.2.1:
version "1.6.0" version "1.6.0"
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e" resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e"
axios@*, axios@^0.16.1:
version "0.16.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.16.1.tgz#c0b6d26600842384b8f509e57111f0d2df8223ca"
dependencies:
follow-redirects "^1.2.3"
babel-code-frame@^6.22.0: babel-code-frame@^6.22.0:
version "6.22.0" version "6.22.0"
resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4"
...@@ -546,7 +558,7 @@ dashdash@^1.12.0: ...@@ -546,7 +558,7 @@ dashdash@^1.12.0:
dependencies: dependencies:
assert-plus "^1.0.0" assert-plus "^1.0.0"
debug@*, debug@^2.1.0, debug@^2.2.0: debug@*, debug@^2.1.0, debug@^2.2.0, debug@^2.4.5:
version "2.6.4" version "2.6.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.4.tgz#7586a9b3c39741c0282ae33445c4e8ac74734fe0" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.4.tgz#7586a9b3c39741c0282ae33445c4e8ac74734fe0"
dependencies: dependencies:
...@@ -718,6 +730,12 @@ findup-sync@~0.3.0: ...@@ -718,6 +730,12 @@ findup-sync@~0.3.0:
dependencies: dependencies:
glob "~5.0.0" glob "~5.0.0"
follow-redirects@^1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.2.3.tgz#01abaeca85e3609837d9fcda3167a7e42fdaca21"
dependencies:
debug "^2.4.5"
for-in@^1.0.1: for-in@^1.0.1:
version "1.0.2" version "1.0.2"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment