Improve instances manegement

Resolve #4187
This commit is contained in:
syuilo 2019-02-08 20:56:16 +09:00
parent 72b85fc09f
commit 5e0eda9526
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
7 changed files with 65 additions and 11 deletions

View file

@ -1384,6 +1384,7 @@ admin/views/federation.vue:
remove-all-following: "フォローを全解除" remove-all-following: "フォローを全解除"
remove-all-following-info: "{host}からのフォローをすべて解除します。そのインスタンスがもう存在しなくなった場合などに実行してください。" remove-all-following-info: "{host}からのフォローをすべて解除します。そのインスタンスがもう存在しなくなった場合などに実行してください。"
block: "ブロック" block: "ブロック"
marked-as-closed: "閉鎖されているとマーク"
lookup: "照会" lookup: "照会"
instances: "インスタンス" instances: "インスタンス"
instance-not-registered: "そのインスタンスは登録されていません" instance-not-registered: "そのインスタンスは登録されていません"
@ -1391,6 +1392,8 @@ admin/views/federation.vue:
sorts: sorts:
caughtAtAsc: "登録日時が古い順" caughtAtAsc: "登録日時が古い順"
caughtAtDesc: "登録日時が新しい順" caughtAtDesc: "登録日時が新しい順"
lastCommunicatedAtAsc: "最後にやり取りした日時が古い順"
lastCommunicatedAtDesc: "最後にやり取りした日時が新しい順"
notesAsc: "投稿が少ない順" notesAsc: "投稿が少ない順"
notesDesc: "投稿が多い順" notesDesc: "投稿が多い順"
usersAsc: "ユーザーが少ない順" usersAsc: "ユーザーが少ない順"
@ -1407,6 +1410,8 @@ admin/views/federation.vue:
states: states:
all: "すべて" all: "すべて"
blocked: "ブロック" blocked: "ブロック"
not-responding: "応答なし"
marked-as-closed: "閉鎖とマーク済み"
result-is-truncated: "上位{n}件を表示しています。" result-is-truncated: "上位{n}件を表示しています。"
charts: "チャート" charts: "チャート"
chart-srcs: chart-srcs:

View file

