This commit is contained in:
tamaina
2023-06-04 15:39:43 +00:00
parent 8bad11c559
commit f651ca4b48
3 changed files with 90 additions and 79 deletions

View File

@@ -7,34 +7,10 @@ import { secureRndstr } from '@/misc/secure-rndstr.js';
import { AppEntityService } from '@/core/entities/AppEntityService.js';
import { DI } from '@/di-symbols.js';
export const meta = {
tags: ['app'],
requireCredential: false,
res: {
type: 'object',
optional: false, nullable: false,
ref: 'App',
},
} as const;
export const paramDef = {
type: 'object',
properties: {
name: { type: 'string' },
description: { type: 'string' },
permission: { type: 'array', uniqueItems: true, items: {
type: 'string',
} },
callbackUrl: { type: 'string', nullable: true },
},
required: ['name', 'description', 'permission'],
} as const;
// eslint-disable-next-line import/no-default-export
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
export default class extends Endpoint<'app/create'> {
name = 'app/create' as const;
constructor(
@Inject(DI.appsRepository)
private appsRepository: AppsRepository,
@@ -42,7 +18,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private appEntityService: AppEntityService,
private idService: IdService,
) {
super(meta, paramDef, async (ps, me) => {
super(async (ps, me) => {
// Generate secret
const secret = secureRndstr(32, true);

View File

@@ -5,49 +5,24 @@ import { AppEntityService } from '@/core/entities/AppEntityService.js';
import { DI } from '@/di-symbols.js';
import { ApiError } from '../../error.js';
export const meta = {
tags: ['app'],
errors: {
noSuchApp: {
message: 'No such app.',
code: 'NO_SUCH_APP',
id: 'dce83913-2dc6-4093-8a7b-71dbb11718a3',
},
},
res: {
type: 'object',
optional: false, nullable: false,
ref: 'App',
},
} as const;
export const paramDef = {
type: 'object',
properties: {
appId: { type: 'string', format: 'misskey:id' },
},
required: ['appId'],
} as const;
// eslint-disable-next-line import/no-default-export
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> {
export default class extends Endpoint<'app/show'> {
name = 'app/show' as const;
constructor(
@Inject(DI.appsRepository)
private appsRepository: AppsRepository,
private appEntityService: AppEntityService,
) {
super(meta, paramDef, async (ps, user, token) => {
super(async (ps, user, token) => {
const isSecure = user != null && token == null;
// Lookup app
const ap = await this.appsRepository.findOneBy({ id: ps.appId });
if (ap == null) {
throw new ApiError(meta.errors.noSuchApp);
throw new ApiError(this.meta.errors.noSuchApp);
}
return await this.appEntityService.pack(ap, user, {