b9cb6d1c10
将来ESMに移行しやすいように Related: #7658 なんかmochaが起動しなくなってるけど理由不明 すぐ直したい
50 lines
979 B
TypeScript
50 lines
979 B
TypeScript
import $ from 'cafy';
|
|
import define from '../define.js';
|
|
import { ID } from '@/misc/cafy-id.js';
|
|
import { publishMainStream } from '@/services/stream.js';
|
|
import { Users, Pages } from '@/models/index.js';
|
|
import { ApiError } from '../error.js';
|
|
|
|
export const meta = {
|
|
requireCredential: true as const,
|
|
secure: true,
|
|
|
|
params: {
|
|
pageId: {
|
|
validator: $.type(ID)
|
|
},
|
|
|
|
event: {
|
|
validator: $.str
|
|
},
|
|
|
|
var: {
|
|
validator: $.optional.nullable.any
|
|
}
|
|
},
|
|
|
|
errors: {
|
|
noSuchPage: {
|
|
message: 'No such page.',
|
|
code: 'NO_SUCH_PAGE',
|
|
id: '4a13ad31-6729-46b4-b9af-e86b265c2e74'
|
|
}
|
|
}
|
|
};
|
|
|
|
export default define(meta, async (ps, user) => {
|
|
const page = await Pages.findOne(ps.pageId);
|
|
if (page == null) {
|
|
throw new ApiError(meta.errors.noSuchPage);
|
|
}
|
|
|
|
publishMainStream(page.userId, 'pageEvent', {
|
|
pageId: ps.pageId,
|
|
event: ps.event,
|
|
var: ps.var,
|
|
userId: user.id,
|
|
user: await Users.pack(user.id, { id: page.userId }, {
|
|
detail: true
|
|
})
|
|
});
|
|
});
|