2023-07-27 14:31:52 +09:00
|
|
|
/*
|
2024-02-13 15:59:27 +00:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 14:31:52 +09:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
2022-09-24 07:12:11 +09:00
|
|
|
import { IsNull, Not } from 'typeorm';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
2023-09-15 14:28:29 +09:00
|
|
|
import type { AccessTokensRepository } from '@/models/_.js';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { AppEntityService } from '@/core/entities/AppEntityService.js';
|
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2017-02-09 00:11:16 +09:00
|
|
|
|
2018-07-17 04:36:44 +09:00
|
|
|
export const meta = {
|
2022-01-18 22:27:10 +09:00
|
|
|
requireCredential: true,
|
2018-07-17 04:36:44 +09:00
|
|
|
|
2018-11-02 12:49:08 +09:00
|
|
|
secure: true,
|
2023-12-21 16:57:05 +09:00
|
|
|
|
|
|
|
|
res: {
|
|
|
|
|
type: 'array',
|
|
|
|
|
items: {
|
|
|
|
|
type: 'object',
|
|
|
|
|
properties: {
|
|
|
|
|
id: {
|
|
|
|
|
type: 'string',
|
|
|
|
|
format: 'misskey:id',
|
2024-02-16 14:27:33 +09:00
|
|
|
optional: false,
|
2023-12-21 16:57:05 +09:00
|
|
|
},
|
|
|
|
|
name: {
|
|
|
|
|
type: 'string',
|
2024-02-16 14:27:33 +09:00
|
|
|
optional: false,
|
2023-12-21 16:57:05 +09:00
|
|
|
},
|
|
|
|
|
callbackUrl: {
|
|
|
|
|
type: 'string',
|
2024-02-16 14:27:33 +09:00
|
|
|
optional: false, nullable: true,
|
2023-12-21 16:57:05 +09:00
|
|
|
},
|
|
|
|
|
permission: {
|
|
|
|
|
type: 'array',
|
2024-02-16 14:27:33 +09:00
|
|
|
optional: false,
|
2023-12-21 16:57:05 +09:00
|
|
|
uniqueItems: true,
|
|
|
|
|
items: {
|
2024-02-16 14:27:33 +09:00
|
|
|
type: 'string',
|
2023-12-21 16:57:05 +09:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
isAuthorized: {
|
|
|
|
|
type: 'boolean',
|
2024-02-16 14:27:33 +09:00
|
|
|
optional: true,
|
2023-12-21 16:57:05 +09:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-02-19 14:05:32 +09:00
|
|
|
} as const;
|
2018-11-02 12:49:08 +09:00
|
|
|
|
2022-02-20 13:15:40 +09:00
|
|
|
export const paramDef = {
|
2022-02-19 14:05:32 +09:00
|
|
|
type: 'object',
|
|
|
|
|
properties: {
|
|
|
|
|
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
|
|
|
|
offset: { type: 'integer', default: 0 },
|
2022-09-18 03:27:08 +09:00
|
|
|
sort: { type: 'string', enum: ['desc', 'asc'], default: 'desc' },
|
2021-12-09 23:58:30 +09:00
|
|
|
},
|
2022-02-19 14:05:32 +09:00
|
|
|
required: [],
|
2022-01-18 22:27:10 +09:00
|
|
|
} as const;
|
2018-11-02 12:49:08 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
@Injectable()
|
2023-08-17 21:20:58 +09:00
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
|
2022-09-18 03:27:08 +09:00
|
|
|
constructor(
|
|
|
|
|
@Inject(DI.accessTokensRepository)
|
|
|
|
|
private accessTokensRepository: AccessTokensRepository,
|
2017-02-09 00:11:16 +09:00
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
private appEntityService: AppEntityService,
|
|
|
|
|
) {
|
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
|
// Get tokens
|
|
|
|
|
const tokens = await this.accessTokensRepository.find({
|
|
|
|
|
where: {
|
|
|
|
|
userId: me.id,
|
2022-09-24 07:12:11 +09:00
|
|
|
appId: Not(IsNull()),
|
2022-09-18 03:27:08 +09:00
|
|
|
},
|
|
|
|
|
take: ps.limit,
|
|
|
|
|
skip: ps.offset,
|
|
|
|
|
order: {
|
|
|
|
|
id: ps.sort === 'asc' ? 1 : -1,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2022-09-24 07:12:11 +09:00
|
|
|
return await Promise.all(tokens.map(token => this.appEntityService.pack(token.appId!, me, {
|
2022-09-18 03:27:08 +09:00
|
|
|
detail: true,
|
|
|
|
|
})));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|