From 5e0eda9526d512344485a4ec642775ca04c2c1af Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 8 Feb 2019 20:56:16 +0900 Subject: [PATCH] Improve instances manegement Resolve #4187 --- locales/ja-JP.yml | 5 ++++ src/client/app/admin/views/federation.vue | 12 +++++++-- src/models/instance.ts | 15 +++++++++++ src/queue/processors/http/deliver.ts | 7 +++-- src/queue/processors/http/process-inbox.ts | 4 ++- .../admin/federation/update-instance.ts | 7 ++++- .../api/endpoints/federation/instances.ts | 26 +++++++++++++++---- 7 files changed, 65 insertions(+), 11 deletions(-) diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index a6148a62d..f052d4ed8 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1384,6 +1384,7 @@ admin/views/federation.vue: remove-all-following: "フォローを全解除" remove-all-following-info: "{host}からのフォローをすべて解除します。そのインスタンスがもう存在しなくなった場合などに実行してください。" block: "ブロック" + marked-as-closed: "閉鎖されているとマーク" lookup: "照会" instances: "インスタンス" instance-not-registered: "そのインスタンスは登録されていません" @@ -1391,6 +1392,8 @@ admin/views/federation.vue: sorts: caughtAtAsc: "登録日時が古い順" caughtAtDesc: "登録日時が新しい順" + lastCommunicatedAtAsc: "最後にやり取りした日時が古い順" + lastCommunicatedAtDesc: "最後にやり取りした日時が新しい順" notesAsc: "投稿が少ない順" notesDesc: "投稿が多い順" usersAsc: "ユーザーが少ない順" @@ -1407,6 +1410,8 @@ admin/views/federation.vue: states: all: "すべて" blocked: "ブロック" + not-responding: "応答なし" + marked-as-closed: "閉鎖とマーク済み" result-is-truncated: "上位{n}件を表示しています。" charts: "チャート" chart-srcs: diff --git a/src/client/app/admin/views/federation.vue b/src/client/app/admin/views/federation.vue index 8b0e9ba45..b60ce8924 100644 --- a/src/client/app/admin/views/federation.vue +++ b/src/client/app/admin/views/federation.vue @@ -40,6 +40,7 @@ {{ $t('latest-request-received-at') }} {{ $t('block') }} + {{ $t('marked-as-closed') }}
{{ $t('charts') }} @@ -80,6 +81,8 @@ {{ $t('sort') }} + + @@ -97,6 +100,8 @@ {{ $t('state') }} + + @@ -247,7 +252,9 @@ export default Vue.extend({ fetchInstances() { this.instances = []; this.$root.api('federation/instances', { - state: this.state, + blocked: this.state === 'blocked' ? true : null, + notResponding: this.state === 'notResponding' ? true : null, + markedAsClosed: this.state === 'markedAsClosed' ? true : null, sort: this.sort, limit: this.limit }).then(instances => { @@ -269,7 +276,8 @@ export default Vue.extend({ updateInstance() { this.$root.api('admin/federation/update-instance', { host: this.instance.host, - isBlocked: this.instance.isBlocked, + isBlocked: this.instance.isBlocked || false, + isClosed: this.instance.isMarkedAsClosed || false }); }, diff --git a/src/models/instance.ts b/src/models/instance.ts index 985564f8d..cdce570a4 100644 --- a/src/models/instance.ts +++ b/src/models/instance.ts @@ -68,8 +68,23 @@ export interface IInstance { */ latestRequestReceivedAt?: Date; + /** + * このインスタンスと不通かどうか + */ + isNotResponding: boolean; + + /** + * このインスタンスと最後にやり取りした日時 + */ + lastCommunicatedAt: Date; + /** * このインスタンスをブロックしているか */ isBlocked: boolean; + + /** + * このインスタンスが閉鎖済みとしてマークされているか + */ + isMarkedAsClosed: boolean; } diff --git a/src/queue/processors/http/deliver.ts b/src/queue/processors/http/deliver.ts index 6d24cd263..1ba582a28 100644 --- a/src/queue/processors/http/deliver.ts +++ b/src/queue/processors/http/deliver.ts @@ -17,7 +17,9 @@ export default async (job: bq.Job, done: any): Promise => { Instance.update({ _id: i._id }, { $set: { latestRequestSentAt: new Date(), - latestStatus: 200 + latestStatus: 200, + lastCommunicatedAt: new Date(), + isNotResponding: false } }); @@ -31,7 +33,8 @@ export default async (job: bq.Job, done: any): Promise => { Instance.update({ _id: i._id }, { $set: { latestRequestSentAt: new Date(), - latestStatus: res != null && res.hasOwnProperty('statusCode') ? res.statusCode : null + latestStatus: res != null && res.hasOwnProperty('statusCode') ? res.statusCode : null, + isNotResponding: true } }); diff --git a/src/queue/processors/http/process-inbox.ts b/src/queue/processors/http/process-inbox.ts index 07d4b5ba7..43170848f 100644 --- a/src/queue/processors/http/process-inbox.ts +++ b/src/queue/processors/http/process-inbox.ts @@ -126,7 +126,9 @@ export default async (job: bq.Job, done: any): Promise => { registerOrFetchInstanceDoc(user.host).then(i => { Instance.update({ _id: i._id }, { $set: { - latestRequestReceivedAt: new Date() + latestRequestReceivedAt: new Date(), + lastCommunicatedAt: new Date(), + isNotResponding: false } }); diff --git a/src/server/api/endpoints/admin/federation/update-instance.ts b/src/server/api/endpoints/admin/federation/update-instance.ts index de40480a4..579b437aa 100644 --- a/src/server/api/endpoints/admin/federation/update-instance.ts +++ b/src/server/api/endpoints/admin/federation/update-instance.ts @@ -14,6 +14,10 @@ export const meta = { isBlocked: { validator: $.bool }, + + isClosed: { + validator: $.bool + }, } }; @@ -26,7 +30,8 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => { Instance.update({ host: ps.host }, { $set: { - isBlocked: ps.isBlocked + isBlocked: ps.isBlocked, + isMarkedAsClosed: ps.isClosed } }); diff --git a/src/server/api/endpoints/federation/instances.ts b/src/server/api/endpoints/federation/instances.ts index 9b4efbaaf..9c1e57ee1 100644 --- a/src/server/api/endpoints/federation/instances.ts +++ b/src/server/api/endpoints/federation/instances.ts @@ -6,8 +6,16 @@ export const meta = { requireCredential: false, params: { - state: { - validator: $.str.optional, + blocked: { + validator: $.bool.optional.nullable, + }, + + notResponding: { + validator: $.bool.optional.nullable, + }, + + markedAsClosed: { + validator: $.bool.optional.nullable, }, limit: { @@ -70,6 +78,14 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => { sort = { caughtAt: 1 }; + } else if (ps.sort == '+lastCommunicatedAt') { + sort = { + lastCommunicatedAt: -1 + }; + } else if (ps.sort == '-lastCommunicatedAt') { + sort = { + lastCommunicatedAt: 1 + }; } else if (ps.sort == '+driveUsage') { sort = { driveUsage: -1 @@ -95,9 +111,9 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => { const q = {} as any; - if (ps.state === 'blocked') { - q.isBlocked = true; - } + if (typeof ps.blocked === 'boolean') q.isBlocked = ps.blocked; + if (typeof ps.notResponding === 'boolean') q.isNotResponding = ps.notResponding; + if (typeof ps.markedAsClosed === 'boolean') q.isMarkedAsClosed = ps.markedAsClosed; const instances = await Instance .find(q, {