Skip to content

Commit

Permalink
Enhance: 登録できるユーザー数を表示できるように (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyatea committed Nov 28, 2024
1 parent f0a1668 commit 3a4e031
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
11 changes: 11 additions & 0 deletions packages/backend/src/server/api/endpoints/admin/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
*/

import { Inject, Injectable } from '@nestjs/common';
import { In, IsNull, Not } from 'typeorm';
import { Endpoint } from '@/server/api/endpoint-base.js';
import { MetaService } from '@/core/MetaService.js';
import type { Config } from '@/config.js';
import { DI } from '@/di-symbols.js';
import { DEFAULT_POLICIES } from '@/core/RoleService.js';
import { envOption } from '@/env.js';
import type { UsersRepository } from '@/models/_.js';

export const meta = {
tags: ['meta'],
Expand Down Expand Up @@ -644,6 +646,9 @@ export const meta = {
iconDark: { type: 'string', nullable: true },
bannerLight: { type: 'string', nullable: true },
bannerDark: { type: 'string', nullable: true },
maxLocalUsers: { type: 'number', nullable: true },
nowLocalUsers: { type: 'number', nullable: true },
isManaged: { type: 'boolean', nullable: true },
},
},
} as const;
Expand All @@ -659,6 +664,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
constructor(
@Inject(DI.config)
private config: Config,
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
private metaService: MetaService,
) {
super(meta, paramDef, async (_, me) => {
Expand Down Expand Up @@ -787,6 +794,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
urlPreviewRequireContentLength: instance.urlPreviewRequireContentLength,
urlPreviewUserAgent: instance.urlPreviewUserAgent,
urlPreviewSummaryProxyUrl: instance.urlPreviewSummaryProxyUrl,
maxLocalUsers: 0,
nowLocalUsers: 0,
};

if (!envOption.managed || this.config.rootUserName === me.username) {
Expand All @@ -807,6 +816,8 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
objectStorageUseProxy: false,
objectStorageSetPublicRead: false,
objectStorageS3ForcePathStyle: false,
maxLocalUsers: this.config.maxLocalUsers,
nowLocalUsers: await this.usersRepository.count({ where: { host: IsNull(), username: Not(In(['instance.actor', 'relay.actor', this.config.adminUserName, this.config.rootUserName])) } }),
summalyProxy: 'Masked',
deeplAuthKey: 'Masked',
isManaged: true,
Expand Down
33 changes: 31 additions & 2 deletions packages/frontend/src/pages/admin/overview.stats.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,33 @@ SPDX-License-Identifier: AGPL-3.0-only
<div class="label">Online</div>
</div>
</div>
<div v-if="meta?.isManaged" class="item _panel users">
<div class="icon"><i class="ti ti-users"></i></div>
<div class="body">
<div class="value">
<MkNumber :value="meta?.nowLocalUsers" style="margin-right: 0.5em;"/>
</div>
<div class="label">Now Local Users</div>
</div>
</div>
<div v-if="meta?.isManaged" class="item _panel users">
<div class="icon"><i class="ti ti-users"></i></div>
<div class="body">
<div class="value">
<MkNumber :value="meta?.maxLocalUsers" style="margin-right: 0.5em;"/>
</div>
<div class="label">Max Local Users</div>
</div>
</div>
<div v-if="meta?.isManaged" class="item _panel users">
<div class="icon"><i class="ti ti-users"></i></div>
<div class="body">
<div class="value">
<MkNumber :value="meta?.maxLocalUsers - meta?.nowLocalUsers" style="margin-right: 0.5em;"/>
</div>
<div class="label">登録できるユーザー数</div>
</div>
</div>
</div>
</Transition>
</div>
Expand All @@ -71,19 +98,21 @@ import { customEmojis } from '@/custom-emojis.js';
import { defaultStore } from '@/store.js';

const stats = ref<Misskey.entities.StatsResponse | null>(null);
const meta = ref<Misskey.entities.AdminMetaResponse | null>(null);
const usersComparedToThePrevDay = ref<number>();
const notesComparedToThePrevDay = ref<number>();
const onlineUsersCount = ref(0);
const fetching = ref(true);

onMounted(async () => {
const [_stats, _onlineUsersCount] = await Promise.all([
const [_stats, _meta, _onlineUsersCount] = await Promise.all([
misskeyApi('stats', {}),
misskeyApi('admin/meta', {}),
misskeyApiGet('get-online-users-count').then(res => res.count),
]);
stats.value = _stats;
onlineUsersCount.value = _onlineUsersCount;

meta.value = _meta;
misskeyApiGet('charts/users', { limit: 2, span: 'day' }).then(chart => {
usersComparedToThePrevDay.value = stats.value.originalUsersCount - chart.local.total[1];
});
Expand Down
3 changes: 3 additions & 0 deletions packages/misskey-js/src/autogen/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5442,6 +5442,9 @@ export type operations = {
iconDark: string | null;
bannerLight: string | null;
bannerDark: string | null;
maxLocalUsers: number | null;
nowLocalUsers: number | null;
isManaged: boolean | null;
};
};
};
Expand Down

0 comments on commit 3a4e031

Please sign in to comment.