Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
switchMap(action => {
const filepath = action.payload.filepath;
return forkJoin(
readFileObservable(filepath),
statObservable(filepath),
// Project onto the Contents API response
(content: Buffer, stat: fs.Stats): contents.IContent =>
createContentsResponse(filepath, stat, content)
).pipe(
// Timeout after one minute
timeout(60 * 1000),
map((model: contents.IContent<"notebook">) => {
if (model.type !== "notebook") {
throw new Error(
"Attempted to load a non-notebook type from desktop"
);
}
if (model.content === null) {
throw new Error("No content loaded for notebook");
}
mergeMap(() =>
// Create all the directories we need in parallel
forkJoin(
// Ensure the runtime Dir is setup for kernels
mkdirpObservable(jupyterPaths.runtimeDir()),
// Ensure the config directory is all set up
mkdirpObservable(jupyterConfigDir)
)
),
mergeMap(() =>
// Create all the directories we need in parallel
forkJoin(
// Ensure the runtime Dir is setup for kernels
mkdirpObservable(jupyterPaths.runtimeDir()),
// Ensure the config directory is all set up
mkdirpObservable(jupyterConfigDir)
)
),
switchMap(action => {
const filepath = action.payload.filepath;
return forkJoin(
readFileObservable(filepath),
statObservable(filepath),
// Project onto the Contents API response
(content: Buffer, stat: fs.Stats): contents.IContent =>
createContentsResponse(filepath, stat, content)
).pipe(
// Timeout after one minute
timeout(60 * 1000),
map((model: contents.IContent<"notebook">) => {
if (model.type !== "notebook") {
throw new Error(
"Attempted to load a non-notebook type from desktop"
);
}
if (model.content === null) {
throw new Error("No content loaded for notebook");
}
return of(
actions.saveFailed({
contentRef: action.payload.contentRef,
error: new Error("no notebook loaded to save")
})
);
}
const filepath = content.filepath;
const appVersion = selectors.appVersion(state);
const notebook = stringifyNotebook(
toJS(
model.notebook.setIn(["metadata", "nteract", "version"], appVersion)
)
);
return writeFileObservable(filepath, notebook).pipe(
map(() => {
if (process.platform !== "darwin") {
const notificationSystem = selectors.notificationSystem(
state$.value
);
notificationSystem.addNotification({
autoDismiss: 2,
level: "success",
title: "Save successful!"
});
}
return actions.saveFulfilled({
contentRef: action.payload.contentRef,
model: {
last_modified: new Date()
}
mergeMap(() =>
writeFileObservable(
CONFIG_FILE_PATH,
JSON.stringify(state$.value.config.toJS())
).pipe(map(actions.doneSavingConfig))
)
const installShellCommandsObservable = (
exe: string,
rootDir: string,
binDir: string
): Observable => {
if (process.platform === "win32") {
return setWinPathObservable(exe, rootDir, binDir);
}
const envFile = join(binDir, "nteract-env");
return writeFileObservable(
envFile,
`NTERACT_EXE="${exe}"\nNTERACT_DIR="${rootDir}"`
).pipe(
mergeMap(() => {
const target = join(binDir, "nteract.sh");
return createSymlinkObservable(target, "/usr/local/bin/nteract").pipe(
catchError(() => {
if (!process.env.HOME) {
throw new Error("HOME not defined");
}
const dest = join(process.env.HOME, ".local/bin/nteract");
return createSymlinkObservable(target, dest);
})
);
})
);
catchError(err => {
if (err.code === "ENOENT") {
return writeFileObservable(
nteractConfigFilename,
JSON.stringify({
theme: "light"
})
);
}
throw err;
})
)
const installShellCommandsObservable = (
exe: string,
rootDir: string,
binDir: string
) => {
if (process.platform === "win32") {
return setWinPathObservable(exe, rootDir, binDir);
}
const envFile = join(binDir, "nteract-env");
return writeFileObservable(
envFile,
`NTERACT_EXE="${exe}"\nNTERACT_DIR="${rootDir}"`
).pipe(
mergeMap(() => {
const target = join(binDir, "nteract.sh");
return createSymlinkObservable(target, "/usr/local/bin/nteract").pipe(
catchError(() => {
const dest = join(process.env.HOME, ".local/bin/nteract");
return createSymlinkObservable(target, dest);
})
);
})
);
};
catchError(() => {
if (!process.env.HOME) {
throw new Error("HOME not defined");
}
const dest = join(process.env.HOME, ".local/bin/nteract");
return createSymlinkObservable(target, dest);
})
);