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/raw-url.ts
Views: 687
1
/*
2
The raw URL is the following, of course encoded as a URL:
3
4
.../raw/{share id}/{the full path in the project to file}
5
*/
6
7
import { join } from "path";
8
import basePath from "lib/base-path";
9
10
interface Options {
11
id: string;
12
path: string;
13
relativePath: string;
14
}
15
16
export default function rawURL({ id, path, relativePath }: Options): string {
17
return join(
18
basePath,
19
`share/raw/${id}/${encodePath(join(path, relativePath))}`
20
);
21
}
22
23
export function encodePath(path: string) {
24
const segments = path.split("/");
25
const encoded: string[] = [];
26
for (const segment of segments) {
27
encoded.push(encodeURIComponent(segment));
28
}
29
return encoded.join("/");
30
}
31
32