CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/messages/get.ts
Views: 791
1
/*
2
Get your messages via an api
3
*/
4
5
import getAccountId from "lib/account/get-account";
6
import getParams from "lib/api/get-params";
7
import { SuccessStatus } from "lib/api/status";
8
import getMessages from "@cocalc/server/messages/get";
9
import throttle from "@cocalc/util/api/throttle";
10
11
export default async function handle(req, res) {
12
try {
13
const messages = await get(req);
14
res.json({ ...SuccessStatus, messages });
15
} catch (err) {
16
res.json({ error: `${err.message ? err.message : err}` });
17
return;
18
}
19
}
20
21
async function get(req) {
22
const account_id = await getAccountId(req);
23
24
if (!account_id) {
25
throw Error("Must be signed in to get messages");
26
}
27
28
throttle({
29
account_id,
30
endpoint: "messages/get",
31
});
32
const { limit, offset, type, cutoff } = getParams(req);
33
return await getMessages({ account_id, limit, offset, type, cutoff });
34
}
35
36