2019-07-06 12:14:50 +03:00
|
|
|
import $ from 'cafy';
|
2021-08-19 12:33:41 +03:00
|
|
|
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';
|
2019-07-06 12:14:50 +03:00
|
|
|
|
|
|
|
export const meta = {
|
2020-02-15 14:33:32 +02:00
|
|
|
requireCredential: true as const,
|
2019-07-06 12:14:50 +03:00
|
|
|
secure: true,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
pageId: {
|
|
|
|
validator: $.type(ID)
|
|
|
|
},
|
|
|
|
|
|
|
|
event: {
|
|
|
|
validator: $.str
|
2019-07-06 23:12:31 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
var: {
|
|
|
|
validator: $.optional.nullable.any
|
2019-07-06 12:14:50 +03: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 10:55:33 +03:00
|
|
|
publishMainStream(page.userId, 'pageEvent', {
|
2019-07-06 12:14:50 +03:00
|
|
|
pageId: ps.pageId,
|
|
|
|
event: ps.event,
|
2019-07-06 23:12:31 +03:00
|
|
|
var: ps.var,
|
2019-07-09 10:55:55 +03:00
|
|
|
userId: user.id,
|
2021-03-24 04:05:37 +02:00
|
|
|
user: await Users.pack(user.id, { id: page.userId }, {
|
2019-07-06 12:14:50 +03:00
|
|
|
detail: true
|
|
|
|
})
|
|
|
|
});
|
|
|
|
});
|