Skip to content

Commit

Permalink
move launch params parsing to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Apr 8, 2024
1 parent dd2f0d9 commit c7c8af6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 34 deletions.
38 changes: 38 additions & 0 deletions frontend/common/parse_launch_params.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
*
* @return {import("../components/Editor.js").LaunchParameters}
*/
export const parse_launch_params = () => {
const url_params = new URLSearchParams(window.location.search)

return {
//@ts-ignore
notebook_id: url_params.get("id") ?? window.pluto_notebook_id,
//@ts-ignore
statefile: url_params.get("statefile") ?? window.pluto_statefile,
//@ts-ignore
statefile_integrity: url_params.get("statefile_integrity") ?? window.pluto_statefile_integrity,
//@ts-ignore
notebookfile: url_params.get("notebookfile") ?? window.pluto_notebookfile,
//@ts-ignore
notebookfile_integrity: url_params.get("notebookfile_integrity") ?? window.pluto_notebookfile_integrity,
//@ts-ignore
disable_ui: !!(url_params.get("disable_ui") ?? window.pluto_disable_ui),
//@ts-ignore
preamble_html: url_params.get("preamble_html") ?? window.pluto_preamble_html,
//@ts-ignore
isolated_cell_ids: url_params.has("isolated_cell_id") ? url_params.getAll("isolated_cell_id") : window.pluto_isolated_cell_ids,
//@ts-ignore
binder_url: url_params.get("binder_url") ?? window.pluto_binder_url,
//@ts-ignore
pluto_server_url: url_params.get("pluto_server_url") ?? window.pluto_pluto_server_url,
//@ts-ignore
slider_server_url: url_params.get("slider_server_url") ?? window.pluto_slider_server_url,
//@ts-ignore
recording_url: url_params.get("recording_url") ?? window.pluto_recording_url,
//@ts-ignore
recording_url_integrity: url_params.get("recording_url_integrity") ?? window.pluto_recording_url_integrity,
//@ts-ignore
recording_audio_url: url_params.get("recording_audio_url") ?? window.pluto_recording_audio_url,
}
}
36 changes: 2 additions & 34 deletions frontend/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { FetchProgress, read_Uint8Array_with_progress } from "./components/Fetch
import { unpack } from "./common/MsgPack.js"
import { RawHTMLContainer } from "./components/CellOutput.js"
import { ProcessStatus } from "./common/ProcessStatus.js"
import { parse_launch_params } from "./common/parse_launch_params.js"

const url_params = new URLSearchParams(window.location.search)

Expand All @@ -25,40 +26,7 @@ export const set_disable_ui_css = (val) => {
/////////////
// the rest:

/**
*
* @type {import("./components/Editor.js").LaunchParameters}
*/
const launch_params = {
//@ts-ignore
notebook_id: url_params.get("id") ?? window.pluto_notebook_id,
//@ts-ignore
statefile: url_params.get("statefile") ?? window.pluto_statefile,
//@ts-ignore
statefile_integrity: url_params.get("statefile_integrity") ?? window.pluto_statefile_integrity,
//@ts-ignore
notebookfile: url_params.get("notebookfile") ?? window.pluto_notebookfile,
//@ts-ignore
notebookfile_integrity: url_params.get("notebookfile_integrity") ?? window.pluto_notebookfile_integrity,
//@ts-ignore
disable_ui: !!(url_params.get("disable_ui") ?? window.pluto_disable_ui),
//@ts-ignore
preamble_html: url_params.get("preamble_html") ?? window.pluto_preamble_html,
//@ts-ignore
isolated_cell_ids: url_params.has("isolated_cell_id") ? url_params.getAll("isolated_cell_id") : window.pluto_isolated_cell_ids,
//@ts-ignore
binder_url: url_params.get("binder_url") ?? window.pluto_binder_url,
//@ts-ignore
pluto_server_url: url_params.get("pluto_server_url") ?? window.pluto_pluto_server_url,
//@ts-ignore
slider_server_url: url_params.get("slider_server_url") ?? window.pluto_slider_server_url,
//@ts-ignore
recording_url: url_params.get("recording_url") ?? window.pluto_recording_url,
//@ts-ignore
recording_url_integrity: url_params.get("recording_url_integrity") ?? window.pluto_recording_url_integrity,
//@ts-ignore
recording_audio_url: url_params.get("recording_audio_url") ?? window.pluto_recording_audio_url,
}
const launch_params = parse_launch_params()

const truthy = (x) => x === "" || x === "true"
const falsey = (x) => x === "false"
Expand Down

0 comments on commit c7c8af6

Please sign in to comment.