2016-12-28 15:49:51 -07:00
|
|
|
/**
|
|
|
|
* File Server
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as fs from 'fs';
|
2018-04-12 15:06:18 -06:00
|
|
|
import * as Koa from 'koa';
|
|
|
|
import * as cors from '@koa/cors';
|
|
|
|
import * as Router from 'koa-router';
|
|
|
|
import sendDriveFile from './send-drive-file';
|
|
|
|
|
|
|
|
// Init app
|
|
|
|
const app = new Koa();
|
2016-12-28 15:49:51 -07:00
|
|
|
app.use(cors());
|
|
|
|
|
2018-04-12 18:44:00 -06:00
|
|
|
app.use(async (ctx, next) => {
|
2018-04-13 10:46:03 -06:00
|
|
|
// Cache 365days
|
2018-04-12 18:44:00 -06:00
|
|
|
ctx.set('Cache-Control', 'max-age=31536000, immutable');
|
|
|
|
await next();
|
|
|
|
});
|
|
|
|
|
2018-04-12 15:06:18 -06:00
|
|
|
// Init router
|
|
|
|
const router = new Router();
|
2016-12-28 15:49:51 -07:00
|
|
|
|
2018-04-12 15:06:18 -06:00
|
|
|
router.get('/default-avatar.jpg', ctx => {
|
2017-11-09 18:54:08 -07:00
|
|
|
const file = fs.createReadStream(`${__dirname}/assets/avatar.jpg`);
|
2018-05-03 05:03:14 -06:00
|
|
|
ctx.set('Content-Type', 'image/jpeg');
|
|
|
|
ctx.body = file;
|
2016-12-28 15:49:51 -07:00
|
|
|
});
|
|
|
|
|
2018-04-12 15:06:18 -06:00
|
|
|
router.get('/app-default.jpg', ctx => {
|
2017-11-09 18:54:08 -07:00
|
|
|
const file = fs.createReadStream(`${__dirname}/assets/dummy.png`);
|
2018-05-03 05:03:14 -06:00
|
|
|
ctx.set('Content-Type', 'image/jpeg');
|
|
|
|
ctx.body = file;
|
2016-12-28 15:49:51 -07:00
|
|
|
});
|
|
|
|
|
2018-04-12 15:06:18 -06:00
|
|
|
router.get('/:id', sendDriveFile);
|
2018-04-12 18:44:00 -06:00
|
|
|
router.get('/:id/*', sendDriveFile);
|
2017-11-05 23:39:16 -07:00
|
|
|
|
2018-04-12 15:06:18 -06:00
|
|
|
// Register router
|
|
|
|
app.use(router.routes());
|
2016-12-28 15:49:51 -07:00
|
|
|
|
|
|
|
module.exports = app;
|