Path: blob/master/src/packages/next/lib/share/get-project.ts
1449 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Get information about a project.7*/89import getPool from "@cocalc/database/pool";10import { isUUID } from "./util";1112interface ProjectInfo {13title: string;14description: string;15name: string;16avatar_image_tiny: string;17avatar_image_full: string;18}1920export default async function getProjectInfo(21project_id: string,22columns: string[] = ["title", "description", "name"],23// not cached by default since editing then reloading is confusing with this cached.24cache?: "short" | "medium" | "long"25): Promise<Partial<ProjectInfo>> {26const pool = getPool(cache);27if (!isUUID(project_id)) {28throw Error(`project_id ${project_id} must be a uuid`);29}30const project = await pool.query(31`SELECT ${columns.join(",")} FROM projects WHERE project_id=$1`,32[project_id]33);34if (project.rows.length == 0) {35throw Error(`no project with id ${project_id}`);36}37const info: Partial<ProjectInfo> = {};38for (const name of columns) {39info[name] = project.rows[0][name] ?? "";40}41return info;42}434445