Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Molstar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michal Malý
Molstar
Commits
dafa9469
Commit
dafa9469
authored
5 years ago
by
Alexander Rose
Browse files
Options
Downloads
Patches
Plain Diff
Asset.getUrlAsset support body
parent
573c2a7a
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/mol-plugin-state/transforms/data.ts
+1
-1
1 addition, 1 deletion
src/mol-plugin-state/transforms/data.ts
src/mol-util/assets.ts
+19
-15
19 additions, 15 deletions
src/mol-util/assets.ts
src/mol-util/data-source.ts
+2
-2
2 additions, 2 deletions
src/mol-util/data-source.ts
with
22 additions
and
18 deletions
src/mol-plugin-state/transforms/data.ts
+
1
−
1
View file @
dafa9469
...
@@ -47,7 +47,7 @@ const Download = PluginStateTransform.BuiltIn({
...
@@ -47,7 +47,7 @@ const Download = PluginStateTransform.BuiltIn({
})({
})({
apply
({
params
:
p
,
cache
},
plugin
:
PluginContext
)
{
apply
({
params
:
p
,
cache
},
plugin
:
PluginContext
)
{
return
Task
.
create
(
'
Download
'
,
async
ctx
=>
{
return
Task
.
create
(
'
Download
'
,
async
ctx
=>
{
let
url
=
Asset
.
getUrlAsset
(
p
.
url
,
plugin
.
managers
.
asset
);
let
url
=
Asset
.
getUrlAsset
(
plugin
.
managers
.
asset
,
p
.
url
);
const
asset
=
await
plugin
.
managers
.
asset
.
resolve
(
url
,
p
.
isBinary
?
'
binary
'
:
'
string
'
).
runInContext
(
ctx
);
const
asset
=
await
plugin
.
managers
.
asset
.
resolve
(
url
,
p
.
isBinary
?
'
binary
'
:
'
string
'
).
runInContext
(
ctx
);
(
cache
as
any
).
asset
=
asset
;
(
cache
as
any
).
asset
=
asset
;
return
p
.
isBinary
return
p
.
isBinary
...
...
This diff is collapsed.
Click to expand it.
src/mol-util/assets.ts
+
19
−
15
View file @
dafa9469
...
@@ -35,24 +35,28 @@ namespace Asset {
...
@@ -35,24 +35,28 @@ namespace Asset {
return
x
?.
kind
===
'
file
'
;
return
x
?.
kind
===
'
file
'
;
}
}
export
class
Wrapper
<
T
extends
DataType
=
DataType
>
{
export
interface
Wrapper
<
T
extends
DataType
=
DataType
>
{
dispose
()
{
readonly
data
:
DataResponse
<
T
>
this
.
manager
.
release
(
this
.
asset
);
dispose
:
()
=>
void
}
}
constructor
(
public
readonly
data
:
DataResponse
<
T
>
,
private
asset
:
Asset
,
private
manager
:
AssetManager
)
{
}
export
function
Wrapper
<
T
extends
DataType
=
DataType
>
(
data
:
DataResponse
<
T
>
,
asset
:
Asset
,
manager
:
AssetManager
)
{
return
{
data
,
dispose
:
()
=>
{
manager
.
release
(
asset
);
}
};
}
}
export
function
getUrl
(
url
:
string
|
Url
)
{
export
function
getUrl
(
url
:
string
|
Url
)
{
return
typeof
url
===
'
string
'
?
url
:
url
.
url
;
return
typeof
url
===
'
string
'
?
url
:
url
.
url
;
}
}
export
function
getUrlAsset
(
url
:
string
|
Url
,
manager
:
AssetManager
)
{
export
function
getUrlAsset
(
manager
:
AssetManager
,
url
:
string
|
Url
,
body
?:
string
)
{
if
(
typeof
url
===
'
string
'
)
{
if
(
typeof
url
===
'
string
'
)
{
const
asset
=
manager
.
tryFindUrl
(
url
);
const
asset
=
manager
.
tryFindUrl
(
url
,
body
);
return
asset
||
Url
(
url
);
return
asset
||
Url
(
url
,
{
body
}
);
}
}
return
url
;
return
url
;
}
}
...
@@ -88,24 +92,24 @@ class AssetManager {
...
@@ -88,24 +92,24 @@ class AssetManager {
if
(
this
.
_assets
.
has
(
asset
.
id
))
{
if
(
this
.
_assets
.
has
(
asset
.
id
))
{
const
entry
=
this
.
_assets
.
get
(
asset
.
id
)
!
;
const
entry
=
this
.
_assets
.
get
(
asset
.
id
)
!
;
entry
.
refCount
++
;
entry
.
refCount
++
;
return
new
Asset
.
Wrapper
(
await
readFromFile
(
entry
.
file
,
type
).
runInContext
(
ctx
),
asset
,
this
);
return
Asset
.
Wrapper
(
await
readFromFile
(
entry
.
file
,
type
).
runInContext
(
ctx
),
asset
,
this
);
}
}
if
(
!
store
)
{
if
(
!
store
)
{
return
new
Asset
.
Wrapper
(
await
ajaxGet
({
...
asset
,
type
}).
runInContext
(
ctx
),
asset
,
this
);
return
Asset
.
Wrapper
(
await
ajaxGet
({
...
asset
,
type
}).
runInContext
(
ctx
),
asset
,
this
);
}
}
const
data
=
await
ajaxGet
({
...
asset
,
type
:
'
binary
'
}).
runInContext
(
ctx
);
const
data
=
await
ajaxGet
({
...
asset
,
type
:
'
binary
'
}).
runInContext
(
ctx
);
const
file
=
new
File
([
data
],
'
raw-data
'
);
const
file
=
new
File
([
data
],
'
raw-data
'
);
this
.
_assets
.
set
(
asset
.
id
,
{
asset
,
file
,
refCount
:
1
});
this
.
_assets
.
set
(
asset
.
id
,
{
asset
,
file
,
refCount
:
1
});
return
new
Asset
.
Wrapper
(
await
readFromFile
(
file
,
type
).
runInContext
(
ctx
),
asset
,
this
);
return
Asset
.
Wrapper
(
await
readFromFile
(
file
,
type
).
runInContext
(
ctx
),
asset
,
this
);
});
});
}
else
{
}
else
{
return
Task
.
create
(
`Read
${
asset
.
name
}
`
,
async
ctx
=>
{
return
Task
.
create
(
`Read
${
asset
.
name
}
`
,
async
ctx
=>
{
if
(
this
.
_assets
.
has
(
asset
.
id
))
{
if
(
this
.
_assets
.
has
(
asset
.
id
))
{
const
entry
=
this
.
_assets
.
get
(
asset
.
id
)
!
;
const
entry
=
this
.
_assets
.
get
(
asset
.
id
)
!
;
entry
.
refCount
++
;
entry
.
refCount
++
;
return
new
Asset
.
Wrapper
(
await
readFromFile
(
entry
.
file
,
type
).
runInContext
(
ctx
),
asset
,
this
);
return
Asset
.
Wrapper
(
await
readFromFile
(
entry
.
file
,
type
).
runInContext
(
ctx
),
asset
,
this
);
}
}
if
(
!
(
asset
.
file
instanceof
File
))
{
if
(
!
(
asset
.
file
instanceof
File
))
{
throw
new
Error
(
`Cannot resolve file asset '
${
asset
.
name
}
' (
${
asset
.
id
}
)`
);
throw
new
Error
(
`Cannot resolve file asset '
${
asset
.
name
}
' (
${
asset
.
id
}
)`
);
...
@@ -113,7 +117,7 @@ class AssetManager {
...
@@ -113,7 +117,7 @@ class AssetManager {
if
(
store
)
{
if
(
store
)
{
this
.
_assets
.
set
(
asset
.
id
,
{
asset
,
file
:
asset
.
file
,
refCount
:
1
});
this
.
_assets
.
set
(
asset
.
id
,
{
asset
,
file
:
asset
.
file
,
refCount
:
1
});
}
}
return
new
Asset
.
Wrapper
(
await
readFromFile
(
asset
.
file
,
type
).
runInContext
(
ctx
),
asset
,
this
);
return
Asset
.
Wrapper
(
await
readFromFile
(
asset
.
file
,
type
).
runInContext
(
ctx
),
asset
,
this
);
});
});
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/mol-util/data-source.ts
+
2
−
2
View file @
dafa9469
...
@@ -293,7 +293,7 @@ export async function ajaxGetMany(ctx: RuntimeContext, assetManager: AssetManage
...
@@ -293,7 +293,7 @@ export async function ajaxGetMany(ctx: RuntimeContext, assetManager: AssetManage
const
current
=
sources
[
currentSrc
];
const
current
=
sources
[
currentSrc
];
promises
.
push
(
wrapPromise
(
currentSrc
,
current
.
id
,
promises
.
push
(
wrapPromise
(
currentSrc
,
current
.
id
,
assetManager
.
resolve
(
Asset
.
getUrlAsset
(
current
.
url
,
assetManager
),
current
.
isBinary
?
'
binary
'
:
'
string
'
).
runAsChild
(
ctx
)));
assetManager
.
resolve
(
Asset
.
getUrlAsset
(
assetManager
,
current
.
url
),
current
.
isBinary
?
'
binary
'
:
'
string
'
).
runAsChild
(
ctx
)));
promiseKeys
.
push
(
currentSrc
);
promiseKeys
.
push
(
currentSrc
);
}
}
...
@@ -315,7 +315,7 @@ export async function ajaxGetMany(ctx: RuntimeContext, assetManager: AssetManage
...
@@ -315,7 +315,7 @@ export async function ajaxGetMany(ctx: RuntimeContext, assetManager: AssetManage
promiseKeys
=
promiseKeys
.
filter
(
_filterRemoveIndex
,
idx
);
promiseKeys
=
promiseKeys
.
filter
(
_filterRemoveIndex
,
idx
);
if
(
currentSrc
<
len
)
{
if
(
currentSrc
<
len
)
{
const
current
=
sources
[
currentSrc
];
const
current
=
sources
[
currentSrc
];
const
asset
=
assetManager
.
resolve
(
Asset
.
getUrlAsset
(
current
.
url
,
assetManager
),
current
.
isBinary
?
'
binary
'
:
'
string
'
).
runAsChild
(
ctx
);
const
asset
=
assetManager
.
resolve
(
Asset
.
getUrlAsset
(
assetManager
,
current
.
url
),
current
.
isBinary
?
'
binary
'
:
'
string
'
).
runAsChild
(
ctx
);
promises
.
push
(
wrapPromise
(
currentSrc
,
current
.
id
,
asset
));
promises
.
push
(
wrapPromise
(
currentSrc
,
current
.
id
,
asset
));
promiseKeys
.
push
(
currentSrc
);
promiseKeys
.
push
(
currentSrc
);
currentSrc
++
;
currentSrc
++
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment