Skip to content

Commit

Permalink
Remove unused functionality from binderhub-client
Browse files Browse the repository at this point in the history
UI related stuff like this goes into spec.js
  • Loading branch information
yuvipanda committed Jul 12, 2024
1 parent 3e31936 commit 0ad9347
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 390 deletions.
107 changes: 0 additions & 107 deletions js/packages/binderhub-client/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,111 +208,4 @@ export class BinderRepository {
this.abortController = null;
}
}

/**
* Get URL to redirect user to on a Jupyter Server to display a given path
* @param {URL} serverUrl URL to the running jupyter server
* @param {string} token Secret token used to authenticate to the jupyter server
* @param {string} [path] The path of the file or url suffix to launch the user into
* @param {string} [pathType] One of "lab", "file" or "url", denoting what kinda path we are launching the user into
*
* @returns {URL} A URL to redirect the user to
*/
getFullRedirectURL(serverUrl, token, path, pathType) {
// Make a copy of the URL so we don't mangle the original
let url = new URL(serverUrl);
if (path) {
// Ensure there is a trailing / in serverUrl
if (!url.pathname.endsWith("/")) {
url.pathname += "/";
}
// trim leading '/' from path to launch users into
path = path.replace(/(^\/)/g, "");

if (pathType === "lab") {
// The path is a specific *file* we should open with JupyterLab
// trim trailing / on file paths
path = path.replace(/(\/$)/g, "");

// /doc/tree is safe because it allows redirect to files
url = new URL("doc/tree/" + encodeURI(path), url);
} else if (pathType === "file") {
// The path is a specific file we should open with *classic notebook*

// trim trailing / on file paths
path = path.replace(/(\/$)/g, "");

url = new URL("tree/" + encodeURI(path), url);
} else {
// pathType is 'url' and we should just pass it on
url = new URL(path, url);
}
}

url.searchParams.append("token", token);
return url;
}
}

/**
* Generate a shareable binder URL for given repository
*
* @param {URL} publicBaseUrl Base URL to use for making public URLs. Must end with a trailing slash.
* @param {string} providerPrefix prefix denoting what provider was selected
* @param {string} repository repo to build
* @param {string} ref optional ref in this repo to build
* @param {string} [path] Path to launch after this repo has been built
* @param {string} [pathType] Type of thing to open path with (raw url, notebook file, lab, etc)
*
* @returns {URL} A URL that can be shared with others, and clicking which will launch the repo
*/
export function makeShareableBinderURL(
publicBaseUrl,
providerPrefix,
repository,
ref,
path,
pathType,
) {
if (!publicBaseUrl.pathname.endsWith("/")) {
throw new Error(
`publicBaseUrl must end with a trailing slash, got ${publicBaseUrl}`,
);
}
const url = new URL(
`v2/${providerPrefix}/${repository}/${ref}`,
publicBaseUrl,
);
if (path && path.length > 0) {
url.searchParams.append(`${pathType}path`, path);
}
return url;
}

/**
* Generate markup that people can put on their README or documentation to link to a specific binder
*
* @param {URL} publicBaseUrl Base URL to use for making public URLs
* @param {URL} url Link target URL that represents this binder installation
* @param {string} syntax Kind of markup to generate. Supports 'markdown' and 'rst'
* @returns {string}
*/
export function makeBadgeMarkup(publicBaseUrl, url, syntax) {
if (!publicBaseUrl.pathname.endsWith("/")) {
throw new Error(
`publicBaseUrl must end with a trailing slash, got ${publicBaseUrl}`,
);
}
const badgeImageUrl = new URL("badge_logo.svg", publicBaseUrl);

if (syntax === "markdown") {
return `[![Binder](${badgeImageUrl})](${url})`;
} else if (syntax === "rst") {
return `.. image:: ${badgeImageUrl}\n :target: ${url}`;
} else {
throw new Error(
`Only markdown or rst badges are supported, got ${syntax} instead`,
);
}
}
Loading

0 comments on commit 0ad9347

Please sign in to comment.