From bb835a6e8ac36d4055b9da3b37f27e8b0d5bea37 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 29 Mar 2020 10:49:43 +0900 Subject: [PATCH] Fix bug --- src/models/repositories/notification.ts | 4 ++-- src/server/api/define.ts | 6 +++--- src/server/api/endpoints/notifications/create.ts | 2 +- src/server/api/stream/index.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/models/repositories/notification.ts b/src/models/repositories/notification.ts index a8978cc01..b484c43c5 100644 --- a/src/models/repositories/notification.ts +++ b/src/models/repositories/notification.ts @@ -46,8 +46,8 @@ export class NotificationRepository extends Repository { } : {}), ...(notification.type === 'app' ? { body: notification.customBody, - header: notification.customHeader || token!.name, - icon: notification.customIcon || token!.iconUrl, + header: notification.customHeader || token?.name, + icon: notification.customIcon || token?.iconUrl, } : {}), }); } diff --git a/src/server/api/define.ts b/src/server/api/define.ts index 2ee0ba486..1c7ee2647 100644 --- a/src/server/api/define.ts +++ b/src/server/api/define.ts @@ -15,12 +15,12 @@ type Params = { export type Response = Record | void; type executor = - (params: Params, user: T['requireCredential'] extends true ? ILocalUser : ILocalUser | null, token: AccessToken, file?: any, cleanup?: Function) => + (params: Params, user: T['requireCredential'] extends true ? ILocalUser : ILocalUser | null, token: AccessToken | null, file?: any, cleanup?: Function) => Promise>>; export default function (meta: T, cb: executor) - : (params: any, user: T['requireCredential'] extends true ? ILocalUser : ILocalUser | null, token: AccessToken, file?: any) => Promise { - return (params: any, user: T['requireCredential'] extends true ? ILocalUser : ILocalUser | null, token: AccessToken, file?: any) => { + : (params: any, user: T['requireCredential'] extends true ? ILocalUser : ILocalUser | null, token: AccessToken | null, file?: any) => Promise { + return (params: any, user: T['requireCredential'] extends true ? ILocalUser : ILocalUser | null, token: AccessToken | null, file?: any) => { function cleanup() { fs.unlink(file.path, () => {}); } diff --git a/src/server/api/endpoints/notifications/create.ts b/src/server/api/endpoints/notifications/create.ts index fed422b64..6267699e9 100644 --- a/src/server/api/endpoints/notifications/create.ts +++ b/src/server/api/endpoints/notifications/create.ts @@ -29,7 +29,7 @@ export const meta = { export default define(meta, async (ps, user, token) => { createNotification(user.id, 'app', { - appAccessTokenId: token.id, + appAccessTokenId: token ? token.id : null, customBody: ps.body, customHeader: ps.header, customIcon: ps.icon, diff --git a/src/server/api/stream/index.ts b/src/server/api/stream/index.ts index 9a6c24746..a5ff56f51 100644 --- a/src/server/api/stream/index.ts +++ b/src/server/api/stream/index.ts @@ -18,7 +18,7 @@ export default class Connection { public user?: User; public following: User['id'][] = []; public muting: User['id'][] = []; - public token: AccessToken; + public token: AccessToken | null | undefined; private wsConnection: websocket.connection; public subscriber: EventEmitter; private channels: Channel[] = [];