なんかもうめっちゃ変えた
This commit is contained in:
parent
d9ab03f086
commit
b75184ec8e
946 changed files with 41219 additions and 28839 deletions
52
packages/backend/src/core/entities/AppEntityService.ts
Normal file
52
packages/backend/src/core/entities/AppEntityService.ts
Normal file
|
@ -0,0 +1,52 @@
|
|||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { AccessTokensRepository, AppsRepository } from '@/models/index.js';
|
||||
import { awaitAll } from '@/misc/prelude/await-all.js';
|
||||
import type { Packed } from '@/misc/schema.js';
|
||||
import type { App } from '@/models/entities/App.js';
|
||||
import type { User } from '@/models/entities/User.js';
|
||||
import { UserEntityService } from './UserEntityService.js';
|
||||
|
||||
@Injectable()
|
||||
export class AppEntityService {
|
||||
constructor(
|
||||
@Inject(DI.appsRepository)
|
||||
private appsRepository: AppsRepository,
|
||||
|
||||
@Inject(DI.accessTokensRepository)
|
||||
private accessTokensRepository: AccessTokensRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public async pack(
|
||||
src: App['id'] | App,
|
||||
me?: { id: User['id'] } | null | undefined,
|
||||
options?: {
|
||||
detail?: boolean,
|
||||
includeSecret?: boolean,
|
||||
includeProfileImageIds?: boolean
|
||||
},
|
||||
): Promise<Packed<'App'>> {
|
||||
const opts = Object.assign({
|
||||
detail: false,
|
||||
includeSecret: false,
|
||||
includeProfileImageIds: false,
|
||||
}, options);
|
||||
|
||||
const app = typeof src === 'object' ? src : await this.appsRepository.findOneByOrFail({ id: src });
|
||||
|
||||
return {
|
||||
id: app.id,
|
||||
name: app.name,
|
||||
callbackUrl: app.callbackUrl,
|
||||
permission: app.permission,
|
||||
...(opts.includeSecret ? { secret: app.secret } : {}),
|
||||
...(me ? {
|
||||
isAuthorized: await this.accessTokensRepository.countBy({
|
||||
appId: app.id,
|
||||
userId: me.id,
|
||||
}).then(count => count > 0),
|
||||
} : {}),
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue