Skip to content

Commit

Permalink
Wow
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Jan 2, 2025
1 parent e4f2ec3 commit f3abe32
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 58 deletions.
46 changes: 25 additions & 21 deletions packages/web-core/src/SessionConnections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,44 @@ export function WebSessionConnectionsMixin(pluginManager: PluginManager) {
const superDeleteConnection = self.deleteConnection
const superAddConnectionConf = self.addConnectionConf
return {
/**
* #action
*/
addConnectionConf(connectionConf: BaseConnectionConfigModel) {
if (self.adminMode) {
return superAddConnectionConf(connectionConf)
} else {
const { connectionId, type } = connectionConf
if (!type) {
throw new Error(`unknown connection type ${type}`)
}
const connection = self.sessionTracks.find(
c => c.connectionId === connectionId,
)
if (connection) {
return connection
} else {
const length = self.sessionConnections.push(connectionConf)
return self.sessionConnections[length - 1]
}
}
const { connectionId, type } = connectionConf
if (!type) {
throw new Error(`unknown connection type ${type}`)
}
const connection = self.sessionTracks.find(
c => c.connectionId === connectionId,
)
if (connection) {
return connection
}
const length = self.sessionConnections.push(connectionConf)
return self.sessionConnections[length - 1]
},

/**
* #action
*/
deleteConnection(configuration: AnyConfigurationModel) {
let deletedConn: unknown
if (self.adminMode) {
deletedConn = superDeleteConnection(configuration)
}
if (!deletedConn) {
return superDeleteConnection(configuration)
} else {
const { connectionId } = configuration
const idx = self.sessionConnections.findIndex(
c => c.connectionId === connectionId,
)
if (idx === -1) {
return undefined
}
return self.sessionConnections.splice(idx, 1)
return idx === -1
? undefined
: self.sessionConnections.splice(idx, 1)
}
return deletedConn
},
}
})
Expand Down
76 changes: 41 additions & 35 deletions products/jbrowse-web/src/SessionLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,7 @@ const SessionLoader = types
try {
const pluginLoader = new PluginLoader(snap.sessionPlugins || [], {
fetchESM: url => import(/* webpackIgnore:true */ url),
})
pluginLoader.installGlobalReExports(window)
}).installGlobalReExports(window)
const plugins = await pluginLoader.load(window.location.href)
self.setSessionPlugins([...plugins])
} catch (e) {
Expand Down Expand Up @@ -325,36 +324,40 @@ const SessionLoader = types
*/
async fetchConfig() {
// @ts-expect-error
let { configPath = window.__jbrowseConfigPath || 'config.json' } = self

// @ts-expect-error
if (window.__jbrowseCacheBuster) {
configPath += `?rand=${Math.random()}`
}

const text = await openLocation({
uri: configPath,
locationType: 'UriLocation',
}).readFile('utf8')
const config = JSON.parse(text)
const configUri = new URL(configPath, window.location.href)
addRelativeUris(config, configUri)
const path = window.__jbrowseConfigPath
let { hubURL, configPath = path || 'config.json' } = self
console.log({ hubURL, configPath })
if (!hubURL) {
// @ts-expect-error
if (window.__jbrowseCacheBuster) {
configPath += `?rand=${Math.random()}`
}
const text = await openLocation({
uri: configPath,
locationType: 'UriLocation',
}).readFile('utf8')
const config = JSON.parse(text)
const configUri = new URL(configPath, window.location.href)
addRelativeUris(config, configUri)

// cross origin config check
if (configUri.hostname !== window.location.hostname) {
const configPlugins = config.plugins || []
const configPluginsAllowed = await checkPlugins(configPlugins)
if (!configPluginsAllowed) {
self.setSessionTriaged({
snap: config,
origin: 'config',
reason: configPlugins,
})
return
// cross origin config check
if (configUri.hostname !== window.location.hostname) {
const configPlugins = config.plugins || []
const configPluginsAllowed = await checkPlugins(configPlugins)
if (!configPluginsAllowed) {
self.setSessionTriaged({
snap: config,
origin: 'config',
reason: configPlugins,
})
return
}
}
await this.fetchPlugins(config)
self.setConfigSnapshot(config)
} else {
self.setConfigSnapshot({})
}
await this.fetchPlugins(config)
self.setConfigSnapshot(config)
},
/**
* #action
Expand Down Expand Up @@ -470,12 +473,11 @@ const SessionLoader = types
* #action
*/
decodeHubSpec() {
const { loc, hubURL, sessionTracksParsed: sessionTracks } = self
if (loc) {
self.hubSpec = {
sessionTracks,
hubURL,
}
const { hubURL, sessionTracksParsed: sessionTracks } = self

self.hubSpec = {
sessionTracks,
hubURL,
}
},
/**
Expand Down Expand Up @@ -509,6 +511,7 @@ const SessionLoader = types
isSharedSession,
isJsonSession,
isJb1StyleSession,
isHubSession,
sessionQuery,
configSnapshot,
} = self
Expand All @@ -535,6 +538,9 @@ const SessionLoader = types
this.decodeJb1StyleSession()
} else if (isEncodedSession) {
await this.decodeEncodedUrlSession()
} else if (isHubSession) {
this.decodeHubSpec()
self.setBlankSession(true)
} else if (isJsonSession) {
await this.decodeJsonUrlSession()
} else if (isLocalSession) {
Expand Down
17 changes: 15 additions & 2 deletions products/jbrowse-web/src/loadHubSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,21 @@ export async function loadHubSpec(
if (!r.ok) {
throw new Error(`HTTP ${r.status} fetching ${hubURL[0]}`)
}
const d = await r.text()
console.log({ d })
// const d = await r.text()

// @ts-expect-error
rootModel.setSession({
name: `${hubURL.join(',')}`,
sessionConnections: hubURL.map(r => ({
type: 'UCSCTrackHubConnection',
connectionId: r,
name: r,
hubTxtLocation: {
uri: r,
locationType: 'UriLocation',
},
})),
})
} catch (e) {
console.error(e)
rootModel.session?.notifyError(`${e}`, e)
Expand Down

0 comments on commit f3abe32

Please sign in to comment.