-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
39 lines (28 loc) · 763 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import koa from 'koa';
import request from 'request';
import parse from 'co-busboy';
import Router from 'koa-router';
import Upyun from './upyun';
import uuid from 'uuid';
import path from 'path';
let app = koa();
/**
* 测试请替换
*/
let upyun = new Upyun('{user}', '{password}', '{bucket}');
let router = new Router();
router.put('/upload', function*() {
var parts = parse(this);
var part;
var files = [];
while (part = yield parts) {
let filename = `${uuid.v4()}${path.extname(part.filename)}`;
yield upyun.upload(part, filename);
files.push(`http://bangzhu.b0.upaiyun.com/${filename}`);
}
this.body = files;
});
app.use(router.routes());
app.listen(9000, ()=> {
console.log('started');
});