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.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/bookmarks/get.ts
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2024 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Request } from "express";
7
8
import { loadStarredFilesBookmarks } from "@cocalc/server/bookmarks/starred";
9
import { STARRED_FILES } from "@cocalc/util/consts/bookmarks";
10
import { apiRoute, apiRouteOperation } from "lib/api";
11
import { processGetRequest } from "lib/api/bookmarks";
12
import {
13
BookmarkGetInputSchema,
14
BookmarkGetOutputSchema,
15
BookmarkGetOutputType,
16
} from "lib/api/schema/bookmarks";
17
18
async function handle(req, res) {
19
try {
20
res.json(await get(req));
21
} catch (err) {
22
res.json({ error: `${err.message}` });
23
return;
24
}
25
}
26
27
async function get(req: Request): Promise<BookmarkGetOutputType> {
28
const { project_id, account_id, type } = await processGetRequest(req);
29
30
switch (type) {
31
case STARRED_FILES: {
32
const { stars, last_edited } = await loadStarredFilesBookmarks({
33
project_id,
34
account_id,
35
});
36
37
return {
38
type,
39
project_id,
40
stars,
41
last_edited,
42
status: "success",
43
};
44
}
45
46
default:
47
return {
48
type,
49
project_id,
50
status: "error",
51
error: `cannot handle type '${type}'`,
52
};
53
}
54
}
55
56
export default apiRoute({
57
getBookmarks: apiRouteOperation({
58
method: "POST",
59
openApiOperation: {
60
tags: ["Projects"],
61
},
62
})
63
.input({
64
contentType: "application/json",
65
body: BookmarkGetInputSchema,
66
})
67
.outputs([
68
{
69
status: 200,
70
contentType: "application/json",
71
body: BookmarkGetOutputSchema,
72
},
73
])
74
.handler(handle),
75
});
76
77