mirror of
https://github.com/paricafe/misskey.git
synced 2025-04-09 06:09:34 -05:00
backend: ap refetch key
This commit is contained in:
parent
ad51752f38
commit
fc2f68f1d6
1 changed files with 25 additions and 4 deletions
|
@ -12,10 +12,11 @@ import type { MiUserPublickey } from '@/models/UserPublickey.js';
|
|||
import { CacheService } from '@/core/CacheService.js';
|
||||
import type { MiNote } from '@/models/Note.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { MiLocalUser, MiRemoteUser } from '@/models/User.js';
|
||||
import type { MiLocalUser, MiRemoteUser } from '@/models/User.js';
|
||||
import { getApId } from './type.js';
|
||||
import { ApPersonService } from './models/ApPersonService.js';
|
||||
import type { IObject } from './type.js';
|
||||
import { ApLoggerService } from '@/core/activitypub/ApLoggerService.js';
|
||||
|
||||
export type UriParseResult = {
|
||||
/** wether the URI was generated by us */
|
||||
|
@ -53,13 +54,14 @@ export class ApDbResolverService implements OnApplicationShutdown {
|
|||
|
||||
private cacheService: CacheService,
|
||||
private apPersonService: ApPersonService,
|
||||
private apLoggerService: ApLoggerService,
|
||||
) {
|
||||
this.publicKeyCache = new MemoryKVCache<MiUserPublickey | null>(1000 * 60 * 60 * 12); // 12h
|
||||
this.publicKeyByUserIdCache = new MemoryKVCache<MiUserPublickey | null>(1000 * 60 * 60 * 12); // 12h
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public parseUri(value: string | IObject): UriParseResult {
|
||||
public parseUri(value: string | IObject | [string | IObject]): UriParseResult {
|
||||
const separator = '/';
|
||||
|
||||
const uri = new URL(getApId(value));
|
||||
|
@ -78,7 +80,7 @@ export class ApDbResolverService implements OnApplicationShutdown {
|
|||
* AP Note => Misskey Note in DB
|
||||
*/
|
||||
@bindThis
|
||||
public async getNoteFromApId(value: string | IObject): Promise<MiNote | null> {
|
||||
public async getNoteFromApId(value: string | IObject | [string | IObject]): Promise<MiNote | null> {
|
||||
const parsed = this.parseUri(value);
|
||||
|
||||
if (parsed.local) {
|
||||
|
@ -98,7 +100,7 @@ export class ApDbResolverService implements OnApplicationShutdown {
|
|||
* AP Person => Misskey User in DB
|
||||
*/
|
||||
@bindThis
|
||||
public async getUserFromApId(value: string | IObject): Promise<MiLocalUser | MiRemoteUser | null> {
|
||||
public async getUserFromApId(value: string | IObject | [string | IObject]): Promise<MiLocalUser | MiRemoteUser | null> {
|
||||
const parsed = this.parseUri(value);
|
||||
|
||||
if (parsed.local) {
|
||||
|
@ -169,6 +171,25 @@ export class ApDbResolverService implements OnApplicationShutdown {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sharkey User -> Refetched Key
|
||||
*/
|
||||
@bindThis
|
||||
public async refetchPublicKeyForApId(user: MiRemoteUser): Promise<MiUserPublickey | null> {
|
||||
this.apLoggerService.logger.debug('Re-fetching public key for user', { userId: user.id, uri: user.uri });
|
||||
await this.apPersonService.updatePerson(user.uri);
|
||||
|
||||
const key = await this.userPublickeysRepository.findOneBy({ userId: user.id });
|
||||
this.publicKeyByUserIdCache.set(user.id, key);
|
||||
|
||||
if (key) {
|
||||
this.apLoggerService.logger.info('Re-fetched public key for user', { userId: user.id, uri: user.uri });
|
||||
} else {
|
||||
this.apLoggerService.logger.warn('Failed to re-fetch key for user', { userId: user.id, uri: user.uri });
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
@bindThis
|
||||
public dispose(): void {
|
||||
this.publicKeyCache.dispose();
|
||||
|
|
Loading…
Add table
Reference in a new issue