Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function downloadArchiveRequest(
path: string,
archiveFormat: ArchiveFormat
): Promise {
const settings = ServerConnection.makeSettings();
let baseUrl = settings.baseUrl;
let url = URLExt.join(baseUrl, DIRECTORIES_URL, URLExt.encodeParts(path));
const fullurl = new URL(url);
// Generate a random token.
const rand = () =>
Math.random()
.toString(36)
.substr(2);
const token = (length: number) =>
(rand() + rand() + rand() + rand()).substr(0, length);
fullurl.searchParams.append("archiveToken", token(20));
fullurl.searchParams.append("archiveFormat", archiveFormat);
export function requestKernel(kernelOptions) {
// request a new Kernel
kernelOptions = mergeOptions({ kernelOptions }).kernelOptions;
if (kernelOptions.serverSettings) {
let ss = kernelOptions.serverSettings;
// workaround bug in jupyterlab where wsUrl and baseUrl must both be set
// https://github.com/jupyterlab/jupyterlab/pull/4427
if (ss.baseUrl && !ss.wsUrl) {
ss.wsUrl = "ws" + ss.baseUrl.slice(4);
}
kernelOptions.serverSettings = ServerConnection.makeSettings(
kernelOptions.serverSettings
);
}
events.trigger("status", {
status: "starting",
message: "Starting Kernel",
});
let p = Session.startNew(kernelOptions);
p.then(session => {
events.trigger("status", {
status: "ready",
message: "Kernel is ready",
});
let k = session.kernel;
return k;
});
it('should handle overrides', () => {
const defaults: Partial = {
baseUrl: 'foo',
wsUrl: 'bar',
init: {
credentials: 'same-origin'
},
token: 'baz'
};
const settings = ServerConnection.makeSettings(defaults);
expect(settings.baseUrl).to.equal(defaults.baseUrl);
expect(settings.wsUrl).to.equal(defaults.wsUrl);
expect(settings.token).to.equal(defaults.token);
expect(settings.init.credentials).to.equal(defaults.init!.credentials);
});
});
it('should accept options', () => {
const manager = new SettingManager({
serverSettings: ServerConnection.makeSettings()
});
expect(manager).to.be.an.instanceof(SettingManager);
});
});
function isNbInGit(args: {readonly path: string}): Promise {
let request = {
method: 'POST',
body: JSON.stringify(args),
};
let settings = ServerConnection.makeSettings();
return ServerConnection.makeRequest(
URLExt.join(urlRStrip(settings.baseUrl), '/nbdime/api/isgit'),
request, settings).then((response) => {
if (!response.ok) {
return Promise.reject(response);
}
return response.json() as Promise;
}).then((data) => {
return data['is_git'];
});
}
function requestApiPromise(
baseUrl: string,
apiPath: string,
argument: any): Promise {
const url = URLExt.join(urlRStrip(baseUrl), apiPath);
let request = {
method: 'POST',
body: JSON.stringify(argument),
};
let settings = ServerConnection.makeSettings();
return ServerConnection.makeRequest(url, request, settings)
.then(handleError);
}
requestKernel(settings) {
if (this.useStorage && typeof window !== 'undefined') {
const timestamp = new Date().getTime() + this.storageExpire * 60 * 1000;
const json = JSON.stringify({ settings, timestamp });
window.localStorage.setItem(this.storageKey, json);
}
const serverSettings = ServerConnection.makeSettings(settings);
return Kernel.startNew({ type: this.kernelType, name: this.kernelType, serverSettings })
.then(kernel => {
this._event('ready');
return kernel;
});
}