2016-12-29 00:49:51 +02:00
|
|
|
/**
|
|
|
|
* File Server
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as fs from 'fs';
|
2018-04-13 00:06:18 +03:00
|
|
|
import * as Koa from 'koa';
|
|
|
|
import * as cors from '@koa/cors';
|
|
|
|
import * as Router from 'koa-router';
|
|
|
|
import pour from './pour';
|
|
|
|
import sendDriveFile from './send-drive-file';
|
|
|
|
|
|
|
|
// Init app
|
|
|
|
const app = new Koa();
|
2016-12-29 00:49:51 +02:00
|
|
|
app.use(cors());
|
|
|
|
|
2018-04-13 00:06:18 +03:00
|
|
|
// Init router
|
|
|
|
const router = new Router();
|
2016-12-29 00:49:51 +02:00
|
|
|
|
2018-04-13 00:06:18 +03:00
|
|
|
router.get('/default-avatar.jpg', ctx => {
|
2017-11-10 03:54:08 +02:00
|
|
|
const file = fs.createReadStream(`${__dirname}/assets/avatar.jpg`);
|
2018-04-13 00:06:18 +03:00
|
|
|
pour(file, 'image/jpeg', ctx);
|
2016-12-29 00:49:51 +02:00
|
|
|
});
|
|
|
|
|
2018-04-13 00:06:18 +03:00
|
|
|
router.get('/app-default.jpg', ctx => {
|
2017-11-10 03:54:08 +02:00
|
|
|
const file = fs.createReadStream(`${__dirname}/assets/dummy.png`);
|
2018-04-13 00:06:18 +03:00
|
|
|
pour(file, 'image/png', ctx);
|
2016-12-29 00:49:51 +02:00
|
|
|
});
|
|
|
|
|
2018-04-13 00:06:18 +03:00
|
|
|
router.get('/:id', sendDriveFile);
|
|
|
|
router.get('/:id/:name', sendDriveFile);
|
2017-11-06 08:39:16 +02:00
|
|
|
|
2018-04-13 00:06:18 +03:00
|
|
|
// Register router
|
|
|
|
app.use(router.routes());
|
2016-12-29 00:49:51 +02:00
|
|
|
|
|
|
|
module.exports = app;
|