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/project/sync/listings.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 {
7
registerListingsTable as registerListingsTable0,
8
getListingsTable,
9
} from "@cocalc/sync/listings";
10
import getListing from "@cocalc/backend/get-listing";
11
import { Watcher } from "@cocalc/backend/path-watcher";
12
import { close_all_syncdocs_in_tree } from "./sync-doc";
13
import { getLogger } from "@cocalc/backend/logger";
14
import { existsSync } from "fs";
15
16
const logger = getLogger("project:sync:listings");
17
const log = logger.debug;
18
19
export { getListingsTable };
20
21
export function registerListingsTable(table, query): void {
22
log("registerListingsTables");
23
log("registerListingsTables: query=", query);
24
const onDeletePath = async (path) => {
25
// Also we need to close *all* syncdocs that are going to be deleted,
26
// and wait until closing is done before we return.
27
await close_all_syncdocs_in_tree(path);
28
};
29
30
const createWatcher = (path: string, debounce: number) =>
31
new Watcher(path, { debounce });
32
33
const { project_id, compute_server_id } = query.listings[0];
34
35
if (compute_server_id == 0) {
36
log(
37
"registerListingsTables -- actually registering since compute_server_id=0",
38
);
39
registerListingsTable0({
40
table,
41
project_id,
42
compute_server_id,
43
onDeletePath,
44
getListing,
45
createWatcher,
46
existsSync,
47
getLogger,
48
});
49
} else {
50
log(
51
"registerListingsTables -- NOT implemented since compute_server_id=",
52
compute_server_id,
53
);
54
}
55
}
56
57