-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (34 loc) · 992 Bytes
/
Copy pathapp.js
File metadata and controls
43 lines (34 loc) · 992 Bytes
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
40
41
42
43
const Koa = require('koa');
const Router = require('@koa/router');
const Minio = require('minio');
const cors = require('@koa/cors');
const app = new Koa();
const router = new Router();
app.use(cors({
origin: '*'
}));
const minioClient = new Minio.Client({
endPoint: 's3.dev.osssc.ac.cn',
useSSL: true,
accessKey: '9a5MXc4aM4vtKzSLDt9v',
secretKey: '6sCZVuT4Wkg8aFJbhZ5e'
});
router.get('/presignedUrl', async (ctx) => {
const bucketName = 'risc-verse';
const objectName = `${Date.now()}-${ctx.query.filename}`;
try {
const presignedUrl = await minioClient.presignedPutObject(bucketName, objectName);
ctx.body = {
url: presignedUrl,
objectName: objectName
};
} catch (err) {
ctx.status = 500;
ctx.body = err.toString();
}
});
app.use(router.routes()).use(router.allowedMethods());
const PORT = 3009;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});