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