Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.get(action.payload.contentRef);
if (!content || content.type !== "notebook") {
return of({
type: "ERROR",
error: true,
payload: {
error: new Error("Only Notebooks can be published to Bookstore")
}
}) as any;
}
const notebook: NotebookV4 = toJS(content.model.notebook);
// Save notebook first before sending to Bookstore
return contents
.save(serverConfig, content.filepath, {
content: notebook,
type: "notebook"
})
.pipe(
tap((xhr: AjaxResponse) => {
if (xhr.status !== 200) {
throw new Error(xhr.response);
}
}),
map((nb: AjaxResponse) => {
return actions.publishToBookstoreAfterSave({
contentRef: action.payload.contentRef,
model: {
name: content.filepath.split("/").pop(),
path: content.filepath,
const diskDate = new Date(model.last_modified);
const inMemoryDate = content.lastSaved
? new Date(content.lastSaved)
: // FIXME: I'm unsure if we don't have a date if we should default to the disk date
diskDate;
if (Math.abs(diskDate - inMemoryDate) > 600) {
return of(
actions.saveFailed({
error: new Error("open in another tab possibly..."),
contentRef: action.payload.contentRef
})
);
}
return contents.save(serverConfig, filepath, saveModel).pipe(
map(xhr => {
return actions.saveFulfilled({
contentRef: action.payload.contentRef,
model: xhr.response
});
}),
catchError((error: Error) =>
of(
actions.saveFailed({
error,
contentRef: action.payload.contentRef
})
)
)
);
})
? new Date(content.lastSaved)
: // FIXME: I'm unsure if we don't have a date if we should
// default to the disk date
diskDate;
const diffDate = diskDate.getTime() - inMemoryDate.getTime();
if (Math.abs(diffDate) > 600) {
return of(
actions.saveFailed({
error: new Error("open in another tab possibly..."),
contentRef: action.payload.contentRef
})
);
}
return contents.save(serverConfig, filepath, saveModel).pipe(
mergeMap((saveXhr: AjaxResponse) => {
const pollIntervalMs = 500;
const maxPollNb = 4;
// Last_modified value from jupyter server is unreliable: https://github.com/nteract/nteract/issues/4583
// Check last-modified until value is stable.
return interval(pollIntervalMs)
.pipe(take(maxPollNb))
.pipe(
mergeMap(x =>
contents.get(serverConfig, filepath, { content: 0 }).pipe(
map((xhr: AjaxResponse) => {
if (xhr.status !== 200 || typeof xhr.response === "string") {
return undefined;
}
const model = xhr.response;
const sessionPayload: SessionPayload = {
kernel: {
id: null,
name: ks.name
},
name: "",
path: filepath,
type: "notebook"
};
return forkJoin(
// Get their kernel started up
sessions.create(serverConfig, sessionPayload),
// Save the initial notebook document
contents.save(serverConfig, filepath, {
content: notebook,
type: "notebook"
})
);
}),
first(),
const filepath = action.payload.filepath;
const { saveModel } = serializeContent(state, content);
if (!saveModel) {
return of(
actions.saveAsFailed({
error: new Error("No serialized model created for this content."),
contentRef: action.payload.contentRef
})
);
}
const serverConfig: ServerConfig = selectors.serverConfig(host);
return contents.save(serverConfig, filepath, saveModel).pipe(
map((xhr: AjaxResponse) => {
return actions.saveAsFulfilled({
contentRef: action.payload.contentRef,
model: xhr.response
});
}),
catchError((error: Error) =>
of(
actions.saveAsFailed({
error,
contentRef: action.payload.contentRef
})
)
)
);
})