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/lib/api/bookmarks.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2024 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import isCollaborator from "@cocalc/server/projects/is-collaborator";6import getAccountId from "lib/account/get-account";7import getParams from "lib/api/get-params";89import {10BookmarkGetInputSchema,11BookmarkSetInputSchema,12} from "lib/api/schema/bookmarks";1314// Process a request for the api/v2/bookmarks/* endpoints1516// TODO: deduplicate this with proper typing1718export async function processSetRequest(req) {19// ATTN: very confusing: this is the account_id or project_id for project level API keys20// Since bookmakrs are account specific (and collaborators shouldn't snoop on others), we block project keys21// In the future, there might be project-wide stars, which are not account specific.22const account_id = await getAccountId(req);23if (!account_id) {24throw Error("must be signed in");25}2627const data = BookmarkSetInputSchema.parse(getParams(req));2829if (account_id === data.project_id) {30throw new Error(31`As of now, you cannot use a project-level API key to modify account specific bookmarks. Use the account level API key!`,32);33}3435if (!(await isCollaborator({ account_id, project_id: data.project_id }))) {36throw Error("user must be a collaborator on the project");37}3839return { ...data, account_id };40}4142export async function processGetRequest(req) {43// ATTN: very confusing: this is the account_id or project_id for project level API keys44const account_id = await getAccountId(req);45if (!account_id) {46throw Error("must be signed in");47}4849const data = BookmarkGetInputSchema.parse(getParams(req));5051if (account_id === data.project_id) {52throw new Error(53`As of now, you cannot use a project-level API key to modify account specific bookmarks. Use the account level API key!`,54);55}5657if (!(await isCollaborator({ account_id, project_id: data.project_id }))) {58throw Error("user must be a collaborator on the project");59}6061return { ...data, account_id };62}636465