From aadd5b95b811dbd9d0fce9e622613a148e4ad7da Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 3 Nov 2018 11:38:00 +0900 Subject: [PATCH] Improve admin dashboard --- locales/ja-JP.yml | 2 + src/client/app/admin/views/ap-log.vue | 113 ++++++++++++++++++ src/client/app/admin/views/dashboard.vue | 23 ++-- src/client/app/common/views/filters/bytes.ts | 1 + src/client/app/common/views/filters/number.ts | 1 + src/queue/processors/http/process-inbox.ts | 10 ++ src/remote/activitypub/request.ts | 10 ++ src/server/api/stream/channels/ap-log.ts | 24 ++++ src/server/api/stream/channels/index.ts | 2 + src/stream.ts | 5 + 10 files changed, 183 insertions(+), 8 deletions(-) create mode 100644 src/client/app/admin/views/ap-log.vue create mode 100644 src/server/api/stream/channels/ap-log.ts diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index c1555132df..11866c0fa9 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1082,6 +1082,8 @@ admin/views/dashboard.vue: dashboard: "ダッシュボード" accounts: "アカウント" notes: "投稿" + drive: "ドライブ" + instances: "インスタンス" this-instance: "このインスタンス" federated: "連合" invite: "招待" diff --git a/src/client/app/admin/views/ap-log.vue b/src/client/app/admin/views/ap-log.vue new file mode 100644 index 0000000000..a26627a90f --- /dev/null +++ b/src/client/app/admin/views/ap-log.vue @@ -0,0 +1,113 @@ + + + + + diff --git a/src/client/app/admin/views/dashboard.vue b/src/client/app/admin/views/dashboard.vue index 95000d4bad..04a4de8746 100644 --- a/src/client/app/admin/views/dashboard.vue +++ b/src/client/app/admin/views/dashboard.vue @@ -7,6 +7,7 @@

Node{{ meta.node }}

藍ちゃかわいい

