diff --git a/modules/api_v2.js b/modules/api_v2.js index a8fe357..4c74818 100644 --- a/modules/api_v2.js +++ b/modules/api_v2.js @@ -50,3 +50,12 @@ app.get('/api/v2/search/problem/:keyword*?', async (req, res) => { res.send({ success: false }); } }); + +app.get('/api/v2/hitokoto', async (req, res) => { + try { + res.send(await syzoj.utils.hitokoto()); + } catch (e) { + syzoj.log(e); + res.status(500).send({ e: e }); + } +}); diff --git a/modules/index.js b/modules/index.js index 7900e2f..f74aa76 100644 --- a/modules/index.js +++ b/modules/index.js @@ -49,11 +49,20 @@ app.get('/', async (req, res) => { let contests = await Contest.query([1, 5], null, [['start_time', 'desc']]); + let hitokoto; + try { + hitokoto = await syzoj.utils.hitokoto(); + } catch (e) { + syzoj.log(e); + hitokoto = null; + } + res.render('index', { ranklist: ranklist, notices: notices, fortune: fortune, - contests: contests + contests: contests, + hitokoto: hitokoto }); } catch (e) { syzoj.log(e); diff --git a/package.json b/package.json index 843a66e..cc165ed 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "mysql": "^2.11.1", "pygmentize-bundled-cached": "^1.1.0", "request": "^2.74.0", + "request-promise": "^4.1.1", "sequelize": "^3.24.3", "session-file-store": "^1.0.0", "sqlite3": "^3.1.4", diff --git a/utility.js b/utility.js index d9b77fd..2e47c24 100644 --- a/utility.js +++ b/utility.js @@ -195,7 +195,7 @@ module.exports = { res = res.filter(x => x); } - + res.spj = list.includes('spj.js'); return res; }, @@ -219,5 +219,15 @@ module.exports = { }, removeTitleTag(s) { return s.replace(/「[\S\s]+?」/, ''); + }, + async hitokoto() { + let request = require('request-promise'); + return await request({ + uri: 'http://api.hitokoto.us/rand', + qs: { + encode: 'json' + }, + json: true + }); } }; diff --git a/views/index.ejs b/views/index.ejs index b25e90a..358ce55 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -50,6 +50,13 @@