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/frontend/client/file.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
import * as message from "@cocalc/util/message";
7
import { AsyncCall } from "./client";
8
import { redux } from "../app-framework";
9
import { required, defaults } from "@cocalc/util/misc";
10
11
export class FileClient {
12
private async_call: AsyncCall;
13
14
constructor(async_call: AsyncCall) {
15
this.async_call = async_call;
16
}
17
18
// Currently only used for testing and development in the console.
19
public async syncdoc_history(
20
string_id: string,
21
patches?: boolean
22
): Promise<any> {
23
return (
24
await this.async_call({
25
message: message.get_syncdoc_history({
26
string_id,
27
patches,
28
}),
29
allow_post: false,
30
})
31
).history;
32
}
33
34
// Returns true if the given file in the given project is currently
35
// marked as deleted.
36
public is_deleted(filename: string, project_id: string): boolean {
37
return !!redux
38
.getProjectStore(project_id)
39
?.get_listings()
40
?.isDeleted(filename);
41
}
42
43
public undelete(filename: string, project_id: string): void {
44
redux.getProjectStore(project_id)?.get_listings()?.undelete(filename);
45
}
46
47
public set_deleted(_filename, _project_id): void {
48
throw Error("set_deleted doesn't make sense for the frontend");
49
}
50
51
// Mark the given file with the given action.
52
public async mark_file(opts: {
53
project_id: string;
54
path: string;
55
action: string;
56
ttl?: number;
57
}): Promise<void> {
58
opts = defaults(opts, {
59
project_id: required,
60
path: required,
61
action: required,
62
ttl: 120,
63
});
64
await redux
65
.getActions("file_use")
66
?.mark_file(opts.project_id, opts.path, opts.action, opts.ttl);
67
}
68
69
public async remove_blob_ttls(
70
uuids: string[] // list of sha1 hashes of blobs stored in the blobstore
71
) {
72
if (uuids.length === 0) return;
73
await this.async_call({
74
message: message.remove_blob_ttls({ uuids }),
75
});
76
}
77
}
78
79