mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-25 15:35: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 { FlashLikeEntityService } from '@/core/entities/FlashLikeEntityService.js';
|
||||||
import { DI } from '@/di-symbols.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
|
// eslint-disable-next-line import/no-default-export
|
||||||
@Injectable()
|
@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(
|
constructor(
|
||||||
@Inject(DI.flashLikesRepository)
|
@Inject(DI.flashLikesRepository)
|
||||||
private flashLikesRepository: FlashLikesRepository,
|
private flashLikesRepository: FlashLikesRepository,
|
||||||
|
@ -53,7 +16,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
private flashLikeEntityService: FlashLikeEntityService,
|
private flashLikeEntityService: FlashLikeEntityService,
|
||||||
private queryService: QueryService,
|
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)
|
const query = this.queryService.makePaginationQuery(this.flashLikesRepository.createQueryBuilder('like'), ps.sinceId, ps.untilId)
|
||||||
.andWhere('like.userId = :meId', { meId: me.id })
|
.andWhere('like.userId = :meId', { meId: me.id })
|
||||||
.leftJoinAndSelect('like.flash', 'flash');
|
.leftJoinAndSelect('like.flash', 'flash');
|
||||||
|
|
|
@ -5,37 +5,10 @@ import { QueryService } from '@/core/QueryService.js';
|
||||||
import { FlashEntityService } from '@/core/entities/FlashEntityService.js';
|
import { FlashEntityService } from '@/core/entities/FlashEntityService.js';
|
||||||
import { DI } from '@/di-symbols.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
|
// eslint-disable-next-line import/no-default-export
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
export default class extends Endpoint<'flash/my'> {
|
||||||
|
name = 'flash/my' as const;
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DI.flashsRepository)
|
@Inject(DI.flashsRepository)
|
||||||
private flashsRepository: FlashsRepository,
|
private flashsRepository: FlashsRepository,
|
||||||
|
@ -43,7 +16,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
private flashEntityService: FlashEntityService,
|
private flashEntityService: FlashEntityService,
|
||||||
private queryService: QueryService,
|
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)
|
const query = this.queryService.makePaginationQuery(this.flashsRepository.createQueryBuilder('flash'), ps.sinceId, ps.untilId)
|
||||||
.andWhere('flash.userId = :meId', { meId: me.id });
|
.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 { DI } from '@/di-symbols.js';
|
||||||
import { ApiError } from '../../error.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
|
// eslint-disable-next-line import/no-default-export
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
export default class extends Endpoint<'flash/show'> {
|
||||||
|
name = 'flash/show' as const;
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DI.usersRepository)
|
@Inject(DI.usersRepository)
|
||||||
private usersRepository: UsersRepository,
|
private usersRepository: UsersRepository,
|
||||||
|
@ -45,11 +18,11 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
|
|
||||||
private flashEntityService: FlashEntityService,
|
private flashEntityService: FlashEntityService,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(async (ps, me) => {
|
||||||
const flash = await this.flashsRepository.findOneBy({ id: ps.flashId });
|
const flash = await this.flashsRepository.findOneBy({ id: ps.flashId });
|
||||||
|
|
||||||
if (flash == null) {
|
if (flash == null) {
|
||||||
throw new ApiError(meta.errors.noSuchFlash);
|
throw new ApiError(this.meta.errors.noSuchFlash);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.flashEntityService.pack(flash, me);
|
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 { DI } from '@/di-symbols.js';
|
||||||
import { ApiError } from '../../error.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
|
// eslint-disable-next-line import/no-default-export
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
export default class extends Endpoint<'flash/unlike'> {
|
||||||
|
name = 'flash/unlike' as const;
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DI.flashsRepository)
|
@Inject(DI.flashsRepository)
|
||||||
private flashsRepository: FlashsRepository,
|
private flashsRepository: FlashsRepository,
|
||||||
|
@ -46,10 +15,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
@Inject(DI.flashLikesRepository)
|
@Inject(DI.flashLikesRepository)
|
||||||
private flashLikesRepository: FlashLikesRepository,
|
private flashLikesRepository: FlashLikesRepository,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(async (ps, me) => {
|
||||||
const flash = await this.flashsRepository.findOneBy({ id: ps.flashId });
|
const flash = await this.flashsRepository.findOneBy({ id: ps.flashId });
|
||||||
if (flash == null) {
|
if (flash == null) {
|
||||||
throw new ApiError(meta.errors.noSuchFlash);
|
throw new ApiError(this.meta.errors.noSuchFlash);
|
||||||
}
|
}
|
||||||
|
|
||||||
const exist = await this.flashLikesRepository.findOneBy({
|
const exist = await this.flashLikesRepository.findOneBy({
|
||||||
|
@ -58,7 +27,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist == null) {
|
if (exist == null) {
|
||||||
throw new ApiError(meta.errors.notLiked);
|
throw new ApiError(this.meta.errors.notLiked);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete like
|
// Delete like
|
||||||
|
|
|
@ -5,52 +5,10 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import { ApiError } from '../../error.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
|
// eslint-disable-next-line import/no-default-export
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
export default class extends Endpoint<'flash/update'> {
|
||||||
|
name = 'flash/update' as const;
|
||||||
constructor(
|
constructor(
|
||||||
@Inject(DI.flashsRepository)
|
@Inject(DI.flashsRepository)
|
||||||
private flashsRepository: FlashsRepository,
|
private flashsRepository: FlashsRepository,
|
||||||
|
@ -58,13 +16,13 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
|
||||||
@Inject(DI.driveFilesRepository)
|
@Inject(DI.driveFilesRepository)
|
||||||
private driveFilesRepository: DriveFilesRepository,
|
private driveFilesRepository: DriveFilesRepository,
|
||||||
) {
|
) {
|
||||||
super(meta, paramDef, async (ps, me) => {
|
super(async (ps, me) => {
|
||||||
const flash = await this.flashsRepository.findOneBy({ id: ps.flashId });
|
const flash = await this.flashsRepository.findOneBy({ id: ps.flashId });
|
||||||
if (flash == null) {
|
if (flash == null) {
|
||||||
throw new ApiError(meta.errors.noSuchFlash);
|
throw new ApiError(this.meta.errors.noSuchFlash);
|
||||||
}
|
}
|
||||||
if (flash.userId !== me.id) {
|
if (flash.userId !== me.id) {
|
||||||
throw new ApiError(meta.errors.accessDenied);
|
throw new ApiError(this.meta.errors.accessDenied);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.flashsRepository.update(flash.id, {
|
await this.flashsRepository.update(flash.id, {
|
||||||
|
|
|
@ -4537,6 +4537,170 @@ export const endpoints = {
|
||||||
res: undefined,
|
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
|
//#endregion
|
||||||
} as const satisfies { [x: string]: IEndpointMeta; };
|
} as const satisfies { [x: string]: IEndpointMeta; };
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue