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
|
|
|
|
*/
|
|
|
|
|
2023-12-31 19:20:52 +01:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
2022-09-18 03:27:08 +09:00
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
|
2023-12-31 19:20:52 +01:00
|
|
|
import { DI } from '@/di-symbols.js';
|
|
|
|
import type { NotesRepository } from '@/models/_.js';
|
2023-07-19 11:27:50 +09:00
|
|
|
import { ApiError } from '../../error.js';
|
2018-10-22 05:16:27 +09:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 11:20:58 +09:00
|
|
|
tags: ['notes'],
|
|
|
|
|
2022-01-18 22:27:10 +09:00
|
|
|
requireCredential: false,
|
2018-10-22 05:16:27 +09:00
|
|
|
|
2019-02-23 11:20:58 +09:00
|
|
|
res: {
|
2022-01-18 22:27:10 +09:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2019-04-23 22:35:26 +09:00
|
|
|
ref: 'Note',
|
2019-02-23 11:20:58 +09:00
|
|
|
},
|
|
|
|
|
2019-02-22 11:46:58 +09:00
|
|
|
errors: {
|
|
|
|
noSuchNote: {
|
|
|
|
message: 'No such note.',
|
|
|
|
code: 'NO_SUCH_NOTE',
|
2021-12-09 23:58:30 +09:00
|
|
|
id: '24fcbfc6-2e37-42b6-8388-c29b3861a08d',
|
|
|
|
},
|
2024-10-21 12:49:29 +09:00
|
|
|
|
|
|
|
signinRequired: {
|
|
|
|
message: 'Signin required.',
|
|
|
|
code: 'SIGNIN_REQUIRED',
|
|
|
|
id: '8e75455b-738c-471d-9f80-62693f33372e',
|
|
|
|
},
|
2021-12-09 23:58:30 +09:00
|
|
|
},
|
2022-01-18 22:27:10 +09:00
|
|
|
} as const;
|
2018-04-08 02:30:37 +09:00
|
|
|
|
2022-02-20 13:15:40 +09:00
|
|
|
export const paramDef = {
|
2022-02-19 14:05:32 +09:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
noteId: { type: 'string', format: 'misskey:id' },
|
|
|
|
},
|
|
|
|
required: ['noteId'],
|
|
|
|
} as const;
|
|
|
|
|
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(
|
2023-12-31 19:20:52 +01:00
|
|
|
@Inject(DI.notesRepository)
|
|
|
|
private notesRepository: NotesRepository,
|
2022-09-18 03:27:08 +09:00
|
|
|
private noteEntityService: NoteEntityService,
|
2023-12-31 19:20:52 +01:00
|
|
|
private queryService: QueryService,
|
2022-09-18 03:27:08 +09:00
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
2023-12-31 19:20:52 +01:00
|
|
|
const query = await this.notesRepository.createQueryBuilder('note')
|
2024-11-22 12:29:04 +00:00
|
|
|
.where('note.id = :noteId', { noteId: ps.noteId })
|
|
|
|
.innerJoinAndSelect('user');
|
2023-12-31 19:20:52 +01:00
|
|
|
|
|
|
|
this.queryService.generateVisibilityQuery(query, me);
|
|
|
|
if (me) {
|
|
|
|
this.queryService.generateBlockedUserQuery(query, me);
|
|
|
|
}
|
2024-11-22 12:29:04 +00:00
|
|
|
|
2023-12-31 19:20:52 +01:00
|
|
|
const note = await query.getOne();
|
|
|
|
|
|
|
|
if (note === null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchNote);
|
|
|
|
}
|
2022-09-18 03:27:08 +09:00
|
|
|
|
2024-10-21 12:49:29 +09:00
|
|
|
if (note.user!.requireSigninToViewContents && me == null) {
|
|
|
|
throw new ApiError(meta.errors.signinRequired);
|
|
|
|
}
|
|
|
|
|
2022-09-18 03:27:08 +09:00
|
|
|
return await this.noteEntityService.pack(note, me, {
|
|
|
|
detail: true,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|