-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi.js
35 lines (31 loc) · 778 Bytes
/
api.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
'use strict';
const router = require('koa-router')();
const koaBody = require('koa-body');
const uploadDir = `${__dirname}/public/img`;
router.post(
'/asset',
koaBody({
multipart: true,
formLimit: '10mb',
formidable: {
uploadDir,
keepExtensions: true
}
}),
function *assetUploadEndpoint() {
const uploaded = this.request.body.files.asset;
let path = '';
if (typeof uploaded.length !== 'undefined') {
path = uploaded.map((asset) =>
(asset.path.replace(`${__dirname}/public`, '')));
} else {
path = uploaded.path.replace(`${__dirname}/public`, '');
}
const pluginId = this.request.body.fields.pluginId;
this.body = {
pluginId,
path
};
}
);
module.exports = router.routes();