+
@@ -34,22 +35,22 @@
-
%fa:user%
+
%fa:database%
- %i18n:@accounts% - {{ stats.usersCount | number }} + %i18n:@drive% + {{ stats.driveUsageLocal | bytes }}
- %fa:globe% %i18n:@federated% + %fa:home% %i18n:@this-instance%
-
%fa:pencil-alt%
+
%fa:hdd R%
- %i18n:@notes% - {{ stats.notesCount | number }} + %i18n:@instances% + {{ stats.instances | number }}
@@ -65,6 +66,10 @@
+ +
+ +
@@ -72,11 +77,13 @@ import Vue from "vue"; import XCpuMemory from "./cpu-memory.vue"; import XCharts from "./charts.vue"; +import XApLog from "./ap-log.vue"; export default Vue.extend({ components: { XCpuMemory, - XCharts + XCharts, + XApLog }, data() { return { diff --git a/src/client/app/common/views/filters/bytes.ts b/src/client/app/common/views/filters/bytes.ts index f7a1b2690f..5b5d966cfd 100644 --- a/src/client/app/common/views/filters/bytes.ts +++ b/src/client/app/common/views/filters/bytes.ts @@ -1,6 +1,7 @@ import Vue from 'vue'; Vue.filter('bytes', (v, digits = 0) => { + if (v == null) return '?'; const sizes = ['B', 'KB', 'MB', 'GB', 'TB']; if (v == 0) return '0'; const isMinus = v < 0; diff --git a/src/client/app/common/views/filters/number.ts b/src/client/app/common/views/filters/number.ts index d9f48229dd..08f9fea805 100644 --- a/src/client/app/common/views/filters/number.ts +++ b/src/client/app/common/views/filters/number.ts @@ -1,5 +1,6 @@ import Vue from 'vue'; Vue.filter('number', (n) => { + if (n == null) return 'N/A'; return n.toLocaleString(); }); diff --git a/src/queue/processors/http/process-inbox.ts b/src/queue/processors/http/process-inbox.ts index 8e6b3769de..87f0fbfb8d 100644 --- a/src/queue/processors/http/process-inbox.ts +++ b/src/queue/processors/http/process-inbox.ts @@ -8,6 +8,7 @@ import perform from '../../../remote/activitypub/perform'; import { resolvePerson, updatePerson } from '../../../remote/activitypub/models/person'; import { toUnicode } from 'punycode'; import { URL } from 'url'; +import { publishApLogStream } from '../../../stream'; const log = debug('misskey:queue:inbox'); @@ -61,6 +62,15 @@ export default async (job: bq.Job, done: any): Promise => { }) as IRemoteUser; } + //#region Log + publishApLogStream({ + direction: 'in', + activity: activity.type, + host: user.host, + actor: user.username + }); + //#endregion + // Update activityの場合は、ここで署名検証/更新処理まで実施して終了 if (activity.type === 'Update') { if (activity.object && activity.object.type === 'Person') { diff --git a/src/remote/activitypub/request.ts b/src/remote/activitypub/request.ts index 177b6f458e..68c53e0c6c 100644 --- a/src/remote/activitypub/request.ts +++ b/src/remote/activitypub/request.ts @@ -6,6 +6,7 @@ const crypto = require('crypto'); import config from '../../config'; import { ILocalUser } from '../../models/user'; +import { publishApLogStream } from '../../stream'; const log = debug('misskey:activitypub:deliver'); @@ -64,4 +65,13 @@ export default (user: ILocalUser, url: string, object: any) => new Promise((reso }); req.end(data); + + //#region Log + publishApLogStream({ + direction: 'out', + activity: object.type, + host: null, + actor: user.username + }); + //#endregion }); diff --git a/src/server/api/stream/channels/ap-log.ts b/src/server/api/stream/channels/ap-log.ts new file mode 100644 index 0000000000..dfa1cc702d --- /dev/null +++ b/src/server/api/stream/channels/ap-log.ts @@ -0,0 +1,24 @@ +import autobind from 'autobind-decorator'; +import Channel from '../channel'; + +export default class extends Channel { + public readonly chName = 'apLog'; + public static shouldShare = true; + + @autobind + public async init(params: any) { + // Subscribe events + this.subscriber.on('apLog', this.onLog); + } + + @autobind + private async onLog(log: any) { + this.send('log', log); + } + + @autobind + public dispose() { + // Unsubscribe events + this.subscriber.off('apLog', this.onLog); + } +} diff --git a/src/server/api/stream/channels/index.ts b/src/server/api/stream/channels/index.ts index 7e71590d00..7248579abd 100644 --- a/src/server/api/stream/channels/index.ts +++ b/src/server/api/stream/channels/index.ts @@ -10,6 +10,7 @@ import messaging from './messaging'; import messagingIndex from './messaging-index'; import drive from './drive'; import hashtag from './hashtag'; +import apLog from './ap-log'; import gamesReversi from './games/reversi'; import gamesReversiGame from './games/reversi-game'; @@ -26,6 +27,7 @@ export default { messagingIndex, drive, hashtag, + apLog, gamesReversi, gamesReversiGame }; diff --git a/src/stream.ts b/src/stream.ts index b222a45ca9..543421726a 100644 --- a/src/stream.ts +++ b/src/stream.ts @@ -100,6 +100,10 @@ class Publisher { public publishHashtagStream = (note: any): void => { this.publish('hashtag', null, note); } + + public publishApLogStream = (log: any): void => { + this.publish('apLog', null, log); + } } const publisher = new Publisher(); @@ -119,3 +123,4 @@ export const publishLocalTimelineStream = publisher.publishLocalTimelineStream; export const publishHybridTimelineStream = publisher.publishHybridTimelineStream; export const publishGlobalTimelineStream = publisher.publishGlobalTimelineStream; export const publishHashtagStream = publisher.publishHashtagStream; +export const publishApLogStream = publisher.publishApLogStream;