mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-25 11:27:31 -07:00
disableLocalTimeline機能を強化
* ストリームだけではなくAPIも無効に * モデレーターは無効の場合でも見れるように * グローバルタイムラインも無効に(連合数が少ないインスタンスではグローバルタイムラインは実質的にローカルタイムラインと同一なので)
This commit is contained in:
parent
6668cfea50
commit
896b597f18
7 changed files with 38 additions and 18 deletions
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue