mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-25 07:25:12 +00:00
flash
This commit is contained in:
parent
106062fa23
commit
ae3ce71bb2
6 changed files with 184 additions and 184 deletions
|
@ -5,47 +5,10 @@ import { QueryService } from '@/core/QueryService.js';
|
|||
import { FlashLikeEntityService } from '@/core/entities/FlashLikeEntityService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['account', 'flash'],
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'read:flash-likes',
|
||||
|
||||
res: {
|
||||
type: 'array',
|
||||
optional: false, nullable: false,
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
optional: false, nullable: false,
|
||||
format: 'id',
|
||||
},
|
||||
flash: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
ref: 'Flash',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const paramDef = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
||||
sinceId: { type: 'string', format: 'misskey:id' },
|
||||
untilId: { type: 'string', format: 'misskey:id' },
|
||||
},
|
||||
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/my-likes'> {
|
||||
name = 'flash/my-likes' as const;
|
||||
constructor(
|
||||
@Inject(DI.flashLikesRepository)
|
||||
private flashLikesRepository: FlashLikesRepository,
|
||||
|
@ -53,7 +16,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
private flashLikeEntityService: FlashLikeEntityService,
|
||||
private queryService: QueryService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
super(async (ps, me) => {
|
||||
const query = this.queryService.makePaginationQuery(this.flashLikesRepository.createQueryBuilder('like'), ps.sinceId, ps.untilId)
|
||||
.andWhere('like.userId = :meId', { meId: me.id })
|
||||
.leftJoinAndSelect('like.flash', 'flash');
|
||||
|
|
|
@ -5,37 +5,10 @@ import { QueryService } from '@/core/QueryService.js';
|
|||
import { FlashEntityService } from '@/core/entities/FlashEntityService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['account', 'flash'],
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'read:flash',
|
||||
|
||||
res: {
|
||||
type: 'array',
|
||||
optional: false, nullable: false,
|
||||
items: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
ref: 'Flash',
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const paramDef = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
||||
sinceId: { type: 'string', format: 'misskey:id' },
|
||||
untilId: { type: 'string', format: 'misskey:id' },
|
||||
},
|
||||
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/my'> {
|
||||
name = 'flash/my' as const;
|
||||
constructor(
|
||||
@Inject(DI.flashsRepository)
|
||||
private flashsRepository: FlashsRepository,
|
||||
|
@ -43,7 +16,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
private flashEntityService: FlashEntityService,
|
||||
private queryService: QueryService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, me) => {
|
||||
super(async (ps, me) => {
|
||||
const query = this.queryService.makePaginationQuery(this.flashsRepository.createQueryBuilder('flash'), ps.sinceId, ps.untilId)
|
||||
.andWhere('flash.userId = :meId', { meId: me.id });
|
||||
|
||||
|
|
|
@ -5,37 +5,10 @@ import { FlashEntityService } from '@/core/entities/FlashEntityService.js';
|
|||
import { DI } from '@/di-symbols.js';
|
||||
import { ApiError } from '../../error.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['flashs'],
|
||||
|
||||
requireCredential: false,
|
||||
|
||||
res: {
|
||||
type: 'object',
|
||||
optional: false, nullable: false,
|
||||
ref: 'Flash',
|
||||
},
|
||||
|
||||
errors: {
|
||||
noSuchFlash: {
|
||||
message: 'No such flash.',
|
||||
code: 'NO_SUCH_FLASH',
|
||||
id: 'f0d34a1a-d29a-401d-90ba-1982122b5630',
|
||||
},
|
||||
},
|
||||
} 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/show'> {
|
||||
name = 'flash/show' as const;
|
||||
constructor(
|
||||
@Inject(DI.usersRepository)
|
||||
private usersRepository: UsersRepository,
|
||||
|
@ -45,11 +18,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
|
||||
private flashEntityService: FlashEntityService,
|
||||
) {
|
||||
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);
|
||||
}
|
||||
|
||||
return await this.flashEntityService.pack(flash, me);
|
||||
|
|
|
@ -4,41 +4,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: 'afe8424a-a69e-432d-a5f2-2f0740c62410',
|
||||
},
|
||||
|
||||
notLiked: {
|
||||
message: 'You have not liked that flash.',
|
||||
code: 'NOT_LIKED',
|
||||
id: '755f25a7-9871-4f65-9f34-51eaad9ae0ac',
|
||||
},
|
||||
},
|
||||
} 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/unlike'> {
|
||||
name = 'flash/unlike' as const;
|
||||
constructor(
|
||||
@Inject(DI.flashsRepository)
|
||||
private flashsRepository: FlashsRepository,
|
||||
|
@ -46,10 +15,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
@Inject(DI.flashLikesRepository)
|
||||
private flashLikesRepository: FlashLikesRepository,
|
||||
) {
|
||||
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);
|
||||
}
|
||||
|
||||
const exist = await this.flashLikesRepository.findOneBy({
|
||||
|
@ -58,7 +27,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
});
|
||||
|
||||
if (exist == null) {
|
||||
throw new ApiError(meta.errors.notLiked);
|
||||
throw new ApiError(this.meta.errors.notLiked);
|
||||
}
|
||||
|
||||
// Delete like
|
||||
|
|
|
@ -5,52 +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',
|
||||
|
||||
limit: {
|
||||
duration: ms('1hour'),
|
||||
max: 300,
|
||||
},
|
||||
|
||||
errors: {
|
||||
noSuchFlash: {
|
||||
message: 'No such flash.',
|
||||
code: 'NO_SUCH_FLASH',
|
||||
id: '611e13d2-309e-419a-a5e4-e0422da39b02',
|
||||
},
|
||||
|
||||
accessDenied: {
|
||||
message: 'Access denied.',
|
||||
code: 'ACCESS_DENIED',
|
||||
id: '08e60c88-5948-478e-a132-02ec701d67b2',
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
export const paramDef = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
flashId: { type: 'string', format: 'misskey:id' },
|
||||
title: { type: 'string' },
|
||||
summary: { type: 'string' },
|
||||
script: { type: 'string' },
|
||||
permissions: { type: 'array', items: {
|
||||
type: 'string',
|
||||
} },
|
||||
},
|
||||
required: ['flashId', 'title', 'summary', 'script', 'permissions'],
|
||||
} 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/update'> {
|
||||
name = 'flash/update' as const;
|
||||
constructor(
|
||||
@Inject(DI.flashsRepository)
|
||||
private flashsRepository: FlashsRepository,
|
||||
|
@ -58,13 +16,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|||
@Inject(DI.driveFilesRepository)
|
||||
private driveFilesRepository: DriveFilesRepository,
|
||||
) {
|
||||
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.update(flash.id, {
|
||||
|
|
|
@ -4537,6 +4537,170 @@ export const endpoints = {
|
|||
res: undefined,
|
||||
}]
|
||||
},
|
||||
'flash/my-likes': {
|
||||
tags: ['account', 'flash'],
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'read:flash-likes',
|
||||
|
||||
defines: [{
|
||||
req: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
||||
sinceId: { type: 'string', format: 'misskey:id' },
|
||||
untilId: { type: 'string', format: 'misskey:id' },
|
||||
},
|
||||
required: [],
|
||||
},
|
||||
res: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
$ref: 'https://misskey-hub.net/api/schemas/Id',
|
||||
},
|
||||
flash: {
|
||||
$ref: 'https://misskey-hub.net/api/schemas/Flash',
|
||||
},
|
||||
},
|
||||
required: ['id', 'flash'],
|
||||
},
|
||||
},
|
||||
}],
|
||||
},
|
||||
'flash/my': {
|
||||
tags: ['account', 'flash'],
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'read:flash',
|
||||
|
||||
defines: [{
|
||||
req: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
||||
sinceId: { type: 'string', format: 'misskey:id' },
|
||||
untilId: { type: 'string', format: 'misskey:id' },
|
||||
},
|
||||
required: [],
|
||||
},
|
||||
res: {
|
||||
type: 'array',
|
||||
items: {
|
||||
$ref: 'https://misskey-hub.net/api/schemas/Flash',
|
||||
},
|
||||
},
|
||||
}],
|
||||
},
|
||||
'flash/show': {
|
||||
tags: ['flashs'],
|
||||
|
||||
requireCredential: false,
|
||||
|
||||
errors: {
|
||||
noSuchFlash: {
|
||||
message: 'No such flash.',
|
||||
code: 'NO_SUCH_FLASH',
|
||||
id: 'f0d34a1a-d29a-401d-90ba-1982122b5630',
|
||||
},
|
||||
},
|
||||
|
||||
defines: [{
|
||||
req: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
flashId: { type: 'string', format: 'misskey:id' },
|
||||
},
|
||||
required: ['flashId'],
|
||||
},
|
||||
res: {
|
||||
$ref: 'https://misskey-hub.net/api/schemas/Flash',
|
||||
},
|
||||
}]
|
||||
},
|
||||
'flash/unlike': {
|
||||
tags: ['flash'],
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
prohibitMoved: true,
|
||||
|
||||
kind: 'write:flash-likes',
|
||||
|
||||
errors: {
|
||||
noSuchFlash: {
|
||||
message: 'No such flash.',
|
||||
code: 'NO_SUCH_FLASH',
|
||||
id: 'afe8424a-a69e-432d-a5f2-2f0740c62410',
|
||||
},
|
||||
|
||||
notLiked: {
|
||||
message: 'You have not liked that flash.',
|
||||
code: 'NOT_LIKED',
|
||||
id: '755f25a7-9871-4f65-9f34-51eaad9ae0ac',
|
||||
},
|
||||
},
|
||||
|
||||
defines: [{
|
||||
req: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
flashId: { type: 'string', format: 'misskey:id' },
|
||||
},
|
||||
required: ['flashId'],
|
||||
},
|
||||
res: undefined,
|
||||
}]
|
||||
},
|
||||
'flash/update': {
|
||||
tags: ['flash'],
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
prohibitMoved: true,
|
||||
|
||||
kind: 'write:flash',
|
||||
|
||||
limit: {
|
||||
duration: ms('1hour'),
|
||||
max: 300,
|
||||
},
|
||||
|
||||
errors: {
|
||||
noSuchFlash: {
|
||||
message: 'No such flash.',
|
||||
code: 'NO_SUCH_FLASH',
|
||||
id: '611e13d2-309e-419a-a5e4-e0422da39b02',
|
||||
},
|
||||
|
||||
accessDenied: {
|
||||
message: 'Access denied.',
|
||||
code: 'ACCESS_DENIED',
|
||||
id: '08e60c88-5948-478e-a132-02ec701d67b2',
|
||||
},
|
||||
},
|
||||
|
||||
defines: [{
|
||||
req: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
flashId: { type: 'string', format: 'misskey:id' },
|
||||
title: { type: 'string' },
|
||||
summary: { type: 'string' },
|
||||
script: { type: 'string' },
|
||||
permissions: { type: 'array', items: {
|
||||
type: 'string',
|
||||
} },
|
||||
},
|
||||
required: ['flashId', 'title', 'summary', 'script', 'permissions'],
|
||||
},
|
||||
res: undefined,
|
||||
}]
|
||||
},
|
||||
//#endregion
|
||||
} as const satisfies { [x: string]: IEndpointMeta; };
|
||||
|
||||
|
|
Loading…
Reference in a new issue