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/frontend/compute/cloud-filesystem/api.ts
Views: 687
import api from "@cocalc/frontend/client/api";1import LRU from "lru-cache";2import type {3CreateCloudFilesystem,4CloudFilesystem,5EditCloudFilesystem,6} from "@cocalc/util/db-schema/cloud-filesystems";7import {8CHANGE_MOUNTED,9CHANGE_UNMOUNTED,10} from "@cocalc/util/db-schema/cloud-filesystems";1112export async function createCloudFilesystem(13opts: CreateCloudFilesystem,14): Promise<number> {15return await api("compute/cloud-filesystem/create", opts);16}1718export async function deleteCloudFilesystem({19id,20lock,21}: {22id: number;23lock: string;24}): Promise<void> {25await api("compute/cloud-filesystem/delete", { id, lock });26}2728export async function editCloudFilesystem(29opts: EditCloudFilesystem,30): Promise<void> {31for (const field in opts) {32if (field == "id") {33continue;34}35if (!CHANGE_MOUNTED.has(field) && !CHANGE_UNMOUNTED.has(field)) {36throw Error(`invalid field '${field}' for edit`);37}38}39return await api("compute/cloud-filesystem/edit", opts);40}4142const cloudFilesystemCache = new LRU<string, CloudFilesystem[]>({43max: 100,44ttl: 1000 * 30,45});4647export async function getCloudFilesystems(48// give no options to get all file systems that YOU own across all your projects49opts: {50// id = specific on51id?: number;52// project_id = all in a given project (owned by anybody)53project_id?: string;54// if true, use cache and potentially return stale data (good for repeated calls in a list, etc.)55cache?: boolean;56} = {},57): Promise<CloudFilesystem[]> {58const key = `${opts.id}${opts.project_id}`;59if (opts.cache && cloudFilesystemCache.has(key)) {60return cloudFilesystemCache.get(key)!;61}62const filesystems = await api("compute/cloud-filesystem/get", {63id: opts.id,64project_id: opts.project_id,65});66// always save in cache67cloudFilesystemCache.set(key, filesystems);68return filesystems;69}7071export async function getMetrics({72id,73limit,74offset,75}: {76id: number;77limit?: number;78offset?: number;79}) {80return await api("compute/cloud-filesystem/get-metrics", {81cloud_filesystem_id: id,82limit,83offset,84});85}868788