2021-08-19 12:55:45 +00:00
|
|
|
import define from '../define';
|
|
|
|
import { publishMainStream } from '@/services/stream';
|
|
|
|
import { Users, Pages } from '@/models/index';
|
|
|
|
import { ApiError } from '../error';
|
2019-07-06 09:14:50 +00:00
|
|
|
|
|
|
|
export const meta = {
|
2022-01-18 13:27:10 +00:00
|
|
|
requireCredential: true,
|
2019-07-06 09:14:50 +00:00
|
|
|
secure: true,
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchPage: {
|
|
|
|
message: 'No such page.',
|
|
|
|
code: 'NO_SUCH_PAGE',
|
2021-12-09 14:58:30 +00:00
|
|
|
id: '4a13ad31-6729-46b4-b9af-e86b265c2e74',
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 13:27:10 +00:00
|
|
|
} as const;
|
2019-07-06 09:14:50 +00:00
|
|
|
|
2022-02-19 05:05:32 +00:00
|
|
|
const paramDef = {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
pageId: { type: 'string', format: 'misskey:id' },
|
|
|
|
event: { type: 'string' },
|
|
|
|
var: {},
|
|
|
|
},
|
|
|
|
required: ['pageId', 'event'],
|
|
|
|
} as const;
|
|
|
|
|
2022-01-02 17:12:50 +00:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-19 05:05:32 +00:00
|
|
|
export default define(meta, paramDef, async (ps, user) => {
|
2019-07-06 09:14:50 +00:00
|
|
|
const page = await Pages.findOne(ps.pageId);
|
|
|
|
if (page == null) {
|
|
|
|
throw new ApiError(meta.errors.noSuchPage);
|
|
|
|
}
|
|
|
|
|
2019-07-09 07:55:33 +00:00
|
|
|
publishMainStream(page.userId, 'pageEvent', {
|
2019-07-06 09:14:50 +00:00
|
|
|
pageId: ps.pageId,
|
|
|
|
event: ps.event,
|
2019-07-06 20:12:31 +00:00
|
|
|
var: ps.var,
|
2019-07-09 07:55:55 +00:00
|
|
|
userId: user.id,
|
2021-03-24 02:05:37 +00:00
|
|
|
user: await Users.pack(user.id, { id: page.userId }, {
|
2021-12-09 14:58:30 +00:00
|
|
|
detail: true,
|
|
|
|
}),
|
2019-07-06 09:14:50 +00:00
|
|
|
});
|
|
|
|
});
|