Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
POC Mirador
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
Service Desk
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IIIF
POC Mirador
Commits
d36bd622
Verified
Commit
d36bd622
authored
2 years ago
by
Loïs Poujade
Browse files
Options
Downloads
Plain Diff
Merge branch 'main' into wip-all-local
parents
12e06c42
021e5f3d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/catalog.js
+53
-0
53 additions, 0 deletions
src/catalog.js
src/index.js
+15
-1
15 additions, 1 deletion
src/index.js
with
68 additions
and
1 deletion
src/catalog.js
0 → 100644
+
53
−
0
View file @
d36bd622
/*
* List .json files found in root or first subdirectory level and
* return them as a mirador catalog
* This code works for webpack dev server and caddy (as file server), and is not expected
* to function for other webservers
*/
export
default
{
// url: relative or absolute path
// depth: maximum depth for search of .json (use 0 to search only at root, 1 for first-level folders, etc)
// subfolder: only for internal usage
get_initial_catalog
:
function
(
url
=
'
/data
'
,
depth
=
1
,
subfolder
=
''
)
{
if
(
depth
<
0
)
{
return
;
}
const
req_init
=
{
headers
:
{
'
Accept
'
:
'
application/json
'
}};
return
fetch
(
`
${
url
}
/
${
subfolder
}
`
,
req_init
)
.
then
(
response
=>
{
if
(
!
response
.
ok
)
{
throw
new
Error
(
`failed to list manifests from
${
url
}
, http response code:
${
reponse
.
status
}
`
);
}
return
response
.
json
();
})
.
then
(
async
(
response_json
)
=>
{
// handling caddy response, which is like
// [{name: "first.json", ...}, {name: "second.json", ...}, ...]
if
(
response_json
.
length
>=
1
&&
response_json
[
0
].
hasOwnProperty
(
'
name
'
))
{
response_json
=
response_json
.
map
(
e
=>
e
.
name
.
replace
(
/
\/
$/
,
''
));
}
// assume all files which don't end in .json are folder
let
subfolders_content
=
await
Promise
.
allSettled
(
response_json
.
filter
(
e
=>
!
e
.
endsWith
(
'
.json
'
))
.
map
(
folder
=>
this
.
get_initial_catalog
(
url
,
depth
-
1
,
folder
))
);
// filter files from current folder
// & append files from subfolders
let
items
=
response_json
.
filter
(
e
=>
e
.
endsWith
(
'
.json
'
))
.
concat
(
subfolders_content
// get only successfull queries & with a content
.
filter
(
p
=>
p
.
status
===
"
fulfilled
"
&&
p
.
value
!=
null
)
.
map
(
p
=>
p
.
value
)
).
flat
();
// prepend with original url only if we are at the root folder,
// else prepend only with current folder
return
items
.
map
(
e
=>
subfolder
==
''
?
`
${
url
}
/
${
e
}
`
:
`
${
subfolder
}
/
${
e
}
`
);
});
}
}
This diff is collapsed.
Click to expand it.
src/index.js
+
15
−
1
View file @
d36bd622
import
Mirador
from
'
mirador/dist/es/src/index
'
;
import
LocalCatalog
from
'
./catalog.js
'
;
import
*
as
actions
from
'
mirador/dist/es/src/state/actions
'
;
import
annotationPlugins
from
'
mirador-annotations/es/index
'
;
import
LocalStorageAdapter
from
'
mirador-annotations/es/LocalStorageAdapter
'
;
import
AnnototAdapter
from
'
mirador-annotations/es/AnnototAdapter
'
;
...
...
@@ -25,4 +27,16 @@ const config = {
]
};
Mirador
.
viewer
(
config
,
[...
annotationPlugins
]);
let
viewer
=
Mirador
.
viewer
(
config
,
[...
annotationPlugins
]);
var
store
=
viewer
.
store
;
console
.
info
(
'
store:
'
,
store
);
LocalCatalog
.
get_initial_catalog
()
.
then
(
catalog
=>
{
console
.
debug
(
'
loading local catalog:
'
,
catalog
);
catalog
.
forEach
(
manifest
=>
// setTimeout avoid UI freeze
setTimeout
(()
=>
store
.
dispatch
(
actions
.
addResource
(
manifest
)),
0
)
);
})
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