Commit bb16d4cf authored by nano's avatar nano

template

parent a513cfe6
This diff is collapsed.
......@@ -19,6 +19,7 @@
"is-zip": "^1.0.0",
"koa": "^2.0.0",
"koa-bodyparser": "^3.2.0",
"koa-hbs": "next",
"koa-log4": "^2.1.0",
"koa-router": "^7.0.1",
"mime": "^1.3.4",
......
......@@ -4,6 +4,7 @@ import * as fs from 'fs-extra-promise'
import {mongodb} from '../src/models/iridium'
import {crawlPath, caculateSHA256, archive, archiveSingle, untar} from "./utils";
import {Archive, File} from "../src/models/Package";
import {file} from "tmp";
const upload_path = path.join(__dirname, '../test/upload')
const release_path = path.join(__dirname, '../test/release')
......@@ -36,6 +37,7 @@ export async function bundle(...args) {
let archives = new Map<string, Archive>();
// let files = {}
await crawlPath(package_path, {
onFile: async (file) => {
let file_hash = await caculateSHA256(file)
......@@ -50,32 +52,35 @@ export async function bundle(...args) {
await archiveSingle(sand_file, [file], package_path)
let sand_hash = await caculateSHA256(sand_file)
archives.set(sand_file, {
path: sand_file,
hash: await caculateSHA256(sand_file),
hash: sand_hash,
size: (await fs.statAsync(sand_file)).size
})
await fs.renameAsync(sand_file, path.join(path.dirname(sand_file), `${sand_hash}.tar.gz`))
},
onDir: async (files, _path, depth) => {
},
})
// TODO: 上传checksum: files
const fullFile = path.join(full_path, `${package_id}.tar.gz`)
let filePath = path.join(full_path, `${package_id}.tar.gz`)
await fs.removeAsync(fullFile)
await archive(fullFile, await fs.readdirAsync(package_path), package_path)
await fs.removeAsync(filePath)
await archive(filePath, await fs.readdirAsync(package_path), package_path)
// TODO: 上传meta
const fullHash = await caculateSHA256(fullFile)
const fullSize = (await fs.statAsync(fullFile)).size
const fullHash = await caculateSHA256(filePath)
const fullSize = (await fs.statAsync(filePath)).size
// TODO: 增量包
let fullPath = path.join(path.dirname(filePath), `${fullHash}.tar.gz`)
await fs.renameAsync(filePath, fullPath)
return {
files: Array.from(files.values()),
archives: Array.from(archives.values()),
fullFile,
fullPath,
fullSize,
fullHash
}
......
......@@ -4,6 +4,7 @@ if(process.env.NODE_ENV !== 'production') {
import * as Koa from 'koa'
import * as log4js from 'log4js'
import * as bodyParser from 'koa-bodyparser'
import * as hbs from 'koa-hbs'
import { mongodb } from './src/models/iridium'
// import index from './routes/index';
......@@ -18,6 +19,10 @@ const logger = log4js.getLogger();
const app = new Koa();
app.use(hbs.middleware({
viewPath: __dirname + '/views',
}));
app.use(async(ctx, next) => {
const start = new Date();
await next();
......
......@@ -10,12 +10,30 @@ router.get('/v2/packages', async (ctx: Context, next) => {
if (!ctx.request.query.appId) {
ctx.throw(400, "appId must be required!")
}
let packs = await mongodb.Packages.find({appId: ctx.request.query.appId, status: 'uploaded'})
let packs = await mongodb.Packages.find({appId: ctx.params.id, status: 'uploaded'})
ctx.body = {
[ctx.request.query.appId]: packs
}
})
router.get('/v2/package/:id', async(ctx: Context, next) => {
//TODO
})
router.get('/v2/package/:id/meta', async(ctx: Context, next) => {
let {fullHash, fullSize, fullPath} = await mongodb.Packages.findOne({id: ctx.params.id, status: 'uploaded'}) || {}
if(!fullHash || !fullSize || !fullPath) {
ctx.throw(400, 'pack error')
}
await ctx['render']('update', {files: {
name: fullPath,
size: fullSize,
hash: fullHash
}})
})
router.post('/v2/package/:id/update', async (ctx: Context, next) => {
const package_id = ctx.params.id
const download_path = config.download_path
......@@ -57,7 +75,7 @@ router.post('/v2/package/:id/update', async (ctx: Context, next) => {
}]
}
ctx.body = files
await ctx['render']('update', {files})
})
......
......@@ -118,6 +118,7 @@ export const UploadPackage = async (ctx: Context) => {
} catch (e) {
pack.status = 'failed'
await pack.save()
console.log(e)
}
})
......@@ -164,8 +165,11 @@ const uploadPackageUrl = async (ctx: Context) => {
const bundled = await bundle(path.basename(file.path))
// 打包完, 上传阿里云
pack.files = bundled.files
Object.assign(pack, bundled)
pack.status = 'uploaded'
await mongodb.Packages.update({id: pack.id}, {$set: { status: 'deprecated' }}, {multi: true})
await pack.save()
} catch (e) {
......@@ -178,6 +182,7 @@ const uploadPackageUrl = async (ctx: Context) => {
// console.log(await downloader.send('tellStatus', err.gid))
pack.status = 'failed'
await pack.save()
console.log(err)
}
......
<?xml version="1.0" encoding="UTF-8"?>
<metalink xmlns="urn:ietf:params:xml:ns:metalink">
{{#files}}
<file name="{{name}}">
<size>{{size}}</size>
<hash type="sha-256">{{hash}}</hash>
<url priority="1">https://thief.mycard.moe/dist/{{hash}}.tar.gz</url>
<url priority="1">https://thief.my-card.in/dist/{{hash}}.tar.gz</url>
</file>
{{/files}}
</metalink>
\ No newline at end of file
......@@ -183,6 +183,14 @@ ajv@^4.9.1:
co "^4.6.0"
json-stable-stringify "^1.0.1"
align-text@^0.1.1, align-text@^0.1.3:
version "0.1.4"
resolved "https://registry.yarnpkg.com/align-text/-/align-text-0.1.4.tgz#0cd90a561093f35d0a99256c22b7069433fad117"
dependencies:
kind-of "^3.0.2"
longest "^1.0.1"
repeat-string "^1.5.2"
aliyun-oss-upload-stream@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/aliyun-oss-upload-stream/-/aliyun-oss-upload-stream-1.3.0.tgz#38301b19f0344068438eb63977a0cd95d60470c0"
......@@ -197,6 +205,10 @@ aliyun-sdk@^1.9.22:
xml2js "0.4.4"
xmlbuilder "^2.4.5"
amdefine@>=0.0.4:
version "1.0.1"
resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"
ansi-regex@^0.2.0, ansi-regex@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-0.2.1.tgz#0d8e946967a3d8143f93e24e298525fc1b2235f9"
......@@ -303,7 +315,7 @@ async-each@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.1.tgz#19d386a1d9edc6e7c1c85d388aedbcc56d33602d"
async@1.5.2:
async@1.5.2, async@^1.4.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
......@@ -510,7 +522,7 @@ callsite@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/callsite/-/callsite-1.0.0.tgz#280398e5d664bd74038b6f0905153e6e8af1bc20"
camelcase@^1.2.1:
camelcase@^1.0.2, camelcase@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-1.2.1.tgz#9bb5304d2e0b56698b2c758b08a3eaa9daa58a39"
......@@ -526,6 +538,13 @@ caseless@~0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
center-align@^0.1.1:
version "0.1.3"
resolved "https://registry.yarnpkg.com/center-align/-/center-align-0.1.3.tgz#aa0d32629b6ee972200411cbd4461c907bc2b7ad"
dependencies:
align-text "^0.1.3"
lazy-cache "^1.0.3"
chai@^2.2.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/chai/-/chai-2.3.0.tgz#8a2f6a34748da801090fd73287b2aa739a4e909a"
......@@ -568,6 +587,14 @@ chokidar@1.6.1, chokidar@^1.4.3:
optionalDependencies:
fsevents "^1.0.0"
cliui@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-2.1.0.tgz#4b475760ff80264c762c3a1719032e91c7fea0d1"
dependencies:
center-align "^0.1.1"
right-align "^0.1.1"
wordwrap "0.0.2"
cliui@^3.0.3, cliui@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/cliui/-/cliui-3.2.0.tgz#120601537a916d29940f934da3b48d585a39213d"
......@@ -1212,6 +1239,16 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9:
version "1.0.1"
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
handlebars@^4.0.5:
version "4.0.6"
resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.6.tgz#2ce4484850537f9c97a8026d5399b935c4ed4ed7"
dependencies:
async "^1.4.0"
optimist "^0.6.1"
source-map "^0.4.4"
optionalDependencies:
uglify-js "^2.6"
har-schema@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-1.0.5.tgz#d263135f43307c02c602afc8fe95970c0151369e"
......@@ -1629,6 +1666,13 @@ koa-convert@^1.2.0:
co "^4.6.0"
koa-compose "^3.0.0"
koa-hbs@^0.9.0:
version "0.9.0"
resolved "https://registry.yarnpkg.com/koa-hbs/-/koa-hbs-0.9.0.tgz#c8a2af2933a49acaa47a197e2c279f8b2ecdb76e"
dependencies:
glob "^7.0.5"
handlebars "^4.0.5"
koa-is-json@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/koa-is-json/-/koa-is-json-1.0.0.tgz#273c07edcdcb8df6a2c1ab7d59ee76491451ec14"
......@@ -1684,6 +1728,10 @@ latest-version@^1.0.0:
dependencies:
package-json "^1.0.0"
lazy-cache@^1.0.3:
version "1.0.4"
resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e"
lcid@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/lcid/-/lcid-1.0.0.tgz#308accafa0bc483a3867b4b6f2b9506251d1b835"
......@@ -1820,6 +1868,10 @@ log4js@^0.6.35:
version "2.4.0"
resolved "https://registry.yarnpkg.com/long/-/long-2.4.0.tgz#9fa180bb1d9500cdc29c4156766a1995e1f4524f"
longest@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
lowercase-keys@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-1.0.0.tgz#4e3366b39e7f5457e35f1324bdf6f88d0bfc7306"
......@@ -2146,7 +2198,7 @@ opn@4.0.2:
object-assign "^4.0.1"
pinkie-promise "^2.0.0"
optimist@~0.6.0:
optimist@^0.6.1, optimist@~0.6.0:
version "0.6.1"
resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
dependencies:
......@@ -2552,6 +2604,12 @@ resp-modifier@6.0.2:
debug "^2.2.0"
minimatch "^3.0.2"
right-align@^0.1.1:
version "0.1.3"
resolved "https://registry.yarnpkg.com/right-align/-/right-align-0.1.3.tgz#61339b722fe6a3515689210d24e14c96148613ef"
dependencies:
align-text "^0.1.1"
rimraf@2, rimraf@~2.5.1, rimraf@~2.5.4:
version "2.5.4"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.5.4.tgz#96800093cbf1a0c86bd95b4625467535c29dfa04"
......@@ -2719,6 +2777,16 @@ socket.io@1.6.0:
socket.io-client "1.6.0"
socket.io-parser "2.3.1"
source-map@^0.4.4:
version "0.4.4"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.4.4.tgz#eba4f5da9c0dc999de68032d8b4f76173652036b"
dependencies:
amdefine ">=0.0.4"
source-map@~0.5.1:
version "0.5.6"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.6.tgz#75ce38f52bf0733c5a7f0c118d81334a2bb5f412"
spawn-command@^0.0.2-1:
version "0.0.2"
resolved "https://registry.yarnpkg.com/spawn-command/-/spawn-command-0.0.2.tgz#9544e1a43ca045f8531aac1a48cb29bdae62338e"
......@@ -2952,6 +3020,19 @@ ua-parser-js@0.7.12:
version "0.7.12"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.12.tgz#04c81a99bdd5dc52263ea29d24c6bf8d4818a4bb"
uglify-js@^2.6:
version "2.8.22"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.22.tgz#d54934778a8da14903fa29a326fb24c0ab51a1a0"
dependencies:
source-map "~0.5.1"
yargs "~3.10.0"
optionalDependencies:
uglify-to-browserify "~1.0.0"
uglify-to-browserify@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz#6e0924d6bda6b5afe349e39a6d632850a0f882b7"
uid-number@~0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81"
......@@ -3052,6 +3133,10 @@ wide-align@^1.1.0:
dependencies:
string-width "^1.0.1"
window-size@0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.0.tgz#5438cd2ea93b202efa3a19fe8887aee7c94f9c9d"
window-size@^0.1.2:
version "0.1.4"
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.4.tgz#f8e1aa1ee5a53ec5bf151ffa09742a6ad7697876"
......@@ -3060,6 +3145,10 @@ window-size@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.2.0.tgz#b4315bb4214a3d7058ebeee892e13fa24d98b075"
wordwrap@0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.2.tgz#b79669bb42ecb409f83d583cad52ca17eaa1643f"
wordwrap@~0.0.2:
version "0.0.3"
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107"
......@@ -3161,6 +3250,15 @@ yargs@6.4.0:
y18n "^3.2.1"
yargs-parser "^4.1.0"
yargs@~3.10.0:
version "3.10.0"
resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.10.0.tgz#f7ee7bd857dd7c1d2d38c0e74efbd681d1431fd1"
dependencies:
camelcase "^1.0.2"
cliui "^2.1.0"
decamelize "^1.0.0"
window-size "0.1.0"
yeast@0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419"
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