mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-25 00:49:17 +09:00
Mod: とりあえずproxyAccountをシステムアカウントな感じにしてみた
This commit is contained in:
parent
763c708253
commit
10b3458cda
@ -4,25 +4,54 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
|
import { IsNull } from 'typeorm';
|
||||||
import type { MiMeta, UsersRepository } from '@/models/_.js';
|
import type { MiMeta, UsersRepository } from '@/models/_.js';
|
||||||
import type { MiLocalUser } from '@/models/User.js';
|
import type { MiLocalUser } from '@/models/User.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
|
import { CreateSystemUserService } from '@/core/CreateSystemUserService.js';
|
||||||
|
import { MemorySingleCache } from '@/misc/cache.js';
|
||||||
|
import { MetaService } from '@/core/MetaService.js';
|
||||||
|
|
||||||
|
const ACTOR_USERNAME = 'proxy.actor' as const;
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ProxyAccountService {
|
export class ProxyAccountService {
|
||||||
|
private cache: MemorySingleCache<MiLocalUser>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DI.meta)
|
@Inject(DI.meta)
|
||||||
private meta: MiMeta,
|
private meta: MiMeta,
|
||||||
|
|
||||||
@Inject(DI.usersRepository)
|
@Inject(DI.usersRepository)
|
||||||
private usersRepository: UsersRepository,
|
private usersRepository: UsersRepository,
|
||||||
|
|
||||||
|
private createSystemUserService: CreateSystemUserService,
|
||||||
|
private metaService: MetaService,
|
||||||
) {
|
) {
|
||||||
|
this.cache = new MemorySingleCache<MiLocalUser>(Infinity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async fetch(): Promise<MiLocalUser | null> {
|
public async fetch(): Promise<MiLocalUser | null> {
|
||||||
if (this.meta.proxyAccountId == null) return null;
|
const cached = this.cache.get();
|
||||||
return await this.usersRepository.findOneByOrFail({ id: this.meta.proxyAccountId }) as MiLocalUser;
|
if (cached) return cached;
|
||||||
|
|
||||||
|
const user = await this.usersRepository.findOneBy({
|
||||||
|
host: IsNull(),
|
||||||
|
username: ACTOR_USERNAME,
|
||||||
|
}) as MiLocalUser | undefined;
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
this.cache.set(user);
|
||||||
|
return user;
|
||||||
|
} else {
|
||||||
|
const created = await this.createSystemUserService.createSystemUser(ACTOR_USERNAME) as MiLocalUser;
|
||||||
|
this.cache.set(created);
|
||||||
|
const set = {} as Partial<MiMeta>;
|
||||||
|
set.proxyAccountId = created.id;
|
||||||
|
await this.metaService.update(set);
|
||||||
|
return created;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user