Commit 4292629a authored by nano's avatar nano

fix check file

parent 6ed6079d
This diff is collapsed.
...@@ -23,6 +23,3 @@ max-download-limit=0 ...@@ -23,6 +23,3 @@ max-download-limit=0
max-overall-upload-limit=0 max-overall-upload-limit=0
#单文件速度限制 #单文件速度限制
max-upload-limit=0 max-upload-limit=0
#文件保存路径, 默认为当前启动位置
dir=/Users/vai/Downloads
...@@ -41,12 +41,11 @@ async function updatePackage(app, pack) { ...@@ -41,12 +41,11 @@ async function updatePackage(app, pack) {
const rawUrl = xml.valueWithPath('file.url'); const rawUrl = xml.valueWithPath('file.url');
const url = rawUrl.replace('https://r.my-card.in/dist/', 'https://r.my-card.in/release/dist/'); const url = rawUrl.replace('https://r.my-card.in/dist/', 'https://r.my-card.in/release/dist/');
if (app.name == 'th1') { console.log(pack._id, url);
return await axios.post(config.upload_url, { return await axios.post(config.upload_url, {
_id: pack._id, _id: pack._id,
url url
}); });
}
} }
async function createApp(app) { async function createApp(app) {
...@@ -106,9 +105,9 @@ async function main() { ...@@ -106,9 +105,9 @@ async function main() {
let {data} = await axios.get(config.old_apps_json); let {data} = await axios.get(config.old_apps_json);
try { try {
for (let app of _.sampleSize(data, 5)) { for (let app of _.sampleSize(data, 2)) {
if (!['ygopro', 'desmume', 'test'].includes(app.id)) { if (!['ygopro', 'desmume', 'test'].includes(app['id'])) {
apps[app.id] = app; apps[app['id']] = app;
await createApp(app).catch(error => { await createApp(app).catch(error => {
}); });
await updateApp(app); await updateApp(app);
......
...@@ -3,13 +3,12 @@ import * as _fs from 'fs'; ...@@ -3,13 +3,12 @@ import * as _fs from 'fs';
import * as crypto from 'crypto'; import * as crypto from 'crypto';
import * as child_process from 'child_process'; import * as child_process from 'child_process';
interface CrawOptions {
interface crawOptions {
onDir: (files: string | string[], _path: string, depth: number) => Promise<void>; onDir: (files: string | string[], _path: string, depth: number) => Promise<void>;
onFile: (file: string) => Promise<void>; onFile: (file: string) => Promise<void>;
} }
export async function crawlPath(_path, options: crawOptions, depth = 0) { export async function crawlPath(_path, options: CrawOptions, depth = 0) {
if (await isDir(_path)) { if (await isDir(_path)) {
depth += 1; depth += 1;
const files = await fs.readdirAsync(_path); const files = await fs.readdirAsync(_path);
...@@ -50,7 +49,7 @@ export function archiveSingle(archive: string, files: string[], directory: strin ...@@ -50,7 +49,7 @@ export function archiveSingle(archive: string, files: string[], directory: strin
// .pipe(dir) // .pipe(dir)
// return tar.pack(file).pipe(_fs.createWriteStream(archive)) // return tar.pack(file).pipe(_fs.createWriteStream(archive))
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
let child = child_process.spawn("tar", ["-czf", archive, '-P', '-C', directory].concat(files), {stdio: 'inherit'}); let child = child_process.spawn('tar', ['-czf', archive, '-P', '-C', directory].concat(files), {stdio: 'inherit'});
child.on('exit', (code) => { child.on('exit', (code) => {
if (code == 0) { if (code == 0) {
resolve(); resolve();
...@@ -66,7 +65,7 @@ export function archiveSingle(archive: string, files: string[], directory: strin ...@@ -66,7 +65,7 @@ export function archiveSingle(archive: string, files: string[], directory: strin
export function archive(archive: string, files: string[], directory: string): Promise<void> { export function archive(archive: string, files: string[], directory: string): Promise<void> {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
let child = child_process.spawn("tar", ["-vczf", archive, '-C', directory].concat(files), {stdio: 'inherit'}); let child = child_process.spawn('tar', ['-vczf', archive, '-C', directory].concat(files), {stdio: 'inherit'});
child.on('exit', (code) => { child.on('exit', (code) => {
if (code == 0) { if (code == 0) {
resolve(); resolve();
...@@ -82,7 +81,7 @@ export function archive(archive: string, files: string[], directory: string): Pr ...@@ -82,7 +81,7 @@ export function archive(archive: string, files: string[], directory: string): Pr
export function untar(archive: string, directory: string): Promise<void> { export function untar(archive: string, directory: string): Promise<void> {
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
let child = child_process.spawn("tar", ["-xvf", archive, '-C', directory], {stdio: 'inherit'}); let child = child_process.spawn('tar', ['-xvf', archive, '-C', directory], {stdio: 'inherit'});
child.on('exit', (code) => { child.on('exit', (code) => {
if (code == 0) { if (code == 0) {
resolve(); resolve();
...@@ -99,19 +98,19 @@ export function untar(archive: string, directory: string): Promise<void> { ...@@ -99,19 +98,19 @@ export function untar(archive: string, directory: string): Promise<void> {
export function caculateSHA256(file: string): Promise<string> { export function caculateSHA256(file: string): Promise<string> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let input = _fs.createReadStream(file); let input = _fs.createReadStream(file);
const hash = crypto.createHash("sha256"); const hash = crypto.createHash('sha256');
hash.on("error", (error: Error) => { hash.on('error', (error: Error) => {
reject(error); reject(error);
}); });
input.on("error", (error: Error) => { input.on('error', (error: Error) => {
reject(error); reject(error);
}); });
hash.on('readable', () => { hash.on('readable', () => {
let data = hash.read(); let data = hash.read();
if (data) { if (data) {
resolve((<Buffer>data).toString("hex")); resolve((<Buffer>data).toString('hex'));
} }
}); });
input.pipe(hash); input.pipe(hash);
}); });
} }
\ No newline at end of file
...@@ -7,12 +7,19 @@ import * as Client from 'aliyun-oss-upload-stream'; ...@@ -7,12 +7,19 @@ import * as Client from 'aliyun-oss-upload-stream';
import * as fs from 'fs-extra-promise'; import * as fs from 'fs-extra-promise';
import * as path from 'path'; import * as path from 'path';
import * as Aria2 from 'aria2'; import * as Aria2 from 'aria2';
import Router = require('koa-router');
import {bundle} from '../../package/main'; import {bundle} from '../../package/main';
import {mongodb} from '../models/Iridium'; import {mongodb} from '../models/Iridium';
import {toObjectID} from 'iridium'; import {toObjectID} from 'iridium';
import config from '../../config'; import config from '../../config';
import {UploadOSS} from '../utils' import {UploadOSS} from '../utils';
import Router = require('koa-router');
const checkFilePath = async (file) => {
if (['gz', 'rar', 'zip', '7z', 'x-gzip'].indexOf(mime.lookup(file.path)) === -1) {
console.log(file);
throw new Error(`Unsupported file type: ${mime.lookup(file.path)}`);
}
};
const checkPackage = async (file) => { const checkPackage = async (file) => {
if (['application/zip', 'application/gz', 'application/rar', 'application/7z', 'application/x-gzip'].indexOf(file.mime) === -1) { if (['application/zip', 'application/gz', 'application/rar', 'application/7z', 'application/x-gzip'].indexOf(file.mime) === -1) {
...@@ -100,7 +107,7 @@ export const UploadPackage = async (ctx: Context) => { ...@@ -100,7 +107,7 @@ export const UploadPackage = async (ctx: Context) => {
const bundled = await bundle(filename); const bundled = await bundle(filename);
// 打包完,上传阿里云 // 打包完,上传阿里云
await UploadOSS(bundled.distPath) await UploadOSS(bundled.distPath);
Object.assign(pack, bundled); Object.assign(pack, bundled);
pack!.status = 'uploaded'; pack!.status = 'uploaded';
...@@ -109,7 +116,7 @@ export const UploadPackage = async (ctx: Context) => { ...@@ -109,7 +116,7 @@ export const UploadPackage = async (ctx: Context) => {
await pack!.save(); await pack!.save();
// 上传完,干掉本地目录 // 上传完,干掉本地目录
await fs.removeAsync(bundled.distPath) await fs.removeAsync(bundled.distPath);
} catch (e) { } catch (e) {
...@@ -159,13 +166,13 @@ const uploadPackageUrl = async (ctx: Context) => { ...@@ -159,13 +166,13 @@ const uploadPackageUrl = async (ctx: Context) => {
const [file] = files; const [file] = files;
try { try {
await checkPackage(file);
await checkFilePath(file);
// 打包 // 打包
const bundled = await bundle(path.basename(file.path)); const bundled = await bundle(path.basename(file.path));
// 打包完, 上传阿里云 // 打包完, 上传阿里云
await UploadOSS(bundled.distPath) await UploadOSS(bundled.distPath);
Object.assign(pack, bundled); Object.assign(pack, bundled);
pack!.status = 'uploaded'; pack!.status = 'uploaded';
...@@ -174,9 +181,10 @@ const uploadPackageUrl = async (ctx: Context) => { ...@@ -174,9 +181,10 @@ const uploadPackageUrl = async (ctx: Context) => {
await pack!.save(); await pack!.save();
// 上传完,干掉本地目录 // 上传完,干掉本地目录
await fs.removeAsync(bundled.distPath) await fs.removeAsync(bundled.distPath);
} catch (e) { } catch (e) {
console.log(e);
pack!.status = 'failed'; pack!.status = 'failed';
await pack!.save(); await pack!.save();
} }
......
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