@ -40,6 +40,7 @@
<span>{{ $t('latest-request-received-at') }}</span> <span>{{ $t('latest-request-received-at') }}</span>
</ui-input> </ui-input>
<ui-switch v-model="instance.isBlocked" @change="updateInstance()">{{ $t('block') }}</ui-switch> <ui-switch v-model="instance.isBlocked" @change="updateInstance()">{{ $t('block') }}</ui-switch>
<ui-switch v-model="instance.isMarkedAsClosed" @change="updateInstance()">{{ $t('marked-as-closed') }}</ui-switch>
<details> <details>
<summary>{{ $t('charts') }}</summary> <summary>{{ $t('charts') }}</summary>
<ui-horizon-group inputs> <ui-horizon-group inputs>
@ -80,6 +81,8 @@
<span slot="label">{{ $t('sort') }}</span> <span slot="label">{{ $t('sort') }}</span>
<option value="-caughtAt">{{ $t('sorts.caughtAtAsc') }}</option> <option value="-caughtAt">{{ $t('sorts.caughtAtAsc') }}</option>
<option value="+caughtAt">{{ $t('sorts.caughtAtDesc') }}</option> <option value="+caughtAt">{{ $t('sorts.caughtAtDesc') }}</option>
<option value="-lastCommunicatedAt">{{ $t('sorts.lastCommunicatedAtAsc') }}</option>
<option value="+lastCommunicatedAt">{{ $t('sorts.lastCommunicatedAtDesc') }}</option>
<option value="-notes">{{ $t('sorts.notesAsc') }}</option> <option value="-notes">{{ $t('sorts.notesAsc') }}</option>
<option value="+notes">{{ $t('sorts.notesDesc') }}</option> <option value="+notes">{{ $t('sorts.notesDesc') }}</option>
<option value="-users">{{ $t('sorts.usersAsc') }}</option> <option value="-users">{{ $t('sorts.usersAsc') }}</option>
@ -97,6 +100,8 @@
<span slot="label">{{ $t('state') }}</span> <span slot="label">{{ $t('state') }}</span>
<option value="all">{{ $t('states.all') }}</option> <option value="all">{{ $t('states.all') }}</option>
<option value="blocked">{{ $t('states.blocked') }}</option> <option value="blocked">{{ $t('states.blocked') }}</option>
<option value="notResponding">{{ $t('states.not-responding') }}</option>
<option value="markedAsClosed">{{ $t('states.marked-as-closed') }}</option>
</ui-select> </ui-select>
</ui-horizon-group> </ui-horizon-group>
@ -247,7 +252,9 @@ export default Vue.extend({
fetchInstances() { fetchInstances() {
this.instances = []; this.instances = [];
this.$root.api('federation/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, sort: this.sort,
limit: this.limit limit: this.limit
}).then(instances => { }).then(instances => {
@ -269,7 +276,8 @@ export default Vue.extend({
updateInstance() { updateInstance() {
this.$root.api('admin/federation/update-instance', { this.$root.api('admin/federation/update-instance', {
host: this.instance.host, host: this.instance.host,
isBlocked: this.instance.isBlocked, isBlocked: this.instance.isBlocked || false,
isClosed: this.instance.isMarkedAsClosed || false
}); });
}, },

View file

@ -68,8 +68,23 @@ export interface IInstance {
*/ */
latestRequestReceivedAt?: Date; latestRequestReceivedAt?: Date;
/**
*
*/
isNotResponding: boolean;
/**
*
*/
lastCommunicatedAt: Date;
/** /**
* *
*/ */
isBlocked: boolean; isBlocked: boolean;
/**
*
*/
isMarkedAsClosed: boolean;
} }

View file

@ -17,7 +17,9 @@ export default async (job: bq.Job, done: any): Promise<void> => {
Instance.update({ _id: i._id }, { Instance.update({ _id: i._id }, {
$set: { $set: {
latestRequestSentAt: new Date(), 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<void> => {
Instance.update({ _id: i._id }, { Instance.update({ _id: i._id }, {
$set: { $set: {
latestRequestSentAt: new Date(), latestRequestSentAt: new Date(),
latestStatus: res != null && res.hasOwnProperty('statusCode') ? res.statusCode : null latestStatus: res != null && res.hasOwnProperty('statusCode') ? res.statusCode : null,
isNotResponding: true
} }
}); });

View file

@ -126,7 +126,9 @@ export default async (job: bq.Job, done: any): Promise<void> => {
registerOrFetchInstanceDoc(user.host).then(i => { registerOrFetchInstanceDoc(user.host).then(i => {
Instance.update({ _id: i._id }, { Instance.update({ _id: i._id }, {
$set: { $set: {
latestRequestReceivedAt: new Date() latestRequestReceivedAt: new Date(),
lastCommunicatedAt: new Date(),
isNotResponding: false
} }
}); });

View file

@ -14,6 +14,10 @@ export const meta = {
isBlocked: { isBlocked: {
validator: $.bool 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 }, { Instance.update({ host: ps.host }, {
$set: { $set: {
isBlocked: ps.isBlocked isBlocked: ps.isBlocked,
isMarkedAsClosed: ps.isClosed
} }
}); });

View file

@ -6,8 +6,16 @@ export const meta = {
requireCredential: false, requireCredential: false,
params: { params: {
state: { blocked: {
validator: $.str.optional, validator: $.bool.optional.nullable,
},
notResponding: {
validator: $.bool.optional.nullable,
},
markedAsClosed: {
validator: $.bool.optional.nullable,
}, },
limit: { limit: {
@ -70,6 +78,14 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
sort = { sort = {
caughtAt: 1 caughtAt: 1
}; };
} else if (ps.sort == '+lastCommunicatedAt') {
sort = {
lastCommunicatedAt: -1
};
} else if (ps.sort == '-lastCommunicatedAt') {
sort = {
lastCommunicatedAt: 1
};
} else if (ps.sort == '+driveUsage') { } else if (ps.sort == '+driveUsage') {
sort = { sort = {
driveUsage: -1 driveUsage: -1
@ -95,9 +111,9 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
const q = {} as any; const q = {} as any;
if (ps.state === 'blocked') { if (typeof ps.blocked === 'boolean') q.isBlocked = ps.blocked;
q.isBlocked = true; if (typeof ps.notResponding === 'boolean') q.isNotResponding = ps.notResponding;
} if (typeof ps.markedAsClosed === 'boolean') q.isMarkedAsClosed = ps.markedAsClosed;
const instances = await Instance const instances = await Instance
.find(q, { .find(q, {