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