-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loader move to simplify CadView. (#751)
* Generalize src/* IFC references to prepare for .obj support. * Improve MimeTypes api. * Rename MimeType.js to Filetype.js; improve API; add unit tests. * ShareRoutes uses new Filetypes API. * Remove .obj testing for now. * Alert user of missing filepath or unsupported filetype. * Restart PR#695 from new base #694. * Lint fix. --------- Signed-off-by: Pablo Mayrgundter <pablo.mayrgundter@gmail.com>
- Loading branch information
1 parent
602522e
commit b1132c0
Showing
6 changed files
with
59 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"name": "bldrs", | ||
"version": "1.0.0-r683", | ||
"version": "1.0.0-r682", | ||
"main": "src/index.jsx", | ||
"license": "MIT", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import debug from '../utils/debug' | ||
|
||
|
||
/** | ||
* Upload a local file for display. | ||
* | ||
* @param {Function} navigate | ||
* @param {string} appPrefix | ||
* @param {Function} handleBeforeUnload | ||
*/ | ||
export function loadLocalFile(navigate, appPrefix, handleBeforeUnload) { | ||
const viewerContainer = document.getElementById('viewer-container') | ||
const fileInput = document.createElement('input') | ||
fileInput.setAttribute('type', 'file') | ||
fileInput.addEventListener( | ||
'change', | ||
(event) => { | ||
debug().log('loader#loadLocalFile#event:', event) | ||
let tmpUrl = URL.createObjectURL(event.target.files[0]) | ||
debug().log('loader#loadLocalFile#event: url: ', tmpUrl) | ||
const parts = tmpUrl.split('/') | ||
tmpUrl = parts[parts.length - 1] | ||
window.removeEventListener('beforeunload', handleBeforeUnload) | ||
// TODO(pablo): detect content and set appropriate suffix. | ||
// Alternatively, leave it without suffix, but this also | ||
// triggers downstream handling issues. | ||
navigate(`${appPrefix}/v/new/${tmpUrl}.ifc`) | ||
}, | ||
false, | ||
) | ||
viewerContainer.appendChild(fileInput) | ||
fileInput.click() | ||
viewerContainer.removeChild(fileInput) | ||
} | ||
|
||
|
||
/** | ||
* Construct browser's actual blob URL from app URL for uploaded file. | ||
* | ||
* @param {string} filepath | ||
* @return {string} | ||
*/ | ||
export function getUploadedBlobPath(filepath) { | ||
const l = window.location | ||
// TODO(pablo): fix this with the above TODO for ifc suffix. | ||
filepath = filepath.split('.ifc')[0] | ||
const parts = filepath.split('/') | ||
filepath = parts[parts.length - 1] | ||
filepath = `blob:${l.protocol}//${l.hostname + (l.port ? `:${l.port}` : '')}/${filepath}` | ||
return filepath | ||
} |