Skip to content

Commit

Permalink
サーバー情報にリバーシのバージョンを表示する (misskey-dev#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
kozakura913 authored and nanasina8 committed Sep 6, 2024
1 parent d9611d2 commit e5894a5
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 5 deletions.
15 changes: 14 additions & 1 deletion locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10083,7 +10083,20 @@ export interface Locale extends ILocale {
/**
* 石をアイコンにする
*/
readonly "useAvatarAsStone": string;
"useAvatarAsStone": string;
/**
* リモートサーバーのバージョンが不明です
*/
"remoteVersionUnknown": string;
/**
* 対応していない可能性があります
*/
"remoteVersionUnknownCaption": string;
/**
* リモートサーバーのバージョンが非互換です
*/
"remoteVersionBad": string;
>>>>>>> b6c6d136b2 (サーバー情報にリバーシのバージョンを表示する (#384))
};
readonly "_offlineScreen": {
/**
Expand Down
3 changes: 3 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2684,6 +2684,9 @@ _reversi:
disallowIrregularRules: "変則なし"
showBoardLabels: "盤面に行・列番号を表示"
useAvatarAsStone: "石をアイコンにする"
remoteVersionUnknown: "リモートサーバーのバージョンが不明です"
remoteVersionUnknownCaption: "対応していない可能性があります"
remoteVersionBad: "リモートサーバーのバージョンが非互換です"

_offlineScreen:
title: "オフライン - サーバーに接続できません"
Expand Down
16 changes: 16 additions & 0 deletions packages/backend/migration/1724921022768-AddNodeinfoReversi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project, yojo-art team
* SPDX-License-Identifier: AGPL-3.0-only
*/

export class AddNodeinfoReversi1724921022768 {
name = 'AddNodeinfoReversi1724921022768'

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "instance" ADD "reversiVersion" character varying(32)`);
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "instance" DROP COLUMN "reversiVersion"`);
}
}
1 change: 1 addition & 0 deletions packages/backend/src/core/FetchInstanceMetadataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export class FetchInstanceMetadataService {
updates.openRegistrations = info.openRegistrations;
updates.maintainerName = info.metadata ? info.metadata.maintainer ? (info.metadata.maintainer.name ?? null) : null : null;
updates.maintainerEmail = info.metadata ? info.metadata.maintainer ? (info.metadata.maintainer.email ?? null) : null : null;
updates.reversiVersion = info.metadata ? info.metadata.reversiVersion ?? null : null;
}

if (name) updates.name = name;
Expand Down
6 changes: 3 additions & 3 deletions packages/backend/src/core/ReversiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
if (typeof(reversiVersion) === 'string') {
//0.0.0-foo => 0.0.0
const version = reversiVersion.split('-')[0];
await this.redisClient.setex(`reversi:federation:version:${host}`, version, 5 * 60);
await this.redisClient.setex(`reversi:federation:version:${host}`, 5 * 60, version);
return version;
}
await this.redisClient.setex(`reversi:federation:version:${host}`, '', 5 * 60);
await this.redisClient.setex(`reversi:federation:version:${host}`, 5 * 60, '');
return null;
}
@bindThis
Expand All @@ -132,7 +132,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit {
}
const versionElements = version.split('.');
if (versionElements.length === 3) {
if (versionElements[0] !== NodeinfoServerService.reversiVersion.split('-')[0].split('.')[0]) {
if (versionElements[0] !== NodeinfoServerService.reversiVersion.split('.')[0]) {
//メジャーバージョン不一致
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class ApGameService {
const targetUser = local_user;
const fromUser = remote_user;
if (!game.game_state.game_session_id) throw Error('bad session' + JSON.stringify(game));
if (await this.reversiService.federationAvailable(remote_user.host) === false) {
if ((await this.reversiService.federationAvailable(remote_user.host)) === false) {
//確実に利用できない時
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class InstanceEntityService {
infoUpdatedAt: instance.infoUpdatedAt ? instance.infoUpdatedAt.toISOString() : null,
latestRequestReceivedAt: instance.latestRequestReceivedAt ? instance.latestRequestReceivedAt.toISOString() : null,
moderationNote: iAmModerator ? instance.moderationNote : null,
reversiVersion: instance.reversiVersion,
};
}

Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/core/entities/MetaEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { InstanceActorService } from '@/core/InstanceActorService.js';
import type { Config } from '@/config.js';
import { DI } from '@/di-symbols.js';
import { DEFAULT_POLICIES } from '@/core/RoleService.js';
import { NodeinfoServerService } from '@/server/NodeinfoServerService.js';

@Injectable()
export class MetaEntityService {
Expand Down Expand Up @@ -129,6 +130,7 @@ export class MetaEntityService {
mediaProxy: this.config.mediaProxy,
enableUrlPreview: instance.urlPreviewEnabled,
noteSearchableScope: (this.config.meilisearch == null || this.config.meilisearch.scope !== 'local') ? 'global' : 'local',
reversiVersion: NodeinfoServerService.reversiVersion,
};

return packed;
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/src/models/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,9 @@ export class MiInstance {
length: 16384, default: '',
})
public moderationNote: string;

@Column('varchar', {
length: 64, nullable: true,
})
public reversiVersion: string | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,9 @@ export const packedFederationInstanceSchema = {
type: 'string',
optional: true, nullable: true,
},
reversiVersion: {
type: 'string',
optional: true, nullable: true,
},
},
} as const;
4 changes: 4 additions & 0 deletions packages/backend/src/models/json-schema/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ export const packedMetaLiteSchema = {
optional: false, nullable: false,
default: 'local',
},
reversiVersion: {
type: 'string',
optional: false, nullable: false,
},
},
} as const;

Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/src/components/MkInstanceCardMini.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<div class="body">
<span class="host">{{ instance.name ?? instance.host }}</span>
<span class="sub _monospace"><b>{{ instance.host }}</b> / {{ instance.softwareName || '?' }} {{ instance.softwareVersion }}</span>
<span class="sub _monospace"><b>{{ i18n.ts._reversi.reversi }}</b> / {{ instance.reversiVersion || `(${i18n.ts.unknown})` }}</span>
</div>
<MkMiniChart v-if="chartValues" class="chart" :src="chartValues"/>
</div>
Expand All @@ -20,6 +21,7 @@ import * as Misskey from 'misskey-js';
import MkMiniChart from '@/components/MkMiniChart.vue';
import { misskeyApiGet } from '@/scripts/misskey-api.js';
import { getProxiedImageUrlNullable } from '@/scripts/media-proxy.js';
import { i18n } from '@/i18n.js';

const props = defineProps<{
instance: Misskey.entities.FederationInstance;
Expand Down
4 changes: 4 additions & 0 deletions packages/frontend/src/pages/instance-info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #key>{{ i18n.ts.software }}</template>
<template #value><span class="_monospace">{{ instance.softwareName || `(${i18n.ts.unknown})` }} / {{ instance.softwareVersion || `(${i18n.ts.unknown})` }}</span></template>
</MkKeyValue>
<MkKeyValue oneline>
<template #key>{{ i18n.ts._reversi.reversi }}</template>
<template #value><span class="_monospace">{{ instance.reversiVersion || `(${i18n.ts.unknown})` }} </span></template>
</MkKeyValue>
<MkKeyValue oneline>
<template #key>{{ i18n.ts.administrator }}</template>
<template #value>{{ instance.maintainerName || `(${i18n.ts.unknown})` }} ({{ instance.maintainerEmail || `(${i18n.ts.unknown})` }})</template>
Expand Down
29 changes: 29 additions & 0 deletions packages/frontend/src/pages/reversi/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ import * as os from '@/os.js';
import { useInterval } from '@/scripts/use-interval.js';
import { pleaseLogin } from '@/scripts/please-login.js';
import * as sound from '@/scripts/sound.js';
import { instance } from '@/instance.js';

const myGamesPagination = {
endpoint: 'reversi/games' as const,
Expand Down Expand Up @@ -198,6 +199,34 @@ async function matchUser() {

const user = await os.selectUser({ includeSelf: false, localOnly: false });
if (user == null) return;
if (user.host) {
let remote_instance = await misskeyApi('federation/show-instance', {
host: user.host,
});
//初期のバージョン番号を持たない実装は1.0.0扱いにする
const reversiVersion = remote_instance?.reversiVersion ?? '1.0.0';

const versionElements = reversiVersion.split('.');
if (versionElements.length === 3) {
if (versionElements[0] !== instance.reversiVersion.split('.')[0]) {
//メジャーバージョン不一致
await os.alert({
type: 'error',
text: i18n.ts._reversi.remoteVersionBad,
});
return;
}
}
//バージョン番号不明の場合は警告だけ出す
if (!remote_instance?.reversiVersion) {
const { canceled } = await os.confirm({
type: 'warning',
text: i18n.ts._reversi.remoteVersionUnknown,
caption: i18n.ts._reversi.remoteVersionUnknownCaption,
});
if (canceled) return;
}
}

matchingUser.value = user;

Expand Down
2 changes: 2 additions & 0 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4610,6 +4610,7 @@ export type components = {
/** Format: date-time */
latestRequestReceivedAt: string | null;
moderationNote?: string | null;
reversiVersion?: string | null;
};
GalleryPost: {
/**
Expand Down Expand Up @@ -4947,6 +4948,7 @@ export type components = {
* @enum {string}
*/
noteSearchableScope: 'local' | 'global';
reversiVersion: string;
};
MetaDetailedOnly: {
features?: {
Expand Down

0 comments on commit e5894a5

Please sign in to comment.