Streaming経由でのAPIリクエストを削除
This commit is contained in:
parent
ddd655c0c1
commit
3770bb6576
@ -1,20 +1,18 @@
|
|||||||
import * as websocket from 'websocket';
|
|
||||||
import { readNotification } from '../common/read-notification.js';
|
|
||||||
import call from '../call.js';
|
|
||||||
import readNote from '@/services/note/read.js';
|
|
||||||
import Channel from './channel.js';
|
|
||||||
import channels from './channels/index.js';
|
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
|
import * as websocket from 'websocket';
|
||||||
|
import readNote from '@/services/note/read.js';
|
||||||
import { User } from '@/models/entities/user.js';
|
import { User } from '@/models/entities/user.js';
|
||||||
import { Channel as ChannelModel } from '@/models/entities/channel.js';
|
import { Channel as ChannelModel } from '@/models/entities/channel.js';
|
||||||
import { Users, Followings, Mutings, UserProfiles, ChannelFollowings, Blockings } from '@/models/index.js';
|
import { Users, Followings, Mutings, UserProfiles, ChannelFollowings, Blockings } from '@/models/index.js';
|
||||||
import { ApiError } from '../error.js';
|
|
||||||
import { AccessToken } from '@/models/entities/access-token.js';
|
import { AccessToken } from '@/models/entities/access-token.js';
|
||||||
import { UserProfile } from '@/models/entities/user-profile.js';
|
import { UserProfile } from '@/models/entities/user-profile.js';
|
||||||
import { publishChannelStream, publishGroupMessagingStream, publishMessagingStream } from '@/services/stream.js';
|
import { publishChannelStream, publishGroupMessagingStream, publishMessagingStream } from '@/services/stream.js';
|
||||||
import { UserGroup } from '@/models/entities/user-group.js';
|
import { UserGroup } from '@/models/entities/user-group.js';
|
||||||
import { StreamEventEmitter, StreamMessages } from './types.js';
|
|
||||||
import { Packed } from '@/misc/schema.js';
|
import { Packed } from '@/misc/schema.js';
|
||||||
|
import { readNotification } from '../common/read-notification.js';
|
||||||
|
import channels from './channels/index.js';
|
||||||
|
import Channel from './channel.js';
|
||||||
|
import { StreamEventEmitter, StreamMessages } from './types.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main stream connection
|
* Main stream connection
|
||||||
@ -126,7 +124,6 @@ export default class Connection {
|
|||||||
const { type, body } = obj;
|
const { type, body } = obj;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'api': this.onApiRequest(body); break;
|
|
||||||
case 'readNotification': this.onReadNotification(body); break;
|
case 'readNotification': this.onReadNotification(body); break;
|
||||||
case 'subNote': this.onSubscribeNote(body); break;
|
case 'subNote': this.onSubscribeNote(body); break;
|
||||||
case 's': this.onSubscribeNote(body); break; // alias
|
case 's': this.onSubscribeNote(body); break; // alias
|
||||||
@ -183,31 +180,6 @@ export default class Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* APIリクエスト要求時
|
|
||||||
*/
|
|
||||||
private async onApiRequest(payload: any) {
|
|
||||||
// 新鮮なデータを利用するためにユーザーをフェッチ
|
|
||||||
const user = this.user ? await Users.findOneBy({ id: this.user.id }) : null;
|
|
||||||
|
|
||||||
const endpoint = payload.endpoint || payload.ep; // alias
|
|
||||||
|
|
||||||
// 呼び出し
|
|
||||||
call(endpoint, user, this.token, payload.data).then(res => {
|
|
||||||
this.sendMessageToWs(`api:${payload.id}`, { res });
|
|
||||||
}).catch((e: ApiError) => {
|
|
||||||
this.sendMessageToWs(`api:${payload.id}`, {
|
|
||||||
error: {
|
|
||||||
message: e.message,
|
|
||||||
code: e.code,
|
|
||||||
id: e.id,
|
|
||||||
kind: e.kind,
|
|
||||||
...(e.info ? { info: e.info } : {}),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private onReadNotification(payload: any) {
|
private onReadNotification(payload: any) {
|
||||||
if (!payload.id) return;
|
if (!payload.id) return;
|
||||||
readNotification(this.user!.id, [payload.id]);
|
readNotification(this.user!.id, [payload.id]);
|
||||||
|
Loading…
Reference in New Issue
Block a user