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, {

View File

@ -2145,20 +2145,20 @@ export const endpoints = {
},
'antennas/update': {
tags: ['antennas'],
requireCredential: true,
prohibitMoved: true,
kind: 'write:account',
errors: {
noSuchAntenna: {
message: 'No such antenna.',
code: 'NO_SUCH_ANTENNA',
id: '10c673ac-8852-48eb-aa1f-f5b67f069290',
},
noSuchUserList: {
message: 'No such user list.',
code: 'NO_SUCH_USER_LIST',
@ -2179,19 +2179,25 @@ export const endpoints = {
{ type: 'null' },
],
},
keywords: { type: 'array', items: {
keywords: {
type: 'array', items: {
type: 'array', items: {
type: 'string',
},
}
},
excludeKeywords: {
type: 'array', items: {
type: 'array', items: {
type: 'string',
},
}
},
users: {
type: 'array', items: {
type: 'string',
},
} },
excludeKeywords: { type: 'array', items: {
type: 'array', items: {
type: 'string',
},
} },
users: { type: 'array', items: {
type: 'string',
} },
}
},
caseSensitive: { type: 'boolean' },
withReplies: { type: 'boolean' },
withFile: { type: 'boolean' },
@ -2209,14 +2215,14 @@ export const endpoints = {
//#region ap
'ap/get': {
tags: ['federation'],
requireCredential: true,
limit: {
duration: ms('1hour'),
max: 30,
},
defines: [{
req: {
type: 'object',
@ -2232,14 +2238,14 @@ export const endpoints = {
},
'ap/show': {
tags: ['federation'],
requireCredential: true,
limit: {
duration: ms('1hour'),
max: 30,
},
errors: {
noSuchObject: {
message: 'No such object.',
@ -2247,7 +2253,7 @@ export const endpoints = {
id: 'dc94d745-1262-4e63-a17d-fecaa57efc82',
},
},
defines: [{
req: {
type: 'object',
@ -2281,6 +2287,60 @@ export const endpoints = {
],
},
}],
},
//#endregion
//#region app
'app/create': {
tags: ['app'],
requireCredential: false,
defines: [{
req: {
type: 'object',
properties: {
name: { type: 'string' },
description: { type: 'string' },
permission: {
type: 'array',
uniqueItems: true,
items: {
type: 'string',
},
},
callbackUrl: { type: ['string', 'null'] },
} as const satisfies Record<string, JSONSchema7>,
required: ['name', 'description', 'permission'],
},
res: {
$ref: 'https://misskey-hub.net/api/schemas/App',
},
}],
},
'app/show': {
tags: ['app'],
errors: {
noSuchApp: {
message: 'No such app.',
code: 'NO_SUCH_APP',
id: 'dce83913-2dc6-4093-8a7b-71dbb11718a3',
},
},
defines: [{
req: {
type: 'object',
properties: {
appId: { type: 'string', format: 'misskey:id' },
},
required: ['appId'],
},
res: {
$ref: 'https://misskey-hub.net/api/schemas/App',
},
}],
}
//#endregion
} as const satisfies { [x: string]: IEndpointMeta; };