Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/pages/api/v2/bookmarks/get.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2024 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Request } from "express";67import { loadStarredFilesBookmarks } from "@cocalc/server/bookmarks/starred";8import { STARRED_FILES } from "@cocalc/util/consts/bookmarks";9import { apiRoute, apiRouteOperation } from "lib/api";10import { processGetRequest } from "lib/api/bookmarks";11import {12BookmarkGetInputSchema,13BookmarkGetOutputSchema,14BookmarkGetOutputType,15} from "lib/api/schema/bookmarks";1617async function handle(req, res) {18try {19res.json(await get(req));20} catch (err) {21res.json({ error: `${err.message}` });22return;23}24}2526async function get(req: Request): Promise<BookmarkGetOutputType> {27const { project_id, account_id, type } = await processGetRequest(req);2829switch (type) {30case STARRED_FILES: {31const { stars, last_edited } = await loadStarredFilesBookmarks({32project_id,33account_id,34});3536return {37type,38project_id,39stars,40last_edited,41status: "success",42};43}4445default:46return {47type,48project_id,49status: "error",50error: `cannot handle type '${type}'`,51};52}53}5455export default apiRoute({56getBookmarks: apiRouteOperation({57method: "POST",58openApiOperation: {59tags: ["Projects"],60},61})62.input({63contentType: "application/json",64body: BookmarkGetInputSchema,65})66.outputs([67{68status: 200,69contentType: "application/json",70body: BookmarkGetOutputSchema,71},72])73.handler(handle),74});757677