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-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:

View file

@ -40,6 +40,7 @@
<span>{{ $t('latest-request-received-at') }}</span>
</ui-input>
<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>
<summary>{{ $t('charts') }}</summary>
<ui-horizon-group inputs>
@ -80,6 +81,8 @@
<span slot="label">{{ $t('sort') }}</span>
<option value="-caughtAt">{{ $t('sorts.caughtAtAsc') }}</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.notesDesc') }}</option>
<option value="-users">{{ $t('sorts.usersAsc') }}</option>
@ -97,6 +100,8 @@
<span slot="label">{{ $t('state') }}</span>
<option value="all">{{ $t('states.all') }}</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-horizon-group>
@ -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
});
},

View file

@ -68,8 +68,23 @@ export interface IInstance {
*/
latestRequestReceivedAt?: Date;
/**
*
*/
isNotResponding: boolean;
/**
*
*/
lastCommunicatedAt: Date;
/**
*
*/
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 }, {
$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<void> => {
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
}
});

View file

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

View file

@ -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
}
});

View file

@ -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, {