Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Handle workspace:// URLs in beaker://library
Browse files Browse the repository at this point in the history
Fixes #887
  • Loading branch information
taravancil committed Mar 16, 2018
1 parent 691c57d commit 6d289b0
Showing 1 changed file with 60 additions and 27 deletions.
87 changes: 60 additions & 27 deletions app/builtin-pages/views/library-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async function setup () {
window.OS_CAN_IMPORT_FOLDERS_AND_FILES = browserInfo.platform !== 'linux'

// load data
let url = window.location.pathname.slice(1)
let url = await parseLibraryUrl()
archive = new LibraryDatArchive(url)
await archive.setup()

Expand Down Expand Up @@ -296,38 +296,51 @@ async function loadReadme () {
// =

function render () {
yo.update(
document.querySelector('.library-wrapper'), yo`
<div class="library-wrapper library-view builtin-wrapper">
<div class="drag-hint">
<div class="icons">
<i class="fa fa-file-video-o"></i>
<i class="fa fa-file-image-o"></i>
<i class="fa fa-file-code-o"></i>
<i class="fa fa-file-text-o"></i>
<i class="fa fa-file-archive-o"></i>
if (!archive) {
yo.update(
document.querySelector('.library-wrapper'), yo`
<div class="library-wrapper library-view builtin-wrapper">
<div class="builtin-main" style="margin-left: 0; width: 100%">
<div class="view-wrapper">
${renderView()}
</div>
</div>
</div>`
)
} else {
yo.update(
document.querySelector('.library-wrapper'), yo`
<div class="library-wrapper library-view builtin-wrapper">
<div class="drag-hint">
<div class="icons">
<i class="fa fa-file-video-o"></i>
<i class="fa fa-file-image-o"></i>
<i class="fa fa-file-code-o"></i>
<i class="fa fa-file-text-o"></i>
<i class="fa fa-file-archive-o"></i>
</div>
<h1>Drop to add files</h1>
<h1>Drop to add files</h1>
<p>
Dropped files will be published directly to
<a href=${archive.url}>${shortenHash(archive.url)}</a>
</p>
</div>
<p>
Dropped files will be published directly to
<a href=${archive.url}>${shortenHash(archive.url)}</a>
</p>
</div>
<div class="builtin-main" style="margin-left: 0; width: 100%">
${renderHeader()}
<div class="builtin-main" style="margin-left: 0; width: 100%">
${renderHeader()}
<div class="view-wrapper">
${renderView()}
</div>
<div class="view-wrapper">
${renderView()}
</div>
${renderFooter()}
${renderFooter()}
</div>
</div>
</div>
`
)
`
)
}
}

function renderHeader () {
Expand Down Expand Up @@ -1989,7 +2002,8 @@ async function readViewStateFromUrl () {

try {
var node
var urlp = parseDatURL(window.location.pathname.slice(1))
var datUrl = await parseLibraryUrl()
var urlp = parseDatURL(datUrl)
var pathParts = urlp.pathname.split('/').filter(Boolean)

// select the archive
Expand Down Expand Up @@ -2044,6 +2058,25 @@ function getSafeDesc () {
return _get(archive, 'info.description', '').trim() || yo`<em>No description</em>`
}

async function parseLibraryUrl () {
var url
if (window.location.pathname.slice(1).startsWith('workspace:')) {
const wsName = window.location.pathname.slice('/workspace://'.length).split('/')[0]

const wsInfo = await beaker.workspaces.get(0, wsName)
if (wsInfo) {
url = wsInfo.publishTargetUrl
window.location.pathname = url + window.location.pathname.slice(`/workspace://${wsInfo.name}`.length)
} else {
toplevelError = createToplevelError('Invalid workspace name')
render()
}
} else {
url = window.location.pathname.slice(1)
}
return url
}

function createToplevelError (err) {
switch (err.name) {
case 'TimeoutError':
Expand Down

0 comments on commit 6d289b0

Please sign in to comment.