1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-11-01 23:55:58 +09:00

disableLocalTimeline機能を強化

* ストリームだけではなくAPIも無効に
* モデレーターは無効の場合でも見れるように
* グローバルタイムラインも無効に(連合数が少ないインスタンスではグローバルタイムラインは実質的にローカルタイムラインと同一なので)
This commit is contained in:
syuilo 2019-01-16 02:30:55 +09:00
parent c8e2b22942
commit c2f6b09969
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
7 changed files with 38 additions and 18 deletions

View File

@ -4,6 +4,7 @@ import Mute from '../../../../models/mute';
import { packMany } from '../../../../models/note';
import define from '../../define';
import { countIf } from '../../../../prelude/array';
import fetchMeta from '../../../../misc/fetch-meta';
export const meta = {
desc: {
@ -51,6 +52,13 @@ export const meta = {
};
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const meta = await fetchMeta();
if (meta.disableLocalTimeline) {
if (user == null || (!user.isAdmin && !user.isModerator)) {
return rej('local timeline disabled');
}
}
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) {
return rej('only one of sinceId, untilId, sinceDate, untilDate can be specified');

View File

@ -5,6 +5,7 @@ import { getFriends } from '../../common/get-friends';
import { packMany } from '../../../../models/note';
import define from '../../define';
import { countIf } from '../../../../prelude/array';
import fetchMeta from '../../../../misc/fetch-meta';
export const meta = {
desc: {
@ -91,6 +92,11 @@ export const meta = {
};
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const meta = await fetchMeta();
if (meta.disableLocalTimeline && !user.isAdmin && !user.isModerator) {
return rej('local timeline disabled');
}
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) {
return rej('only one of sinceId, untilId, sinceDate, untilDate can be specified');

View File

@ -4,6 +4,7 @@ import Mute from '../../../../models/mute';
import { packMany } from '../../../../models/note';
import define from '../../define';
import { countIf } from '../../../../prelude/array';
import fetchMeta from '../../../../misc/fetch-meta';
export const meta = {
desc: {
@ -66,6 +67,13 @@ export const meta = {
};
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const meta = await fetchMeta();
if (meta.disableLocalTimeline) {
if (user == null || (!user.isAdmin && !user.isModerator)) {
return rej('local timeline disabled');
}
}
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) {
return rej('only one of sinceId, untilId, sinceDate, untilDate can be specified');

View File

@ -3,6 +3,7 @@ import Mute from '../../../../models/mute';
import { pack } from '../../../../models/note';
import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
import Channel from '../channel';
import fetchMeta from '../../../../misc/fetch-meta';
export default class extends Channel {
public readonly chName = 'globalTimeline';
@ -13,6 +14,11 @@ export default class extends Channel {
@autobind
public async init(params: any) {
const meta = await fetchMeta();
if (meta.disableLocalTimeline) {
if (this.user == null || (!this.user.isAdmin && !this.user.isModerator)) return;
}
// Subscribe events
this.subscriber.on('globalTimeline', this.onNote);

View File

@ -3,6 +3,7 @@ import Mute from '../../../../models/mute';
import { pack } from '../../../../models/note';
import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
import Channel from '../channel';
import fetchMeta from '../../../../misc/fetch-meta';
export default class extends Channel {
public readonly chName = 'hybridTimeline';
@ -13,6 +14,9 @@ export default class extends Channel {
@autobind
public async init(params: any) {
const meta = await fetchMeta();
if (meta.disableLocalTimeline && !this.user.isAdmin && !this.user.isModerator) return;
// Subscribe events
this.subscriber.on('hybridTimeline', this.onNewNote);
this.subscriber.on(`hybridTimeline:${this.user._id}`, this.onNewNote);

View File

@ -3,6 +3,7 @@ import Mute from '../../../../models/mute';
import { pack } from '../../../../models/note';
import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
import Channel from '../channel';
import fetchMeta from '../../../../misc/fetch-meta';
export default class extends Channel {
public readonly chName = 'localTimeline';
@ -13,6 +14,11 @@ export default class extends Channel {
@autobind
public async init(params: any) {
const meta = await fetchMeta();
if (meta.disableLocalTimeline) {
if (this.user == null || (!this.user.isAdmin && !this.user.isModerator)) return;
}
// Subscribe events
this.subscriber.on('localTimeline', this.onNote);

View File

@ -1,31 +1,17 @@
import * as mongo from 'mongodb';
import redis from './db/redis';
import Xev from 'xev';
import { IMeta } from './models/meta';
import fetchMeta from './misc/fetch-meta';
type ID = string | mongo.ObjectID;
class Publisher {
private ev: Xev;
private meta: IMeta;
constructor() {
// Redisがインストールされてないときはプロセス間通信を使う
if (redis == null) {
this.ev = new Xev();
}
setInterval(async () => {
this.meta = await fetchMeta();
}, 5000);
}
public fetchMeta = async () => {
if (this.meta != null) return this.meta;
this.meta = await fetchMeta();
return this.meta;
}
private publish = (channel: string, type: string, value?: any): void => {
@ -83,14 +69,10 @@ class Publisher {
}
public publishLocalTimelineStream = async (note: any): Promise<void> => {
const meta = await this.fetchMeta();
if (meta.disableLocalTimeline) return;
this.publish('localTimeline', null, note);
}
public publishHybridTimelineStream = async (userId: ID, note: any): Promise<void> => {
const meta = await this.fetchMeta();
if (meta.disableLocalTimeline) return;
this.publish(userId ? `hybridTimeline:${userId}` : 'hybridTimeline', null, note);
}