Skip to content

Commit

Permalink
New URL formats in URLHelper (#2229)
Browse files Browse the repository at this point in the history
* URLHelper now supports both old and new speckle URLs. Moved URLHelper to the viewer library so users can use it to transform speckle urls in loadable object urls. Disabled object-loader from reading the local storage for auth tokens.

* Added URI decoding

* Error checking. URLHelper is not a class anymore

* Queries are not run in parallel
  • Loading branch information
AlexandruPopovici authored Apr 26, 2024
1 parent cd16b04 commit af8c3e1
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 92 deletions.
17 changes: 11 additions & 6 deletions packages/objectloader/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import 'core-js'
import 'regenerator-runtime/runtime'

import { SafeLocalStorage } from '@speckle/shared'
import {
ObjectLoaderConfigurationError,
ObjectLoaderRuntimeError
Expand Down Expand Up @@ -54,11 +53,17 @@ export default class ObjectLoader {
}

this.logger('Object loader constructor called!')
try {
this.token = token || SafeLocalStorage.get('AuthToken')
} catch (error) {
// Accessing localStorage may throw when executing on sandboxed document, ignore.
}

/** I don't think the object-loader should read the token from local storage, since there is no
* builtin mechanism that sets it in the first place. So you're reading a key from the local storage
* and hoping it will magically be there.
*/
// try {
// this.token = token || SafeLocalStorage.get('AuthToken')
// } catch (error) {
// // Accessing localStorage may throw when executing on sandboxed document, ignore.
// }
this.token = token

this.headers = {
Accept: 'text/plain'
Expand Down
4 changes: 2 additions & 2 deletions packages/viewer-sandbox/src/Sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import {
ExplodeExtension,
DiffExtension,
SpeckleLoader,
ObjLoader
ObjLoader,
UrlHelper
} from '@speckle/viewer'
import { FolderApi, Pane } from 'tweakpane'
import UrlHelper from './UrlHelper'
import { DiffResult } from '@speckle/viewer'
import type { PipelineOptions } from '@speckle/viewer/dist/modules/pipeline/Pipeline'
import { Units } from '@speckle/viewer'
Expand Down
83 changes: 0 additions & 83 deletions packages/viewer-sandbox/src/UrlHelper.ts

This file was deleted.

4 changes: 3 additions & 1 deletion packages/viewer-sandbox/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '@speckle/viewer'
import { SectionTool } from '@speckle/viewer'
import { SectionOutlines } from '@speckle/viewer'

const createViewer = async (containerName: string, stream: string) => {
const container = document.querySelector<HTMLElement>(containerName)

Expand Down Expand Up @@ -122,6 +123,7 @@ const getStream = () => {
// 'https://speckle.xyz/streams/da9e320dad/commits/5388ef24b8?c=%5B-7.66134,10.82932,6.41935,-0.07739,-13.88552,1.8697,0,1%5D'
// Revit sample house (good for bim-like stuff with many display meshes)
// 'https://speckle.xyz/streams/da9e320dad/commits/5388ef24b8'
'https://app.speckle.systems/projects/da9e320dad/models/3f0dc4be35%405388ef24b8'
// 'https://latest.speckle.dev/streams/58b5648c4d/commits/60371ecb2d'
// 'Super' heavy revit shit
// 'https://speckle.xyz/streams/e6f9156405/commits/0694d53bb5'
Expand All @@ -141,7 +143,7 @@ const getStream = () => {
// AutoCAD NEW
// 'https://latest.speckle.dev/streams/3ed8357f29/commits/46905429f6'
//Blizzard world
'https://latest.speckle.dev/streams/0c6ad366c4/commits/aa1c393aec'
// 'https://latest.speckle.dev/streams/0c6ad366c4/commits/aa1c393aec'
//Car
// 'https://latest.speckle.dev/streams/17d2e25a97/commits/6b6cf3d43e'
// Jonathon's
Expand Down
1 change: 1 addition & 0 deletions packages/viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
],
"dependencies": {
"@speckle/objectloader": "workspace:^",
"@speckle/shared": "workspace:^",
"@types/flat": "^5.0.2",
"camera-controls": "^1.33.1",
"flat": "^5.0.2",
Expand Down
2 changes: 2 additions & 0 deletions packages/viewer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,5 @@ export type {
MeasurementOptions,
FilteringState
}

export * as UrlHelper from './modules/UrlHelper'
Loading

0 comments on commit af8c3e1

Please sign in to comment.