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/proxy/get-proxied-public-path-info.ts
Views: 687
1
// Get public path info for public path defined by url proxy which is assumed
2
// to already exist in the database.
3
4
import getPublicPathInfoGithub from "./get-public-path-info-github";
5
import getPublicPathInfoGist from "./get-public-path-info-gist";
6
import { join } from "path";
7
8
// disabled -- see comment below
9
// import getPublicPathInfoUrl from "./get-public-path-info-url";
10
11
export default async function getProxiedPublicPathInfo(
12
url: string,
13
segments?: string[]
14
) {
15
if (url.startsWith("github/")) {
16
return await getPublicPathInfoGithub(
17
segments == null ? url : join(url, ...segments.slice(1))
18
);
19
}
20
if (url.startsWith("gist/")) {
21
return await getPublicPathInfoGist(url);
22
}
23
// This is disabled now since it is easy for spammers to take advantage of this,
24
// and also when people paste general URL's in they are almost never the actual
25
// raw url of a notebook, but instead a general HTML page that has something like
26
// a notebook in it, and they just get confused.
27
// if (url.startsWith("url/")) {
28
// return await getPublicPathInfoUrl(url);
29
// }
30
throw Error(
31
`unsupported proxy url schema -- "${url}" -- url must be hosted on GitHub`
32
);
33
}
34
35