2019-07-06 18:14:50 +09:00
|
|
|
import $ from 'cafy';
|
2021-08-19 21:55:45 +09:00
|
|
|
import define from '../define';
|
|
|
|
import { ID } from '@/misc/cafy-id';
|
|
|
|
import { publishMainStream } from '@/services/stream';
|
|
|
|
import { Users, Pages } from '@/models/index';
|
|
|
|
import { ApiError } from '../error';
|
2019-07-06 18:14:50 +09:00
|
|
|
|
|
|
|
export const meta = {
|
2020-02-15 21:33:32 +09:00
|
|
|
requireCredential: true as const,
|
2019-07-06 18:14:50 +09:00
|
|
|
secure: true,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
pageId: {
|
2021-12-09 23:58:30 +09:00
|
|
|
validator: $.type(ID),
|
2019-07-06 18:14:50 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
event: {
|
2021-12-09 23:58:30 +09:00
|
|
|
validator: $.str,
|
2019-07-07 05:12:31 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
var: {
|
2021-12-09 23:58:30 +09:00
|
|
|
validator: $.optional.nullable.any,
|
|
|
|
},
|
2019-07-06 18:14:50 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchPage: {
|
|
|
|
message: 'No such page.',
|
|
|
|
code: 'NO_SUCH_PAGE',
|
2021-12-09 23:58:30 +09:00
|
|
|
id: '4a13ad31-6729-46b4-b9af-e86b265c2e74',
|
|
|
|
},
|
|
|
|
},
|
2019-07-06 18:14:50 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
export default define(meta, async (ps, user) => {
|
|
|
|
const page = await Pages.findOne(ps.pageId);
|
|
|
|
if (page == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchPage);
|
|
|
|
}
|
|
|
|
|
2019-07-09 16:55:33 +09:00
|
|
|
publishMainStream(page.userId, 'pageEvent', {
|
2019-07-06 18:14:50 +09:00
|
|
|
pageId: ps.pageId,
|
|
|
|
event: ps.event,
|
2019-07-07 05:12:31 +09:00
|
|
|
var: ps.var,
|
2019-07-09 16:55:55 +09:00
|
|
|
userId: user.id,
|
2021-03-24 11:05:37 +09:00
|
|
|
user: await Users.pack(user.id, { id: page.userId }, {
|
2021-12-09 23:58:30 +09:00
|
|
|
detail: true,
|
|
|
|
}),
|
2019-07-06 18:14:50 +09:00
|
|
|
});
|
|
|
|
});
|