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(() =>
readFileObservable(nteractConfigFilename).pipe(
catchError(err => {
if (err.code === "ENOENT") {
return writeFileObservable(
nteractConfigFilename,
JSON.stringify({
theme: "light"
})
);
}
throw err;
})
)
),
switchMap(() =>
readFileObservable(CONFIG_FILE_PATH).pipe(
map(data => actions.configLoaded(JSON.parse(data.toString())))
)
)