misskey/packages/backend/src/server/api/endpoints/page-push.ts

51 lines
964 B
TypeScript
Raw Normal View History

import $ from 'cafy';
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';
export const meta = {
2020-02-15 13:33:32 +01:00
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);
}
2019-07-09 09:55:33 +02:00
publishMainStream(page.userId, 'pageEvent', {
pageId: ps.pageId,
event: ps.event,
var: ps.var,
2019-07-09 09:55:55 +02:00
userId: user.id,
user: await Users.pack(user.id, { id: page.userId }, {
detail: true
})
});
});