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/client/file.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import * as message from "@cocalc/util/message";6import { AsyncCall } from "./client";7import { redux } from "../app-framework";8import { required, defaults } from "@cocalc/util/misc";910export class FileClient {11private async_call: AsyncCall;1213constructor(async_call: AsyncCall) {14this.async_call = async_call;15}1617// Currently only used for testing and development in the console.18public async syncdoc_history(19string_id: string,20patches?: boolean21): Promise<any> {22return (23await this.async_call({24message: message.get_syncdoc_history({25string_id,26patches,27}),28allow_post: false,29})30).history;31}3233// Returns true if the given file in the given project is currently34// marked as deleted.35public is_deleted(filename: string, project_id: string): boolean {36return !!redux37.getProjectStore(project_id)38?.get_listings()39?.isDeleted(filename);40}4142public undelete(filename: string, project_id: string): void {43redux.getProjectStore(project_id)?.get_listings()?.undelete(filename);44}4546public set_deleted(_filename, _project_id): void {47throw Error("set_deleted doesn't make sense for the frontend");48}4950// Mark the given file with the given action.51public async mark_file(opts: {52project_id: string;53path: string;54action: string;55ttl?: number;56}): Promise<void> {57opts = defaults(opts, {58project_id: required,59path: required,60action: required,61ttl: 120,62});63await redux64.getActions("file_use")65?.mark_file(opts.project_id, opts.path, opts.action, opts.ttl);66}6768public async remove_blob_ttls(69uuids: string[] // list of sha1 hashes of blobs stored in the blobstore70) {71if (uuids.length === 0) return;72await this.async_call({73message: message.remove_blob_ttls({ uuids }),74});75}76}777879