Skip to content

Commit

Permalink
fix: support simwrapper command-line tool "here" mode
Browse files Browse the repository at this point in the history
simwrapper tool learned "simwrapper here" mode; these changes
support opening the site in local mode.

- Workers MUST NOT import global store or js/fileSystem.ts !!
  The global store can't hop across contexts.

See https://pypi.org/project/simwrapper/
for full documentation
  • Loading branch information
billyc committed Feb 10, 2022
1 parent 4c45ff7 commit 231f70d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 60 deletions.
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
<meta content="From the VSP team at TU-Berlin" name="twitter:description" />
<meta content="From the VSP team at TU-Berlin" name="og:description" />
<meta content="https://vsp.berlin/simwrapper" name="og:url" />
<meta
<!-- <meta
content="https://github.com/matsim-vsp/covid-sim/raw/master/src/assets/images/v1-thumb.png"
name="og:image"
/>
/> -->
<meta content="summary_large_image" name="twitter:card" />
<meta content="@billyinberlin" name="twitter:site" />
<meta content="@billyinberlin" name="twitter:creator" />
<meta
<!-- <meta
content="https://github.com/matsim-vsp/covid-sim/raw/master/src/assets/images/v1-thumb.png"
name="twitter:image"
/>
/> -->

<!-- github pages hack: allows single-page-app to handle arbitrary URLs -->
<script>
Expand Down
52 changes: 24 additions & 28 deletions src/fileSystemConfig.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import { FileSystemConfig } from '@/Globals'

// The URL contains the websiteLiveHost, calculated at runtime
const loc = window.location
const webLiveHostname = loc.hostname
const websiteLiveHost = `${loc.protocol}//${webLiveHostname}`

const fileSystems: FileSystemConfig[] = [
{
name: webLiveHostname + ' live folders',
slug: 'live',
description: 'Files served using "simwrapper here"',
baseURL: websiteLiveHost + ':9039/_f_', // e.g. 'http://localhost:9039/_f_',
hidden: true,
},
{
name: 'Localhost',
slug: 'local',
description: 'Run mini-file-server to browse files on your PC',
description: 'Files on this computer, shared with "simwrapper serve"',
baseURL: 'http://localhost:8000',
thumbnail: '/simwrapper/images/thumb-localfiles.jpg',
},
Expand Down Expand Up @@ -34,32 +46,6 @@ const fileSystems: FileSystemConfig[] = [
thumbnail: '/simwrapper/images/thumb-localfiles.jpg',
hidden: true,
},

// {
// name: 'Gallery',
// url: 'gallery',
// description: 'Example visualizations of public datasets.',
// svn:
// 'https://svn.vsp.tu-berlin.de/repos/public-svn/matsim/scenarios/countries/de/viz-examples/examples',
// need_password: false,
// thumbnail: '/thumb-examples.jpg',
// },
// {
// name: 'ils4 Math Cluster',
// slug: 'ils4',
// description: 'Mount cluster files using sshfs',
// baseURL: 'http://localhost:8000/cluster',
// needPassword: false,
// thumbnail: '/images/thumb-cluster.png',
// },
// {
// name: 'Apache (Local)',
// slug: 'apache',
// description: 'Run Apache locally',
// baseURL: 'http://localhost',
// needPassword: true,
// thumbnail: '/images/thumbnail.png',
// },
]

for (let port = 8000; port < 8500; port++) {
Expand All @@ -69,7 +55,17 @@ for (let port = 8000; port < 8500; port++) {
description: 'Localhost ' + port,
description_de: 'Localhost ' + port,
baseURL: 'http://localhost:' + port,
thumbnail: '/simwrapper/images/thumb-localfiles.jpg',
hidden: true,
})
}

