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
max-overall-upload-limit=0
#单文件速度限制
max-upload-limit=0
#文件保存路径, 默认为当前启动位置
dir=/Users/vai/Downloads
......@@ -41,12 +41,11 @@ async function updatePackage(app, pack) {
const rawUrl = xml.valueWithPath('file.url');
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, {
_id: pack._id,
url
});
}
}
async function createApp(app) {
......@@ -106,9 +105,9 @@ async function main() {
let {data} = await axios.get(config.old_apps_json);
try {
for (let app of _.sampleSize(data, 5)) {
if (!['ygopro', 'desmume', 'test'].includes(app.id)) {
apps[app.id] = app;
for (let app of _.sampleSize(data, 2)) {
if (!['ygopro', 'desmume', 'test'].includes(app['id'])) {
apps[app['id']] = app;
await createApp(app).catch(error => {
});
await updateApp(app);
......
......@@ -3,13 +3,12 @@ import * as _fs from 'fs';
import * as crypto from 'crypto';
import * as child_process from 'child_process';
interface crawOptions {
interface CrawOptions {
onDir: (files: string | string[], _path: string, depth: number) => 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)) {
depth += 1;
const files = await fs.readdirAsync(_path);
......@@ -50,7 +49,7 @@ export function archiveSingle(archive: string, files: string[], directory: strin
// .pipe(dir)
// return tar.pack(file).pipe(_fs.createWriteStream(archive))
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) => {
if (code == 0) {
resolve();
......@@ -66,7 +65,7 @@ export function archiveSingle(archive: string, files: string[], directory: strin
export function archive(archive: string, files: string[], directory: string): Promise<void> {
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) => {
if (code == 0) {
resolve();
......@@ -82,7 +81,7 @@ export function archive(archive: string, files: string[], directory: string): Pr
export function untar(archive: string, directory: string): Promise<void> {
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) => {
if (code == 0) {
resolve();
......@@ -99,17 +98,17 @@ export function untar(archive: string, directory: string): Promise<void> {
export function caculateSHA256(file: string): Promise<string> {
return new Promise((resolve, reject) => {
let input = _fs.createReadStream(file);
const hash = crypto.createHash("sha256");
hash.on("error", (error: Error) => {
const hash = crypto.createHash('sha256');
hash.on('error', (error: Error) => {
reject(error);
});
input.on("error", (error: Error) => {
input.on('error', (error: Error) => {
reject(error);
});
hash.on('readable', () => {
let data = hash.read();
if (data) {
resolve((<Buffer>data).toString("hex"));
resolve((<Buffer>data).toString('hex'));
}
});
input.pipe(hash);
......
......@@ -7,12 +7,19 @@ import * as Client from 'aliyun-oss-upload-stream';
import * as fs from 'fs-extra-promise';
import * as path from 'path';
import * as Aria2 from 'aria2';
import Router = require('koa-router');
import {bundle} from '../../package/main';
import {mongodb} from '../models/Iridium';
import {toObjectID} from 'iridium';
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) => {
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) => {
const bundled = await bundle(filename);
// 打包完,上传阿里云
await UploadOSS(bundled.distPath)
await UploadOSS(bundled.distPath);
Object.assign(pack, bundled);
pack!.status = 'uploaded';
......@@ -109,7 +116,7 @@ export const UploadPackage = async (ctx: Context) => {
await pack!.save();
// 上传完,干掉本地目录
await fs.removeAsync(bundled.distPath)
await fs.removeAsync(bundled.distPath);
} catch (e) {
......@@ -159,13 +166,13 @@ const uploadPackageUrl = async (ctx: Context) => {
const [file] = files;
try {
await checkPackage(file);
await checkFilePath(file);
// 打包
const bundled = await bundle(path.basename(file.path));
// 打包完, 上传阿里云
await UploadOSS(bundled.distPath)
await UploadOSS(bundled.distPath);
Object.assign(pack, bundled);
pack!.status = 'uploaded';
......@@ -174,9 +181,10 @@ const uploadPackageUrl = async (ctx: Context) => {
await pack!.save();
// 上传完,干掉本地目录
await fs.removeAsync(bundled.distPath)
await fs.removeAsync(bundled.distPath);
} catch (e) {
console.log(e);
pack!.status = 'failed';
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