This commit is contained in:
tamaina 2023-06-05 07:36:48 +00:00
parent b818f2308d
commit b532ad8cd4
7 changed files with 209 additions and 214 deletions

View file

@ -4,41 +4,17 @@ import type { ClipFavoritesRepository } from '@/models/index.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import { ClipEntityService } from '@/core/entities/ClipEntityService.js'; import { ClipEntityService } from '@/core/entities/ClipEntityService.js';
export const meta = {
tags: ['account', 'clip'],
requireCredential: true,
kind: 'read:clip-favorite',
res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
ref: 'Clip',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
},
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<'clips/my-favorites'> {
name = 'clips/my-favorites' as const;
constructor( constructor(
@Inject(DI.clipFavoritesRepository) @Inject(DI.clipFavoritesRepository)
private clipFavoritesRepository: ClipFavoritesRepository, private clipFavoritesRepository: ClipFavoritesRepository,
private clipEntityService: ClipEntityService, private clipEntityService: ClipEntityService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
const query = this.clipFavoritesRepository.createQueryBuilder('favorite') const query = this.clipFavoritesRepository.createQueryBuilder('favorite')
.andWhere('favorite.userId = :meId', { meId: me.id }) .andWhere('favorite.userId = :meId', { meId: me.id })
.leftJoinAndSelect('favorite.clip', 'clip'); .leftJoinAndSelect('favorite.clip', 'clip');

View file

@ -6,46 +6,10 @@ import { NoteEntityService } from '@/core/entities/NoteEntityService.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: ['account', 'notes', 'clips'],
requireCredential: false,
kind: 'read:account',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: '1d7645e6-2b6d-4635-b0fe-fe22b0e72e00',
},
},
res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
ref: 'Note',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
clipId: { type: 'string', format: 'misskey:id' },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
},
required: ['clipId'],
} 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<'clips/notes'> {
name = 'clips/notes' as const;
constructor( constructor(
@Inject(DI.clipsRepository) @Inject(DI.clipsRepository)
private clipsRepository: ClipsRepository, private clipsRepository: ClipsRepository,
@ -59,17 +23,17 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private noteEntityService: NoteEntityService, private noteEntityService: NoteEntityService,
private queryService: QueryService, private queryService: QueryService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
const clip = await this.clipsRepository.findOneBy({ const clip = await this.clipsRepository.findOneBy({
id: ps.clipId, id: ps.clipId,
}); });
if (clip == null) { if (clip == null) {
throw new ApiError(meta.errors.noSuchClip); throw new ApiError(this.meta.errors.noSuchClip);
} }
if (!clip.isPublic && (me == null || (clip.userId !== me.id))) { if (!clip.isPublic && (me == null || (clip.userId !== me.id))) {
throw new ApiError(meta.errors.noSuchClip); throw new ApiError(this.meta.errors.noSuchClip);
} }
const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId) const query = this.queryService.makePaginationQuery(this.notesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)

View file

@ -5,42 +5,10 @@ import { DI } from '@/di-symbols.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
import { GetterService } from '@/server/api/GetterService.js'; import { GetterService } from '@/server/api/GetterService.js';
export const meta = {
tags: ['account', 'notes', 'clips'],
requireCredential: true,
prohibitMoved: true,
kind: 'write:account',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: 'b80525c6-97f7-49d7-a42d-ebccd49cfd52',
},
noSuchNote: {
message: 'No such note.',
code: 'NO_SUCH_NOTE',
id: 'aff017de-190e-434b-893e-33a9ff5049d8',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
clipId: { type: 'string', format: 'misskey:id' },
noteId: { type: 'string', format: 'misskey:id' },
},
required: ['clipId', 'noteId'],
} 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<'clips/remove-note'> {
name = 'clips/remove-note' as const;
constructor( constructor(
@Inject(DI.clipsRepository) @Inject(DI.clipsRepository)
private clipsRepository: ClipsRepository, private clipsRepository: ClipsRepository,
@ -50,18 +18,18 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private getterService: GetterService, private getterService: GetterService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
const clip = await this.clipsRepository.findOneBy({ const clip = await this.clipsRepository.findOneBy({
id: ps.clipId, id: ps.clipId,
userId: me.id, userId: me.id,
}); });
if (clip == null) { if (clip == null) {
throw new ApiError(meta.errors.noSuchClip); throw new ApiError(this.meta.errors.noSuchClip);
} }
const note = await this.getterService.getNote(ps.noteId).catch(err => { const note = await this.getterService.getNote(ps.noteId).catch(err => {
if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(meta.errors.noSuchNote); if (err.id === '9725d0ce-ba28-4dde-95a7-2cbb2c15de24') throw new ApiError(this.meta.errors.noSuchNote);
throw err; throw err;
}); });

View file

@ -5,57 +5,28 @@ import { ClipEntityService } from '@/core/entities/ClipEntityService.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: ['clips', 'account'],
requireCredential: false,
kind: 'read:account',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: 'c3c5fe33-d62c-44d2-9ea5-d997703f5c20',
},
},
res: {
type: 'object',
optional: false, nullable: false,
ref: 'Clip',
},
} as const;
export const paramDef = {
type: 'object',
properties: {
clipId: { type: 'string', format: 'misskey:id' },
},
required: ['clipId'],
} 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<'clips/show'> {
name = 'clips/show' as const;
constructor( constructor(
@Inject(DI.clipsRepository) @Inject(DI.clipsRepository)
private clipsRepository: ClipsRepository, private clipsRepository: ClipsRepository,
private clipEntityService: ClipEntityService, private clipEntityService: ClipEntityService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
// Fetch the clip // Fetch the clip
const clip = await this.clipsRepository.findOneBy({ const clip = await this.clipsRepository.findOneBy({
id: ps.clipId, id: ps.clipId,
}); });
if (clip == null) { if (clip == null) {
throw new ApiError(meta.errors.noSuchClip); throw new ApiError(this.meta.errors.noSuchClip);
} }
if (!clip.isPublic && (me == null || (clip.userId !== me.id))) { if (!clip.isPublic && (me == null || (clip.userId !== me.id))) {
throw new ApiError(meta.errors.noSuchClip); throw new ApiError(this.meta.errors.noSuchClip);
} }
return await this.clipEntityService.pack(clip, me); return await this.clipEntityService.pack(clip, me);

View file

@ -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: ['clip'],
requireCredential: true,
prohibitMoved: true,
kind: 'write:clip-favorite',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: '2603966e-b865-426c-94a7-af4a01241dc1',
},
notFavorited: {
message: 'You have not favorited the clip.',
code: 'NOT_FAVORITED',
id: '90c3a9e8-b321-4dae-bf57-2bf79bbcc187',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
clipId: { type: 'string', format: 'misskey:id' },
},
required: ['clipId'],
} 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<'clips/unfavorite'> {
name = 'clips/unfavorite' as const;
constructor( constructor(
@Inject(DI.clipsRepository) @Inject(DI.clipsRepository)
private clipsRepository: ClipsRepository, private clipsRepository: ClipsRepository,
@ -46,10 +15,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
@Inject(DI.clipFavoritesRepository) @Inject(DI.clipFavoritesRepository)
private clipFavoritesRepository: ClipFavoritesRepository, private clipFavoritesRepository: ClipFavoritesRepository,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
const clip = await this.clipsRepository.findOneBy({ id: ps.clipId }); const clip = await this.clipsRepository.findOneBy({ id: ps.clipId });
if (clip == null) { if (clip == null) {
throw new ApiError(meta.errors.noSuchClip); throw new ApiError(this.meta.errors.noSuchClip);
} }
const exist = await this.clipFavoritesRepository.findOneBy({ const exist = await this.clipFavoritesRepository.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.notFavorited); throw new ApiError(this.meta.errors.notFavorited);
} }
await this.clipFavoritesRepository.delete(exist.id); await this.clipFavoritesRepository.delete(exist.id);

View file

@ -5,51 +5,17 @@ import { ClipEntityService } from '@/core/entities/ClipEntityService.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: ['clips'],
requireCredential: true,
prohibitMoved: true,
kind: 'write:account',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: 'b4d92d70-b216-46fa-9a3f-a8c811699257',
},
},
res: {
type: 'object',
optional: false, nullable: false,
ref: 'Clip',
},
} as const;
export const paramDef = {
type: 'object',
properties: {
clipId: { type: 'string', format: 'misskey:id' },
name: { type: 'string', minLength: 1, maxLength: 100 },
isPublic: { type: 'boolean' },
description: { type: 'string', nullable: true, minLength: 1, maxLength: 2048 },
},
required: ['clipId', 'name'],
} 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<'clips/update'> {
name = 'clips/update' as const;
constructor( constructor(
@Inject(DI.clipsRepository) @Inject(DI.clipsRepository)
private clipsRepository: ClipsRepository, private clipsRepository: ClipsRepository,
private clipEntityService: ClipEntityService, private clipEntityService: ClipEntityService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
// Fetch the clip // Fetch the clip
const clip = await this.clipsRepository.findOneBy({ const clip = await this.clipsRepository.findOneBy({
id: ps.clipId, id: ps.clipId,
@ -57,7 +23,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
}); });
if (clip == null) { if (clip == null) {
throw new ApiError(meta.errors.noSuchClip); throw new ApiError(this.meta.errors.noSuchClip);
} }
await this.clipsRepository.update(clip.id, { await this.clipsRepository.update(clip.id, {

View file

@ -3385,7 +3385,188 @@ export const endpoints = {
}, },
} }
}], }],
} },
'clips/my-favorites': {
tags: ['account', 'clip'],
requireCredential: true,
kind: 'read:clip-favorite',
defines: [{
req: undefined,
res: {
type: 'array',
items: {
$ref: 'https://misskey-hub.net/api/schemas/Clip',
},
},
}],
},
'clips/notes': {
tags: ['account', 'notes', 'clips'],
requireCredential: false,
kind: 'read:account',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: '1d7645e6-2b6d-4635-b0fe-fe22b0e72e00',
},
},
defines: [{
req: {
type: 'object',
properties: {
clipId: { type: 'string', format: 'misskey:id' },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
},
required: ['clipId'],
},
res: {
type: 'array',
items: {
$ref: 'https://misskey-hub.net/api/schemas/Note',
},
},
}],
},
'clips/remove-note': {
tags: ['account', 'notes', 'clips'],
requireCredential: true,
prohibitMoved: true,
kind: 'write:account',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: 'b80525c6-97f7-49d7-a42d-ebccd49cfd52',
},
noSuchNote: {
message: 'No such note.',
code: 'NO_SUCH_NOTE',
id: 'aff017de-190e-434b-893e-33a9ff5049d8',
},
},
defines: [{
req: {
type: 'object',
properties: {
clipId: { type: 'string', format: 'misskey:id' },
noteId: { type: 'string', format: 'misskey:id' },
},
required: ['clipId', 'noteId'],
},
res: undefined,
}],
},
'clips/show': {
tags: ['clips', 'account'],
requireCredential: false,
kind: 'read:account',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: 'c3c5fe33-d62c-44d2-9ea5-d997703f5c20',
},
},
defines: [{
req: {
type: 'object',
properties: {
clipId: { type: 'string', format: 'misskey:id' },
},
required: ['clipId'],
},
res: {
$ref: 'https://misskey-hub.net/api/schemas/Clip',
},
}],
},
'clips/unfavorite': {
tags: ['clip'],
requireCredential: true,
prohibitMoved: true,
kind: 'write:clip-favorite',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: '2603966e-b865-426c-94a7-af4a01241dc1',
},
notFavorited: {
message: 'You have not favorited the clip.',
code: 'NOT_FAVORITED',
id: '90c3a9e8-b321-4dae-bf57-2bf79bbcc187',
},
},
defines: [{
req: {
type: 'object',
properties: {
clipId: { type: 'string', format: 'misskey:id' },
},
required: ['clipId'],
},
res: undefined,
}]
},
'clips/update': {
tags: ['clips'],
requireCredential: true,
prohibitMoved: true,
kind: 'write:account',
errors: {
noSuchClip: {
message: 'No such clip.',
code: 'NO_SUCH_CLIP',
id: 'b4d92d70-b216-46fa-9a3f-a8c811699257',
},
},
defines: [{
req: {
type: 'object',
properties: {
clipId: { type: 'string', format: 'misskey:id' },
name: { type: 'string', minLength: 1, maxLength: 100 },
isPublic: { type: 'boolean' },
description: { type: 'string', nullable: true, minLength: 1, maxLength: 2048 },
},
required: ['clipId', 'name'],
},
res: {
$ref: 'https://misskey-hub.net/api/schemas/Clip',
},
}]
},
//#endregion //#endregion
} as const satisfies { [x: string]: IEndpointMeta; }; } as const satisfies { [x: string]: IEndpointMeta; };