2019-07-06 04:14:50 -05:00
|
|
|
import $ from 'cafy';
|
|
|
|
import define from '../define';
|
|
|
|
import { ID } from '../../../misc/cafy-id';
|
|
|
|
import { publishMainStream } from '../../../services/stream';
|
|
|
|
import { Users, Pages } from '../../../models';
|
|
|
|
import { ApiError } from '../error';
|
|
|
|
|
|
|
|
export const meta = {
|
2020-02-15 06:33:32 -06:00
|
|
|
requireCredential: true as const,
|
2019-07-06 04:14:50 -05:00
|
|
|
secure: true,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
pageId: {
|
|
|
|
validator: $.type(ID)
|
|
|
|
},
|
|
|
|
|
|
|
|
event: {
|
|
|
|
validator: $.str
|
2019-07-06 15:12:31 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
var: {
|
|
|
|
validator: $.optional.nullable.any
|
2019-07-06 04:14:50 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-07-09 02:55:33 -05:00
|
|
|
publishMainStream(page.userId, 'pageEvent', {
|
2019-07-06 04:14:50 -05:00
|
|
|
pageId: ps.pageId,
|
|
|
|
event: ps.event,
|
2019-07-06 15:12:31 -05:00
|
|
|
var: ps.var,
|
2019-07-09 02:55:55 -05:00
|
|
|
userId: user.id,
|
2019-07-06 04:14:50 -05:00
|
|
|
user: await Users.pack(user, page.userId, {
|
|
|
|
detail: true
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|