Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
Hubs
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
Container Registry
Model registry
Operate
Environments
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
ar-noc
Hubs
Commits
dbeeb9b5
Commit
dbeeb9b5
authored
6 years ago
by
netpro2k
Browse files
Options
Downloads
Patches
Plain Diff
Add media index support to media-loader/reolsveMedia
parent
cfbe58c2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/components/media-loader.js
+3
-2
3 additions, 2 deletions
src/components/media-loader.js
src/utils/media-utils.js
+5
-4
5 additions, 4 deletions
src/utils/media-utils.js
with
8 additions
and
6 deletions
src/components/media-loader.js
+
3
−
2
View file @
dbeeb9b5
...
@@ -5,6 +5,7 @@ AFRAME.registerComponent("media-loader", {
...
@@ -5,6 +5,7 @@ AFRAME.registerComponent("media-loader", {
schema
:
{
schema
:
{
src
:
{
type
:
"
string
"
},
src
:
{
type
:
"
string
"
},
token
:
{
type
:
"
string
"
},
token
:
{
type
:
"
string
"
},
index
:
{
type
:
"
number
"
},
resize
:
{
default
:
false
}
resize
:
{
default
:
false
}
},
},
...
@@ -59,7 +60,7 @@ AFRAME.registerComponent("media-loader", {
...
@@ -59,7 +60,7 @@ AFRAME.registerComponent("media-loader", {
// TODO: correctly handle case where src changes
// TODO: correctly handle case where src changes
async
update
(
oldData
)
{
async
update
(
oldData
)
{
try
{
try
{
const
{
src
,
token
}
=
this
.
data
;
const
{
src
,
token
,
index
}
=
this
.
data
;
if
(
src
!==
oldData
.
src
&&
!
this
.
showLoaderTimeout
)
{
if
(
src
!==
oldData
.
src
&&
!
this
.
showLoaderTimeout
)
{
this
.
showLoaderTimeout
=
setTimeout
(
this
.
showLoader
,
100
);
this
.
showLoaderTimeout
=
setTimeout
(
this
.
showLoader
,
100
);
...
@@ -67,7 +68,7 @@ AFRAME.registerComponent("media-loader", {
...
@@ -67,7 +68,7 @@ AFRAME.registerComponent("media-loader", {
if
(
!
src
)
return
;
if
(
!
src
)
return
;
const
{
raw
,
images
,
contentType
}
=
await
resolveMedia
(
src
,
token
);
const
{
raw
,
images
,
contentType
}
=
await
resolveMedia
(
src
,
token
,
false
,
index
);
if
(
token
)
{
if
(
token
)
{
if
(
this
.
blobURL
)
{
if
(
this
.
blobURL
)
{
...
...
This diff is collapsed.
Click to expand it.
src/utils/media-utils.js
+
5
−
4
View file @
dbeeb9b5
...
@@ -17,9 +17,10 @@ const fetchContentType = async (url, token) => {
...
@@ -17,9 +17,10 @@ const fetchContentType = async (url, token) => {
};
};
const
resolveMediaCache
=
new
Map
();
const
resolveMediaCache
=
new
Map
();
export
const
resolveMedia
=
async
(
url
,
token
,
skipContentType
)
=>
{
export
const
resolveMedia
=
async
(
url
,
token
,
skipContentType
,
index
)
=>
{
const
parsedUrl
=
new
URL
(
url
);
const
parsedUrl
=
new
URL
(
url
);
if
(
resolveMediaCache
.
has
(
url
))
return
resolveMediaCache
.
get
(
url
);
const
cacheKey
=
`
${
url
}
|
${
index
}
`
;
if
(
resolveMediaCache
.
has
(
cacheKey
))
return
resolveMediaCache
.
get
(
cacheKey
);
const
isNotHttpOrHttps
=
parsedUrl
.
protocol
!==
"
http:
"
&&
parsedUrl
.
protocol
!==
"
https:
"
;
const
isNotHttpOrHttps
=
parsedUrl
.
protocol
!==
"
http:
"
&&
parsedUrl
.
protocol
!==
"
https:
"
;
const
resolved
=
const
resolved
=
...
@@ -28,7 +29,7 @@ export const resolveMedia = async (url, token, skipContentType) => {
...
@@ -28,7 +29,7 @@ export const resolveMedia = async (url, token, skipContentType) => {
:
await
fetch
(
mediaAPIEndpoint
,
{
:
await
fetch
(
mediaAPIEndpoint
,
{
method
:
"
POST
"
,
method
:
"
POST
"
,
headers
:
{
"
Content-Type
"
:
"
application/json
"
},
headers
:
{
"
Content-Type
"
:
"
application/json
"
},
body
:
JSON
.
stringify
({
media
:
{
url
}
})
body
:
JSON
.
stringify
({
media
:
{
url
,
index
}
})
}).
then
(
r
=>
r
.
json
());
}).
then
(
r
=>
r
.
json
());
if
(
!
isNotHttpOrHttps
&&
!
skipContentType
)
{
if
(
!
isNotHttpOrHttps
&&
!
skipContentType
)
{
...
@@ -37,7 +38,7 @@ export const resolveMedia = async (url, token, skipContentType) => {
...
@@ -37,7 +38,7 @@ export const resolveMedia = async (url, token, skipContentType) => {
resolved
.
contentType
=
contentType
;
resolved
.
contentType
=
contentType
;
}
}
resolveMediaCache
.
set
(
url
,
resolved
);
resolveMediaCache
.
set
(
cacheKey
,
resolved
);
return
resolved
;
return
resolved
;
};
};
...
...
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