wip
This commit is contained in:
parent
42990fe6b6
commit
106062fa23
4 changed files with 110 additions and 109 deletions
|
@ -4,50 +4,21 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import { ApiError } from '../../error.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['flashs'],
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'write:flash',
|
||||
|
||||
errors: {
|
||||
noSuchFlash: {
|
||||
message: 'No such flash.',
|
||||
code: 'NO_SUCH_FLASH',
|
||||
id: 'de1623ef-bbb3-4289-a71e-14cfa83d9740',
|
||||
},
|
||||
|
||||
accessDenied: {
|
||||
message: 'Access denied.',
|
||||
code: 'ACCESS_DENIED',
|
||||
id: '1036ad7b-9f92-4fff-89c3-0e50dc941704',
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const paramDef = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
flashId: { type: 'string', format: 'misskey:id' },
|
||||
},
|
||||
required: ['flashId'],
|
||||
} 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<'flash/delete'> {
|
||||
name = 'flash/delete' as const;
|
||||
constructor(
|
||||
@Inject(DI.flashsRepository)
|
||||
private flashsRepository: FlashsRepository,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
super(async (ps, me) => {
|
||||
const flash = await this.flashsRepository.findOneBy({ id: ps.flashId });
|
||||
if (flash == null) {
|
||||
throw new ApiError(meta.errors.noSuchFlash);
|
||||
throw new ApiError(this.meta.errors.noSuchFlash);
|
||||
}
|
||||
if (flash.userId !== me.id) {
|
||||
throw new ApiError(meta.errors.accessDenied);
|
||||
throw new ApiError(this.meta.errors.accessDenied);
|
||||
}
|
||||
|
||||
await this.flashsRepository.delete(flash.id);
|
||||
|
|
|
@ -4,38 +4,17 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
|
|||
import { FlashEntityService } from '@/core/entities/FlashEntityService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['flash'],
|
||||
|
||||
requireCredential: false,
|
||||
|
||||
res: {
|
||||
type: 'array',
|
||||
optional: false, nullable: false,
|
||||
items: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
ref: 'Flash',
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const paramDef = {
|
||||
type: 'object',
|
||||
properties: {},
|
||||
required: [],
|
||||
} 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<'flash/featured'> {
|
||||
name = 'flash/featured' as const;
|
||||
constructor(
|
||||
@Inject(DI.flashsRepository)
|
||||
private flashsRepository: FlashsRepository,
|
||||
|
||||
private flashEntityService: FlashEntityService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
super(async (ps, me) => {
|
||||
const query = this.flashsRepository.createQueryBuilder('flash')
|
||||
.andWhere('flash.likedCount > 0')
|
||||
.orderBy('flash.likedCount', 'DESC');
|
||||
|
|
|
@ -5,47 +5,10 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import { ApiError } from '../../error.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['flash'],
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
prohibitMoved: true,
|
||||
|
||||
kind: 'write:flash-likes',
|
||||
|
||||
errors: {
|
||||
noSuchFlash: {
|
||||
message: 'No such flash.',
|
||||
code: 'NO_SUCH_FLASH',
|
||||
id: 'c07c1491-9161-4c5c-9d75-01906f911f73',
|
||||
},
|
||||
|
||||
yourFlash: {
|
||||
message: 'You cannot like your flash.',
|
||||
code: 'YOUR_FLASH',
|
||||
id: '3fd8a0e7-5955-4ba9-85bb-bf3e0c30e13b',
|
||||
},
|
||||
|
||||
alreadyLiked: {
|
||||
message: 'The flash has already been liked.',
|
||||
code: 'ALREADY_LIKED',
|
||||
id: '010065cf-ad43-40df-8067-abff9f4686e3',
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const paramDef = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
flashId: { type: 'string', format: 'misskey:id' },
|
||||
},
|
||||
required: ['flashId'],
|
||||
} 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<'flash/like'> {
|
||||
name = 'flash/like' as const;
|
||||
constructor(
|
||||
@Inject(DI.flashsRepository)
|
||||
private flashsRepository: FlashsRepository,
|
||||
|
@ -55,14 +18,14 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
|
||||
private idService: IdService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
super(async (ps, me) => {
|
||||
const flash = await this.flashsRepository.findOneBy({ id: ps.flashId });
|
||||
if (flash == null) {
|
||||
throw new ApiError(meta.errors.noSuchFlash);
|
||||
throw new ApiError(this.meta.errors.noSuchFlash);
|
||||
}
|
||||
|
||||
if (flash.userId === me.id) {
|
||||
throw new ApiError(meta.errors.yourFlash);
|
||||
throw new ApiError(this.meta.errors.yourFlash);
|
||||
}
|
||||
|
||||
// if already liked
|
||||
|
@ -72,7 +35,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
});
|
||||
|
||||
if (exist != null) {
|
||||
throw new ApiError(meta.errors.alreadyLiked);
|
||||
throw new ApiError(this.meta.errors.alreadyLiked);
|
||||
}
|
||||
|
||||
// Create like
|
||||
|
|
|
@ -4416,18 +4416,18 @@ export const endpoints = {
|
|||
//#region flash
|
||||
'flash/create': {
|
||||
tags: ['flash'],
|
||||
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
|
||||
prohibitMoved: true,
|
||||
|
||||
|
||||
kind: 'write:flash',
|
||||
|
||||
|
||||
limit: {
|
||||
duration: ms('1hour'),
|
||||
max: 10,
|
||||
},
|
||||
|
||||
|
||||
errors: {
|
||||
},
|
||||
|
||||
|
@ -4438,9 +4438,11 @@ export const endpoints = {
|
|||
title: { type: 'string' },
|
||||
summary: { type: 'string' },
|
||||
script: { type: 'string' },
|
||||
permissions: { type: 'array', items: {
|
||||
type: 'string',
|
||||
} },
|
||||
permissions: {
|
||||
type: 'array', items: {
|
||||
type: 'string',
|
||||
}
|
||||
},
|
||||
},
|
||||
required: ['title', 'summary', 'script', 'permissions'],
|
||||
},
|
||||
|
@ -4449,6 +4451,92 @@ export const endpoints = {
|
|||
},
|
||||
}]
|
||||
},
|
||||
'flash/delete': {
|
||||
tags: ['flashs'],
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'write:flash',
|
||||
|
||||
errors: {
|
||||
noSuchFlash: {
|
||||
message: 'No such flash.',
|
||||
code: 'NO_SUCH_FLASH',
|
||||
id: 'de1623ef-bbb3-4289-a71e-14cfa83d9740',
|
||||
},
|
||||
|
||||
accessDenied: {
|
||||
message: 'Access denied.',
|
||||
code: 'ACCESS_DENIED',
|
||||
id: '1036ad7b-9f92-4fff-89c3-0e50dc941704',
|
||||
},
|
||||
},
|
||||
defines: [{
|
||||
req: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
flashId: { type: 'string', format: 'misskey:id' },
|
||||
},
|
||||
required: ['flashId'],
|
||||
},
|
||||
res: undefined,
|
||||
}],
|
||||
},
|
||||
'flash/featured': {
|
||||
tags: ['flash'],
|
||||
|
||||
requireCredential: false,
|
||||
|
||||
defines: [{
|
||||
req: undefined,
|
||||
res: {
|
||||
type: 'array',
|
||||
items: {
|
||||
$ref: 'https://misskey-hub.net/api/schemas/Flash',
|
||||
},
|
||||
},
|
||||
}],
|
||||
},
|
||||
'flash/like': {
|
||||
tags: ['flash'],
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
prohibitMoved: true,
|
||||
|
||||
kind: 'write:flash-likes',
|
||||
|
||||
errors: {
|
||||
noSuchFlash: {
|
||||
message: 'No such flash.',
|
||||
code: 'NO_SUCH_FLASH',
|
||||
id: 'c07c1491-9161-4c5c-9d75-01906f911f73',
|
||||
},
|
||||
|
||||
yourFlash: {
|
||||
message: 'You cannot like your flash.',
|
||||
code: 'YOUR_FLASH',
|
||||
id: '3fd8a0e7-5955-4ba9-85bb-bf3e0c30e13b',
|
||||
},
|
||||
|
||||
alreadyLiked: {
|
||||
message: 'The flash has already been liked.',
|
||||
code: 'ALREADY_LIKED',
|
||||
id: '010065cf-ad43-40df-8067-abff9f4686e3',
|
||||
},
|
||||
},
|
||||
|
||||
defines: [{
|
||||
req: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
flashId: { type: 'string', format: 'misskey:id' },
|
||||
},
|
||||
required: ['flashId'],
|
||||
},
|
||||
res: undefined,
|
||||
}]
|
||||
},
|
||||
//#endregion
|
||||
} as const satisfies { [x: string]: IEndpointMeta; };
|
||||
|
||||
|
|
Loading…
Reference in a new issue