2022-04-17 06:14:29 +02:00
|
|
|
import { IsNull } from 'typeorm';
|
2022-02-27 03:07:39 +01:00
|
|
|
import { Pages, Users } from '@/models/index.js';
|
|
|
|
import { Page } from '@/models/entities/page.js';
|
2022-04-17 06:14:29 +02:00
|
|
|
import define from '../../define.js';
|
|
|
|
import { ApiError } from '../../error.js';
|
2019-04-29 02:11:57 +02:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
tags: ['pages'],
|
|
|
|
|
2022-01-18 14:27:10 +01:00
|
|
|
requireCredential: false,
|
2019-04-29 02:11:57 +02:00
|
|
|
|
|
|
|
res: {
|
2022-01-18 14:27:10 +01:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2019-04-29 02:11:57 +02:00
|
|
|
ref: 'Page',
|
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchPage: {
|
|
|
|
message: 'No such page.',
|
|
|
|
code: 'NO_SUCH_PAGE',
|
2021-12-09 15:58:30 +01:00
|
|
|
id: '222120c0-3ead-4528-811b-b96f233388d7',
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 14:27:10 +01:00
|
|
|
} as const;
|
2019-04-29 02:11:57 +02:00
|
|
|
|
2022-02-20 05:15:40 +01:00
|
|
|
export const paramDef = {
|
2022-02-19 06:05:32 +01:00
|
|
|
type: 'object',
|
2022-04-03 06:57:26 +02:00
|
|
|
anyOf: [
|
|
|
|
{
|
|
|
|
properties: {
|
|
|
|
pageId: { type: 'string', format: 'misskey:id' },
|
|
|
|
},
|
|
|
|
required: ['pageId'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
properties: {
|
|
|
|
name: { type: 'string' },
|
|
|
|
username: { type: 'string' },
|
|
|
|
},
|
|
|
|
required: ['name', 'username'],
|
|
|
|
},
|
|
|
|
],
|
2022-02-19 06:05:32 +01:00
|
|
|
} as const;
|
|
|
|
|
2022-01-02 18:12:50 +01:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 06:05:32 +01:00
|
|
|
export default define(meta, paramDef, async (ps, user) => {
|
2022-04-17 06:14:29 +02:00
|
|
|
let page: Page | null = null;
|
2019-04-29 02:11:57 +02:00
|
|
|
|
|
|
|
if (ps.pageId) {
|
2022-03-26 07:34:00 +01:00
|
|
|
page = await Pages.findOneBy({ id: ps.pageId });
|
2019-04-29 02:11:57 +02:00
|
|
|
} else if (ps.name && ps.username) {
|
2022-03-26 07:34:00 +01:00
|
|
|
const author = await Users.findOneBy({
|
|
|
|
host: IsNull(),
|
2021-12-09 15:58:30 +01:00
|
|
|
usernameLower: ps.username.toLowerCase(),
|
2019-04-29 02:11:57 +02:00
|
|
|
});
|
|
|
|
if (author) {
|
2022-03-26 07:34:00 +01:00
|
|
|
page = await Pages.findOneBy({
|
2019-04-29 02:11:57 +02:00
|
|
|
name: ps.name,
|
2021-12-09 15:58:30 +01:00
|
|
|
userId: author.id,
|
2019-04-29 02:11:57 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (page == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchPage);
|
|
|
|
}
|
|
|
|
|
2019-05-17 12:56:47 +02:00
|
|
|
return await Pages.pack(page, user);
|
2019-04-29 02:11:57 +02:00
|
|
|
});
|