From 6012e98ae6232146b91d8dc2f140282f660e66f0 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 11 Nov 2018 02:22:34 +0900 Subject: [PATCH] Improve streaming API --- src/server/api/stream/channel.ts | 1 + src/server/api/stream/channels/ap-log.ts | 1 + src/server/api/stream/channels/drive.ts | 1 + src/server/api/stream/channels/games/reversi-game.ts | 1 + src/server/api/stream/channels/games/reversi.ts | 1 + src/server/api/stream/channels/global-timeline.ts | 1 + src/server/api/stream/channels/hashtag.ts | 1 + src/server/api/stream/channels/home-timeline.ts | 1 + src/server/api/stream/channels/hybrid-timeline.ts | 1 + src/server/api/stream/channels/local-timeline.ts | 1 + src/server/api/stream/channels/main.ts | 1 + src/server/api/stream/channels/messaging-index.ts | 1 + src/server/api/stream/channels/messaging.ts | 1 + src/server/api/stream/channels/notes-stats.ts | 1 + src/server/api/stream/channels/server-stats.ts | 1 + src/server/api/stream/channels/user-list.ts | 1 + src/server/api/stream/index.ts | 4 ++++ 17 files changed, 20 insertions(+) diff --git a/src/server/api/stream/channel.ts b/src/server/api/stream/channel.ts index 75914964cb..bdbe4605cf 100644 --- a/src/server/api/stream/channel.ts +++ b/src/server/api/stream/channel.ts @@ -9,6 +9,7 @@ export default abstract class Channel { public id: string; public abstract readonly chName: string; public static readonly shouldShare: boolean; + public static readonly requireCredential: boolean; protected get user() { return this.connection.user; diff --git a/src/server/api/stream/channels/ap-log.ts b/src/server/api/stream/channels/ap-log.ts index dfa1cc702d..867fd3670b 100644 --- a/src/server/api/stream/channels/ap-log.ts +++ b/src/server/api/stream/channels/ap-log.ts @@ -4,6 +4,7 @@ import Channel from '../channel'; export default class extends Channel { public readonly chName = 'apLog'; public static shouldShare = true; + public static requireCredential = false; @autobind public async init(params: any) { diff --git a/src/server/api/stream/channels/drive.ts b/src/server/api/stream/channels/drive.ts index 7425a620ff..391c4b5c32 100644 --- a/src/server/api/stream/channels/drive.ts +++ b/src/server/api/stream/channels/drive.ts @@ -4,6 +4,7 @@ import Channel from '../channel'; export default class extends Channel { public readonly chName = 'drive'; public static shouldShare = true; + public static requireCredential = true; @autobind public async init(params: any) { diff --git a/src/server/api/stream/channels/games/reversi-game.ts b/src/server/api/stream/channels/games/reversi-game.ts index 5dc9ca0608..f287ad0107 100644 --- a/src/server/api/stream/channels/games/reversi-game.ts +++ b/src/server/api/stream/channels/games/reversi-game.ts @@ -10,6 +10,7 @@ import Channel from '../../channel'; export default class extends Channel { public readonly chName = 'gamesReversiGame'; public static shouldShare = false; + public static requireCredential = false; private gameId: mongo.ObjectID; diff --git a/src/server/api/stream/channels/games/reversi.ts b/src/server/api/stream/channels/games/reversi.ts index 51cb264d98..b40709617b 100644 --- a/src/server/api/stream/channels/games/reversi.ts +++ b/src/server/api/stream/channels/games/reversi.ts @@ -7,6 +7,7 @@ import Channel from '../../channel'; export default class extends Channel { public readonly chName = 'gamesReversi'; public static shouldShare = true; + public static requireCredential = true; @autobind public async init(params: any) { diff --git a/src/server/api/stream/channels/global-timeline.ts b/src/server/api/stream/channels/global-timeline.ts index e39ea269a6..c5499801ed 100644 --- a/src/server/api/stream/channels/global-timeline.ts +++ b/src/server/api/stream/channels/global-timeline.ts @@ -7,6 +7,7 @@ import Channel from '../channel'; export default class extends Channel { public readonly chName = 'globalTimeline'; public static shouldShare = true; + public static requireCredential = false; private mutedUserIds: string[] = []; diff --git a/src/server/api/stream/channels/hashtag.ts b/src/server/api/stream/channels/hashtag.ts index 1f99aa3539..052240c18c 100644 --- a/src/server/api/stream/channels/hashtag.ts +++ b/src/server/api/stream/channels/hashtag.ts @@ -7,6 +7,7 @@ import Channel from '../channel'; export default class extends Channel { public readonly chName = 'hashtag'; public static shouldShare = false; + public static requireCredential = false; @autobind public async init(params: any) { diff --git a/src/server/api/stream/channels/home-timeline.ts b/src/server/api/stream/channels/home-timeline.ts index 3fa887f1e5..d3477d846a 100644 --- a/src/server/api/stream/channels/home-timeline.ts +++ b/src/server/api/stream/channels/home-timeline.ts @@ -7,6 +7,7 @@ import Channel from '../channel'; export default class extends Channel { public readonly chName = 'homeTimeline'; public static shouldShare = true; + public static requireCredential = true; private mutedUserIds: string[] = []; diff --git a/src/server/api/stream/channels/hybrid-timeline.ts b/src/server/api/stream/channels/hybrid-timeline.ts index d72545e4c8..15a516b0c0 100644 --- a/src/server/api/stream/channels/hybrid-timeline.ts +++ b/src/server/api/stream/channels/hybrid-timeline.ts @@ -7,6 +7,7 @@ import Channel from '../channel'; export default class extends Channel { public readonly chName = 'hybridTimeline'; public static shouldShare = true; + public static requireCredential = true; private mutedUserIds: string[] = []; diff --git a/src/server/api/stream/channels/local-timeline.ts b/src/server/api/stream/channels/local-timeline.ts index 0ba0b1b195..a26f71af8e 100644 --- a/src/server/api/stream/channels/local-timeline.ts +++ b/src/server/api/stream/channels/local-timeline.ts @@ -7,6 +7,7 @@ import Channel from '../channel'; export default class extends Channel { public readonly chName = 'localTimeline'; public static shouldShare = true; + public static requireCredential = false; private mutedUserIds: string[] = []; diff --git a/src/server/api/stream/channels/main.ts b/src/server/api/stream/channels/main.ts index 7d5462c092..5b0705f1d3 100644 --- a/src/server/api/stream/channels/main.ts +++ b/src/server/api/stream/channels/main.ts @@ -5,6 +5,7 @@ import Channel from '../channel'; export default class extends Channel { public readonly chName = 'main'; public static shouldShare = true; + public static requireCredential = true; @autobind public async init(params: any) { diff --git a/src/server/api/stream/channels/messaging-index.ts b/src/server/api/stream/channels/messaging-index.ts index 0211d702cf..148ff7f935 100644 --- a/src/server/api/stream/channels/messaging-index.ts +++ b/src/server/api/stream/channels/messaging-index.ts @@ -4,6 +4,7 @@ import Channel from '../channel'; export default class extends Channel { public readonly chName = 'messagingIndex'; public static shouldShare = true; + public static requireCredential = true; @autobind public async init(params: any) { diff --git a/src/server/api/stream/channels/messaging.ts b/src/server/api/stream/channels/messaging.ts index ab04a332cf..0d81b4e45c 100644 --- a/src/server/api/stream/channels/messaging.ts +++ b/src/server/api/stream/channels/messaging.ts @@ -5,6 +5,7 @@ import Channel from '../channel'; export default class extends Channel { public readonly chName = 'messaging'; public static shouldShare = false; + public static requireCredential = true; private otherpartyId: string; diff --git a/src/server/api/stream/channels/notes-stats.ts b/src/server/api/stream/channels/notes-stats.ts index 2282f8bc70..0c6b84d6cf 100644 --- a/src/server/api/stream/channels/notes-stats.ts +++ b/src/server/api/stream/channels/notes-stats.ts @@ -7,6 +7,7 @@ const ev = new Xev(); export default class extends Channel { public readonly chName = 'notesStats'; public static shouldShare = true; + public static requireCredential = false; @autobind public async init(params: any) { diff --git a/src/server/api/stream/channels/server-stats.ts b/src/server/api/stream/channels/server-stats.ts index 912dcf5305..d245a7f70c 100644 --- a/src/server/api/stream/channels/server-stats.ts +++ b/src/server/api/stream/channels/server-stats.ts @@ -7,6 +7,7 @@ const ev = new Xev(); export default class extends Channel { public readonly chName = 'serverStats'; public static shouldShare = true; + public static requireCredential = false; @autobind public async init(params: any) { diff --git a/src/server/api/stream/channels/user-list.ts b/src/server/api/stream/channels/user-list.ts index b526a5f986..dbdd8afb0a 100644 --- a/src/server/api/stream/channels/user-list.ts +++ b/src/server/api/stream/channels/user-list.ts @@ -4,6 +4,7 @@ import Channel from '../channel'; export default class extends Channel { public readonly chName = 'userList'; public static shouldShare = false; + public static requireCredential = false; @autobind public async init(params: any) { diff --git a/src/server/api/stream/index.ts b/src/server/api/stream/index.ts index 96a4c7add6..58dbacd688 100644 --- a/src/server/api/stream/index.ts +++ b/src/server/api/stream/index.ts @@ -173,6 +173,10 @@ export default class Connection { */ @autobind public connectChannel(id: string, params: any, channel: string, pong = false) { + if ((channels as any)[channel].requireCredential && this.user == null) { + return; + } + // 共有可能チャンネルに接続しようとしていて、かつそのチャンネルに既に接続していたら無意味なので無視 if ((channels as any)[channel].shouldShare && this.channels.some(c => c.chName === channel)) { return;