From f49e5f479015b089b0e5762b86bc6f38c3286697 Mon Sep 17 00:00:00 2001 From: Menci Date: Mon, 3 Jul 2017 10:23:21 +0800 Subject: [PATCH] Request hitokoto on client side --- modules/api_v2.js | 9 --------- modules/index.js | 9 --------- utility.js | 17 ----------------- views/index.ejs | 15 +++++++++++++-- 4 files changed, 13 insertions(+), 37 deletions(-) diff --git a/modules/api_v2.js b/modules/api_v2.js index 2f54e32..8cf958a 100644 --- a/modules/api_v2.js +++ b/modules/api_v2.js @@ -69,15 +69,6 @@ app.get('/api/v2/search/tags/:keyword*?', async (req, res) => { } }); -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 }); - } -}); - app.post('/api/v2/markdown', async (req, res) => { try { let s = await syzoj.utils.markdown(req.body.s.toString(), null, req.body.noReplaceUI === 'true'); diff --git a/modules/index.js b/modules/index.js index 388aed0..4354eba 100644 --- a/modules/index.js +++ b/modules/index.js @@ -45,20 +45,11 @@ app.get('/', async (req, res) => { else where = { is_public: true }; let contests = await Contest.query([1, 5], where, [['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, - hitokoto: hitokoto, links: syzoj.config.links }); } catch (e) { diff --git a/utility.js b/utility.js index b7eb742..95752c2 100644 --- a/utility.js +++ b/utility.js @@ -325,23 +325,6 @@ module.exports = { md5.update(data); return md5.digest('hex'); }, - async hitokoto() { - try { - let request = require('request-promise'); - let res = await request({ - uri: 'https://sslapi.hitokoto.cn', - timeout: 1500, - qs: { - c: 'a' - }, - json: true - }); - if (!res.hitokoto) return null; - else return res; - } catch (e) { - return null; - } - }, isValidUsername(s) { return /^[a-zA-Z0-9\-\_]+$/.test(s); }, diff --git a/views/index.ejs b/views/index.ejs index fbcff94..b918cdf 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -79,8 +79,19 @@ <% if (hitokoto) { %>

一言(ヒトコト)

-
<%= hitokoto.hitokoto %>
- <% if (hitokoto.from) { %>
——<%= hitokoto.from %>
<% } %> +
+ + +
<% } %> <%