for (let port = 9039; port < 9100; port++) {
fileSystems.push({
name: webLiveHostname + port,
slug: `${port}`,
description: webLiveHostname + port,
description_de: webLiveHostname + port,
baseURL: websiteLiveHost + `:${port}/_f_`, // e.g. 'http://localhost:9039/_f_',
hidden: true,
})
}
Expand Down
9 changes: 4 additions & 5 deletions src/js/HTTPFileSystem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import micromatch from 'micromatch'
import { DirectoryEntry, FileSystemConfig, YamlConfigs } from '@/Globals'
import globalStore from '@/store'

const YAML_FOLDER = 'simwrapper'

Expand Down Expand Up @@ -49,11 +48,11 @@ class SVNFileSystem {
const path = this.cleanURL(scaryPath)

const headers: any = {}
const credentials = globalStore.state.credentials[this.urlId]

if (this.needsAuth) {
headers['Authorization'] = `Basic ${credentials}`
}
// const credentials = globalStore.state.credentials[this.urlId]
// if (this.needsAuth) {
// headers['Authorization'] = `Basic ${credentials}`
// }

const myRequest = new Request(path, { headers })
const response = await fetch(myRequest).then(response => {
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/transit-demand/TransitDemand.vue
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@ class MyComponent extends Vue {
// save the promise by id so we can look it up when we get messages
const id = this.resolverId++
this.xmlWorker.postMessage(Object.assign({ id }, props))
const fileSystem = this.getFileSystem(props.fileApi)
this.xmlWorker.postMessage(Object.assign({ id, fileSystem }, props))
const promise = new Promise((resolve, reject) => {
this.resolvers[id] = { resolve, reject }
Expand Down
19 changes: 2 additions & 17 deletions src/workers/NewXmlFetcher.worker.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,17 @@
import pako from 'pako'
import { parseXML } from '@/js/util'

import globalStore from '@/store'
import HTTPFileSystem from '@/js/HTTPFileSystem'
import { FileSystemConfig } from '@/Globals'

onmessage = async function (e) {
const id = e.data.id
const xml = await fetchXML(e.data.fileApi, e.data.filePath, e.data.options)
const xml = await fetchXML(e.data.fileSystem, e.data.filePath, e.data.options)

postMessage({ xml, id })
}

const state = globalStore.state

function getFileSystem(name: string) {
const svnProject: FileSystemConfig[] = state.svnProjects.filter(
(a: FileSystemConfig) => a.slug === name
)
if (svnProject.length === 0) {
console.log('no such project:', name)
throwError('no such project' + name)
}
return svnProject[0]
}

async function fetchXML(fileApi: string, filePath: string, options: any) {
const fileSystem = getFileSystem(fileApi)
async function fetchXML(fileSystem: FileSystemConfig, filePath: string, options: any) {
const httpFileSystem = new HTTPFileSystem(fileSystem)

const blob = await httpFileSystem.getFileBlob(filePath)
Expand Down
9 changes: 4 additions & 5 deletions src/workers/XmlFetcher.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import { InitParams, MethodNames } from './XmlFetcherContract'
import pako from 'pako'
import { parseXML } from '@/js/util'

import globalStore from '@/store'
import HTTPFileSystem from '@/js/HTTPFileSystem'
import { FileSystemConfig } from '@/Globals'

class XmlFetcher extends AsyncBackgroundWorker {
private params!: InitParams
private state = globalStore.state

public handleInitialize(call: MethodCall) {
this.params = call.parameters as InitParams
Expand All @@ -26,9 +24,10 @@ class XmlFetcher extends AsyncBackgroundWorker {
}

private getFileSystem(name: string) {
const svnProject: FileSystemConfig[] = this.state.svnProjects.filter(
(a: FileSystemConfig) => a.slug === name
)
const svnProject: FileSystemConfig[] = []
// const svnProject: FileSystemConfig[] = this.state.svnProjects.filter(
// (a: FileSystemConfig) => a.slug === name
// )
if (svnProject.length === 0) {
console.log('no such project')
throw Error
Expand Down

0 comments on commit 231f70d

Please sign in to comment.