Pages (#4811)
* wip * wip * wip * Update page-editor.vue * wip * wip * wip * wip * wip * wip * wip * Update page-editor.variable.core.vue * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update aiscript.ts * wip * Update package.json * wip * wip * wip * wip * wip * Update page.vue * wip * wip * wip * wip * more info * wip fn * wip * wip * wip
This commit is contained in:
parent
747a0b1791
commit
05b8111c19
52 changed files with 3583 additions and 37 deletions
74
src/server/api/endpoints/pages/show.ts
Normal file
74
src/server/api/endpoints/pages/show.ts
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
import $ from 'cafy';
|
||||
import define from '../../define';
|
||||
import { ApiError } from '../../error';
|
||||
import { Pages, Users } from '../../../../models';
|
||||
import { types, bool } from '../../../../misc/schema';
|
||||
import { ID } from '../../../../misc/cafy-id';
|
||||
import { Page } from '../../../../models/entities/page';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
'ja-JP': '指定したページの情報を取得します。',
|
||||
},
|
||||
|
||||
tags: ['pages'],
|
||||
|
||||
requireCredential: false,
|
||||
|
||||
params: {
|
||||
pageId: {
|
||||
validator: $.optional.type(ID),
|
||||
desc: {
|
||||
'ja-JP': '対象のページのID',
|
||||
'en-US': 'Target page ID.'
|
||||
}
|
||||
},
|
||||
|
||||
name: {
|
||||
validator: $.optional.str,
|
||||
},
|
||||
|
||||
username: {
|
||||
validator: $.optional.str,
|
||||
},
|
||||
},
|
||||
|
||||
res: {
|
||||
type: types.object,
|
||||
optional: bool.false, nullable: bool.false,
|
||||
ref: 'Page',
|
||||
},
|
||||
|
||||
errors: {
|
||||
noSuchPage: {
|
||||
message: 'No such page.',
|
||||
code: 'NO_SUCH_PAGE',
|
||||
id: '222120c0-3ead-4528-811b-b96f233388d7'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default define(meta, async (ps, user) => {
|
||||
let page: Page | undefined;
|
||||
|
||||
if (ps.pageId) {
|
||||
page = await Pages.findOne(ps.pageId);
|
||||
} else if (ps.name && ps.username) {
|
||||
const author = await Users.findOne({
|
||||
host: null,
|
||||
usernameLower: ps.username.toLowerCase()
|
||||
});
|
||||
if (author) {
|
||||
page = await Pages.findOne({
|
||||
name: ps.name,
|
||||
userId: author.id
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (page == null) {
|
||||
throw new ApiError(meta.errors.noSuchPage);
|
||||
}
|
||||
|
||||
return await Pages.pack(page);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue