From da77aab7c4d7a9e4778f521f7333116efaaf8fc1 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 4 Jan 2017 15:26:40 +0900 Subject: Fix bug --- src/web/app/common/tags/time.tag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/web/app/common') diff --git a/src/web/app/common/tags/time.tag b/src/web/app/common/tags/time.tag index 56c3b8ecc3..52ad89a44f 100644 --- a/src/web/app/common/tags/time.tag +++ b/src/web/app/common/tags/time.tag @@ -11,7 +11,7 @@ script. @absolute = @time.get-full-year! + \年 + - @time.get-month! + \月 + + @time.get-month! + 1 + \月 + @time.get-date! + \日 + ' ' + @time.get-hours! + \時 + -- cgit v1.2.3-freya From 39eabbd2c0413f14d5b5472e651f9c34abaff2b4 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 4 Jan 2017 15:32:04 +0900 Subject: Use nyaize package for nya filter :package: --- gulpfile.ts | 1 + package.json | 1 + src/web/app/common/scripts/text-compiler.js | 6 ++---- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/web/app/common') diff --git a/gulpfile.ts b/gulpfile.ts index 1c5516801a..5ae2652c62 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -149,6 +149,7 @@ const aliasifyConfig = { 'chart.js': './node_modules/chart.js/src/chart.js', 'textarea-caret-position': './node_modules/textarea-caret/index.js', 'misskey-text': './src/common/text/index.js', + 'nyaize': './node_modules/nyaize/built/index.js', 'strength.js': './node_modules/syuilo-password-strength/strength.js', 'cropper': './node_modules/cropperjs/dist/cropper.js', 'Sortable': './node_modules/sortablejs/Sortable.js', diff --git a/package.json b/package.json index 5c75030774..360025749f 100644 --- a/package.json +++ b/package.json @@ -102,6 +102,7 @@ "ms": "0.7.2", "multer": "1.2.1", "nprogress": "0.2.0", + "nyaize": "0.0.2", "page": "1.7.1", "prominence": "0.2.0", "pug": "2.0.0-beta6", diff --git a/src/web/app/common/scripts/text-compiler.js b/src/web/app/common/scripts/text-compiler.js index f6c531c6ce..8ea2361b87 100644 --- a/src/web/app/common/scripts/text-compiler.js +++ b/src/web/app/common/scripts/text-compiler.js @@ -1,4 +1,5 @@ const riot = require('riot'); +const nyaize = require('nyaize').default; module.exports = function(tokens, shouldBreak, escape) { if (shouldBreak == null) { @@ -34,10 +35,7 @@ module.exports = function(tokens, shouldBreak, escape) { }).join(''); if (me && me.data && me.data.nya) { - text = text.replace(/な/g, 'にゃ') - .replace(/ニャ/g, 'にゃ') - .replace(/にゃでにゃで/g, 'なでなで') - .replace(/ニャデニャデ/g, 'ナデナデ'); + text = nyaize(text); } return text; -- cgit v1.2.3-freya From 1232286158629e805093cd13ad6bc12ca337f015 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 4 Jan 2017 15:46:12 +0900 Subject: Fix bug --- src/web/app/common/scripts/date-stringify.ls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/web/app/common') diff --git a/src/web/app/common/scripts/date-stringify.ls b/src/web/app/common/scripts/date-stringify.ls index 9aa8b3e6c5..7e85192ce7 100644 --- a/src/web/app/common/scripts/date-stringify.ls +++ b/src/web/app/common/scripts/date-stringify.ls @@ -3,7 +3,7 @@ module.exports = (date) -> text = date.get-full-year! + \年 + - date.get-month! + \月 + + date.get-month! + 1 + \月 + date.get-date! + \日 + ' ' + date.get-hours! + \時 + -- cgit v1.2.3-freya From 2ded8ba8580f49741e0d5e436f65561c8dd9ef18 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 6 Jan 2017 01:45:02 +0900 Subject: Fix bug, Support thirdparty streaming access --- src/api/streaming.ts | 40 +++++++++++++++++--------- src/web/app/boot.js | 2 +- src/web/app/common/scripts/messaging-stream.ls | 2 +- src/web/app/common/scripts/stream.ls | 5 ++-- 4 files changed, 31 insertions(+), 18 deletions(-) (limited to 'src/web/app/common') diff --git a/src/api/streaming.ts b/src/api/streaming.ts index 38068d1e3d..93d5f217b9 100644 --- a/src/api/streaming.ts +++ b/src/api/streaming.ts @@ -2,6 +2,7 @@ import * as http from 'http'; import * as websocket from 'websocket'; import * as redis from 'redis'; import User from './models/user'; +import Userkey from './models/userkey'; import homeStream from './stream/home'; import messagingStream from './stream/messaging'; @@ -17,7 +18,13 @@ module.exports = (server: http.Server) => { ws.on('request', async (request) => { const connection = request.accept(); - const user = await authenticate(connection); + const user = await authenticate(connection, request.resourceURL.query.i); + + if (user == null) { + connection.send('authentication-failed'); + connection.close(); + return; + } // Connect to Redis const subscriber = redis.createClient( @@ -41,29 +48,36 @@ module.exports = (server: http.Server) => { }); }; -function authenticate(connection: websocket.connection): Promise { - return new Promise((resolve, reject) => { - // Listen first message - connection.once('message', async (data) => { - const msg = JSON.parse(data.utf8Data); - +function authenticate(connection: websocket.connection, token: string): Promise { + return new Promise(async (resolve, reject) => { + if (token[0] == '!') { // Fetch user // SELECT _id const user = await User .findOne({ - token: msg.i + token: token }, { _id: true }); - if (user === null) { - connection.close(); - return; + resolve(user); + } else { + const userkey = await Userkey.findOne({ + key: token + }); + + if (userkey == null) { + return reject('invalid userkey'); } - connection.send('authenticated'); + // Fetch user + // SELECT _id + const user = await User + .findOne({ _id: userkey.user_id }, { + _id: true + }); resolve(user); - }); + } }); } diff --git a/src/web/app/boot.js b/src/web/app/boot.js index 5067600c6c..e8e504c2bb 100644 --- a/src/web/app/boot.js +++ b/src/web/app/boot.js @@ -39,7 +39,7 @@ try { checkForUpdate(); // Get token from cookie -const i = (document.cookie.match(/i=(\w+)/) || [null, null])[1]; +const i = (document.cookie.match(/i=(!\w+)/) || [null, null])[1]; // ユーザーをフェッチしてコールバックする module.exports = callback => { diff --git a/src/web/app/common/scripts/messaging-stream.ls b/src/web/app/common/scripts/messaging-stream.ls index 298285dc93..ac3e74f1f5 100644 --- a/src/web/app/common/scripts/messaging-stream.ls +++ b/src/web/app/common/scripts/messaging-stream.ls @@ -9,7 +9,7 @@ class Connection @event = riot.observable! @me = me host = CONFIG.api.url.replace \http \ws - @socket = new ReconnectingWebSocket "#{host}/messaging?otherparty=#{otherparty}" + @socket = new ReconnectingWebSocket "#{host}/messaging?i=#{me.token}&otherparty=#{otherparty}" @socket.add-event-listener \open @on-open @socket.add-event-listener \message @on-message diff --git a/src/web/app/common/scripts/stream.ls b/src/web/app/common/scripts/stream.ls index 534048248f..64ae03817a 100644 --- a/src/web/app/common/scripts/stream.ls +++ b/src/web/app/common/scripts/stream.ls @@ -9,13 +9,12 @@ module.exports = (me) ~> state-ev = riot.observable! event = riot.observable! - socket = new ReconnectingWebSocket CONFIG.api.url.replace \http \ws + host = CONFIG.api.url.replace \http \ws + socket = new ReconnectingWebSocket "#{host}?i=#{me.token}" socket.onopen = ~> state := \connected state-ev.trigger \connected - socket.send JSON.stringify do - i: me.token socket.onclose = ~> state := \reconnecting -- cgit v1.2.3-freya