Commit 997e57e7 authored by Juergen Enge's avatar Juergen Enge
Browse files

external viewer included

parent a68a6a85
Pipeline #16112 passed with stages
in 3 minutes and 54 seconds
...@@ -60,6 +60,7 @@ type Config struct { ...@@ -60,6 +60,7 @@ type Config struct {
VideoViewerTemplate string VideoViewerTemplate string
AudioViewerTemplate string AudioViewerTemplate string
FileMap []FileMap FileMap []FileMap
Viewer map[string]string
} }
func LoadConfig(filepath string) Config { func LoadConfig(filepath string) Config {
......
...@@ -113,8 +113,7 @@ func main() { ...@@ -113,8 +113,7 @@ func main() {
log, log,
accesslog, accesslog,
config.ErrorTemplate, config.ErrorTemplate,
config.VideoViewerTemplate, config.Viewer,
config.AudioViewerTemplate,
config.StaticPrefix, config.StaticPrefix,
config.StaticDir, config.StaticDir,
) )
...@@ -127,6 +126,7 @@ func main() { ...@@ -127,6 +126,7 @@ func main() {
srv.AddAction(memostream.NewActionImageIIIF(srv)) srv.AddAction(memostream.NewActionImageIIIF(srv))
srv.AddAction(memostream.NewActionVideo(srv)) srv.AddAction(memostream.NewActionVideo(srv))
srv.AddAction(memostream.NewActionAudio(srv)) srv.AddAction(memostream.NewActionAudio(srv))
srv.AddAction(memostream.NewActionExternal(srv))
srv.AddAction(memostream.NewActionMaster(srv)) srv.AddAction(memostream.NewActionMaster(srv))
go func() { go func() {
......
...@@ -13,10 +13,17 @@ jwtkey = "swordfish" ...@@ -13,10 +13,17 @@ jwtkey = "swordfish"
jwtalg = ["HS256", "HS384", "HS512"] # "hs256" "hs384" "hs512" "es256" "es384" "es512" "ps256" "ps384" "ps512" jwtalg = ["HS256", "HS384", "HS512"] # "hs256" "hs384" "hs512" "es256" "es384" "es512" "ps256" "ps384" "ps512"
resolverCacheSize = 1000 resolverCacheSize = 1000
errorTemplate = "C:/daten/go/src/gitlab.switch.ch/memoriav/memobase-2020/services/streaming-server/web/template/error.gohtml" # error message for memoHandler errorTemplate = "C:/daten/go/src/gitlab.switch.ch/memoriav/memobase-2020/services/streaming-server/web/template/error.gohtml" # error message for memoHandler
videoviewertemplate = "C:/daten/go/src/gitlab.switch.ch/memoriav/memobase-2020/services/streaming-server/web/template/video.gohtml"
audioviewertemplate = "C:/daten/go/src/gitlab.switch.ch/memoriav/memobase-2020/services/streaming-server/web/template/audio.gohtml"
baseurl = "http://localhost:88" baseurl = "http://localhost:88"
[viewer]
image = "C:/daten/go/src/gitlab.switch.ch/memoriav/memobase-2020/services/streaming-server/web/template/iiif-image.gohtml"
video = "C:/daten/go/src/gitlab.switch.ch/memoriav/memobase-2020/services/streaming-server/web/template/video.gohtml"
audio = "C:/daten/go/src/gitlab.switch.ch/memoriav/memobase-2020/services/streaming-server/web/template/audio.gohtml"
srfaudio = "C:/daten/go/src/gitlab.switch.ch/memoriav/memobase-2020/services/streaming-server/web/template/player--srg.gohtml"
srfvideo = "C:/daten/go/src/gitlab.switch.ch/memoriav/memobase-2020/services/streaming-server/web/template/player--srg.gohtml"
vimeo = "C:/daten/go/src/gitlab.switch.ch/memoriav/memobase-2020/services/streaming-server/web/template/video--vimeo.gohtml"
youtube = "C:/daten/go/src/gitlab.switch.ch/memoriav/memobase-2020/services/streaming-server/web/template/video--youtube.gohtml"
[[filemap]] [[filemap]]
alias = "c" alias = "c"
folder = "C:/" folder = "C:/"
......
...@@ -82,6 +82,6 @@ func (aa *ActionAudio) viewer(w http.ResponseWriter, req *http.Request, me *Medi ...@@ -82,6 +82,6 @@ func (aa *ActionAudio) viewer(w http.ResponseWriter, req *http.Request, me *Medi
BaseUrl: aa.ms.baseUrl, BaseUrl: aa.ms.baseUrl,
StaticPrefix: aa.ms.staticPrefix, StaticPrefix: aa.ms.staticPrefix,
} }
aa.ms.audioViewerTemplate.Execute(w, data) aa.ms.viewerTemplates["audio"].Execute(w, data)
return true, nil return true, nil
} }
package memostream
import (
"fmt"
"net/http"
"regexp"
)
// image Action using IIIF server for image manipulation
type ActionExternal struct {
ms *memoServer
}
func NewActionExternal(ms *memoServer) *ActionExternal {
ae := &ActionExternal{ms: ms}
return ae
}
func (ae *ActionExternal) GetType() []string {
return []string{"srfaudio", "srfvideo", "youtube", "vimeo"}
}
func (ae *ActionExternal) Do(w http.ResponseWriter, req *http.Request, me *MediaEntry, action string, params ...string) (bool, error) {
switch action {
case "viewer":
return ae.viewer(w, req, me, action, params...)
default:
}
return false, nil
}
var extMatches = map[string]*regexp.Regexp{
"srfvideo": regexp.MustCompile("^.+(urn:srf:video:[-0-9a-f]+)$"),
"srfaudio": regexp.MustCompile("^.+(urn:srf:audio:[-0-9a-f]+)$"),
"youtube": regexp.MustCompile("^http.+/([^/]+)$"),
"vimeo": regexp.MustCompile("^http.+/([^/]+)$"), // https://vimeo.com/289691364
}
func (ae *ActionExternal) viewer(w http.ResponseWriter, req *http.Request, me *MediaEntry, action string, params ...string) (bool, error) {
type vData struct {
Id string
BackgroundColor string
BaseUrl string
StaticPrefix string
}
data := vData{
BackgroundColor: "#000000",
BaseUrl: ae.ms.baseUrl,
StaticPrefix: ae.ms.staticPrefix,
}
rexp, ok := extMatches[me.Type]
if !ok {
return false, fmt.Errorf("no id regexp for type %s - %v", me.Type, me.Signature)
}
matches := rexp.FindStringSubmatch(me.URI.String())
if matches != nil {
data.Id = matches[1]
}
tpl, ok := ae.ms.viewerTemplates[me.Type]
if !ok {
return false, fmt.Errorf("no template for type %s - %v", me.Type, me.Signature)
}
tpl.Execute(w, data)
return true, nil
}
...@@ -65,7 +65,10 @@ func (iai *ActionImageIIIF) iiif(w http.ResponseWriter, req *http.Request, me *M ...@@ -65,7 +65,10 @@ func (iai *ActionImageIIIF) iiif(w http.ResponseWriter, req *http.Request, me *M
func (iai *ActionImageIIIF) viewer(w http.ResponseWriter, req *http.Request, me *MediaEntry, action string, params ...string) (bool, error) { func (iai *ActionImageIIIF) viewer(w http.ResponseWriter, req *http.Request, me *MediaEntry, action string, params ...string) (bool, error) {
type vData struct { type vData struct {
BackgroundColor string BackgroundColor string
Id string
TileSource string TileSource string
BaseUrl string
StaticPrefix string
} }
var err error var err error
newtoken := "" newtoken := ""
...@@ -86,9 +89,12 @@ func (iai *ActionImageIIIF) viewer(w http.ResponseWriter, req *http.Request, me ...@@ -86,9 +89,12 @@ func (iai *ActionImageIIIF) viewer(w http.ResponseWriter, req *http.Request, me
} }
data := vData{ data := vData{
BackgroundColor: "#000000", BackgroundColor: "#000000",
Id: me.Signature,
TileSource: tileSource, TileSource: tileSource,
BaseUrl: iai.ms.baseUrl,
StaticPrefix: iai.ms.staticPrefix,
} }
iai.ms.iiifViewerTemplate.Execute(w, data) iai.ms.viewerTemplates["image"].Execute(w, data)
return true, nil return true, nil
} }
......
...@@ -82,6 +82,6 @@ func (av *ActionVideo) viewer(w http.ResponseWriter, req *http.Request, me *Medi ...@@ -82,6 +82,6 @@ func (av *ActionVideo) viewer(w http.ResponseWriter, req *http.Request, me *Medi
BaseUrl: av.ms.baseUrl, BaseUrl: av.ms.baseUrl,
StaticPrefix: av.ms.staticPrefix, StaticPrefix: av.ms.staticPrefix,
} }
av.ms.videoViewerTemplate.Execute(w, data) av.ms.viewerTemplates["video"].Execute(w, data)
return true, nil return true, nil
} }
...@@ -32,29 +32,27 @@ type Sig struct { ...@@ -32,29 +32,27 @@ type Sig struct {
} }
type memoServer struct { type memoServer struct {
srv *http.Server srv *http.Server
baseUrl string baseUrl string
staticDir string staticDir string
urlPrefix string urlPrefix string
cmdPrefix string cmdPrefix string
staticPrefix string staticPrefix string
iiifPrefix string iiifPrefix string
iiifBase string iiifBase string
iiifUrl string iiifUrl string
iiifJwtSubPrefix string iiifJwtSubPrefix string
iiifViewerTemplate *template.Template viewerTemplates map[string]*template.Template
videoViewerTemplate *template.Template resolver *ResolverCache
audioViewerTemplate *template.Template host string
resolver *ResolverCache port string
host string jwtSecret string
port string jwtAlg []string
jwtSecret string log *logging.Logger
jwtAlg []string accesslog io.Writer
log *logging.Logger errorTemplate *template.Template
accesslog io.Writer fspool *FilesystemPool
errorTemplate *template.Template actions map[string][]Action
fspool *FilesystemPool
actions map[string][]Action
} }
func NewServer( func NewServer(
...@@ -73,9 +71,8 @@ func NewServer( ...@@ -73,9 +71,8 @@ func NewServer(
jwtAlg []string, jwtAlg []string,
log *logging.Logger, log *logging.Logger,
accesslog io.Writer, accesslog io.Writer,
errorTemplate, errorTemplate string,
videoViewerTemplate, viewer map[string]string,
audioViewerTemplate,
staticPrefix, staticPrefix,
staticDir string) (*memoServer, error) { staticDir string) (*memoServer, error) {
urlPrefix = "/" + strings.Trim(urlPrefix, "/") + "/" urlPrefix = "/" + strings.Trim(urlPrefix, "/") + "/"
...@@ -85,17 +82,13 @@ func NewServer( ...@@ -85,17 +82,13 @@ func NewServer(
//log.Panicf("cannot split address %s: %v", addr, err) //log.Panicf("cannot split address %s: %v", addr, err)
return nil, emperror.Wrapf(err, "cannot split address %s", addr) return nil, emperror.Wrapf(err, "cannot split address %s", addr)
} }
iiifTpl, err := template.ParseFiles(iiifViewerTemplate)
if err != nil { vs := make(map[string]*template.Template)
return nil, emperror.Wrapf(err, "cannot parse iiif template %s", iiifViewerTemplate) for key, file := range viewer {
} vs[key], err = template.ParseFiles(file)
videoTpl, err := template.ParseFiles(videoViewerTemplate) if err != nil {
if err != nil { return nil, emperror.Wrapf(err, "cannot parse %s template %s", key, file)
return nil, emperror.Wrapf(err, "cannot parse videoViewer template %s", videoViewerTemplate) }
}
audioTpl, err := template.ParseFiles(audioViewerTemplate)
if err != nil {
return nil, emperror.Wrapf(err, "cannot parse audioViewer template %s", audioViewerTemplate)
} }
errorTpl, err := template.ParseFiles(errorTemplate) errorTpl, err := template.ParseFiles(errorTemplate)
if err != nil { if err != nil {
...@@ -104,28 +97,26 @@ func NewServer( ...@@ -104,28 +97,26 @@ func NewServer(
return &memoServer{ return &memoServer{
//mh: NewMemoHandler(baseDir, urlPrefix, resolver, jwtSecret, log, errorTemplate), //mh: NewMemoHandler(baseDir, urlPrefix, resolver, jwtSecret, log, errorTemplate),
baseUrl: baseUrl, baseUrl: baseUrl,
resolver: resolver, resolver: resolver,
fspool: mapping, fspool: mapping,
urlPrefix: urlPrefix, urlPrefix: urlPrefix,
cmdPrefix: cmdPrefix, cmdPrefix: cmdPrefix,
iiifPrefix: iiifPrefix, iiifPrefix: iiifPrefix,
iiifBase: iiifBase, iiifBase: iiifBase,
iiifUrl: iiifUrl, iiifUrl: iiifUrl,
iiifJwtSubPrefix: iiifJwtSubPrefix, iiifJwtSubPrefix: iiifJwtSubPrefix,
iiifViewerTemplate: iiifTpl, viewerTemplates: vs,
videoViewerTemplate: videoTpl, host: host,
audioViewerTemplate: audioTpl, port: port,
host: host, jwtSecret: jwtSecret,
port: port, jwtAlg: jwtAlg,
jwtSecret: jwtSecret, log: log,
jwtAlg: jwtAlg, accesslog: accesslog,
log: log, errorTemplate: errorTpl,
accesslog: accesslog, staticPrefix: staticPrefix,
errorTemplate: errorTpl, staticDir: staticDir,
staticPrefix: staticPrefix, actions: map[string][]Action{},
staticDir: staticDir,
actions: map[string][]Action{},
}, nil }, nil
} }
......
...@@ -45,3 +45,42 @@ body { ...@@ -45,3 +45,42 @@ body {
height: 100%; height: 100%;
overflow: hidden; overflow: hidden;
} }
/* Mobile */
@media only screen
and (min-device-width: 320px)
and (max-device-width: 767px) {
.openseadragon-viewer {
height: 250px;
width: 300px;
}
}
/* Tablet */
@media only screen
and (min-device-width: 768px)
and (max-device-width: 1023px) {
.openseadragon-viewer {
height: 300px;
width: 400px;
}
}
/* Tablet Landscape */
@media only screen
and (min-device-width: 1024px)
and (max-device-width: 1279px) {
.openseadragon-viewer {
height: 400px;
width: 500px;
}
}
/* Desktop */
@media only screen
and (min-device-width: 1280px) {
.openseadragon-viewer {
height: 500px;
width: 700px;
}
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Media Player</title>
<link rel="stylesheet" type="text/css" href="{{.BaseUrl}}{{.StaticPrefix}}css/style.css">
<script src="{{.BaseUrl}}{{.StaticPrefix}}js/jquery.min.js"></script>
<script src="{{.BaseUrl}}{{.StaticPrefix}}openseadragon-bin-2.4.2/openseadragon.js"></script>
<!-- <script src="{{.BaseUrl}}{{.StaticPrefix}}js/openseadragon-viewer.js"></script> -->
<script>
$(document).ready(function () {
$('.openseadragon-viewer').each(function () {
let openseadragon = $(this);
$.ajax({
type: 'GET',
url: '{{.TileSource}}',
success: function (data) {
let options = {
id: openseadragon.attr('data-image-id'),
tileSources: data,
prefixUrl: `{{.BaseUrl}}{{.StaticPrefix}}openseadragon-bin-2.4.2/images/`
};
let viewer = new OpenSeadragon.Viewer(options);
}
});
});
});
</script>
</head>
<body>
<div class="openseadragon-viewer" id="{{.Id}}" data-image-id="{{.Id}}"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Media Player</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script src="js/jquery.min.js"></script>
<script src="openseadragon-bin-2.4.2/openseadragon.js"></script>
<script src="js/openseadragon-viewer.js"></script>
</head>
<body>
<div class="openseadragon-viewer" id="BAZ-B_MEI-MEI_49905a-1" data-image-id="BAZ-B_MEI-MEI_49905a-1"></div>
</body>
</html>
...@@ -3,15 +3,15 @@ ...@@ -3,15 +3,15 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Media Player</title> <title>Media Player</title>
<link rel="stylesheet" type="text/css" href="css/style.css"> <link rel="stylesheet" type="text/css" href="{{.BaseUrl}}{{.StaticPrefix}}css/style.css">
<script src="js/jquery.min.js"></script> <script src="{{.BaseUrl}}{{.StaticPrefix}}js/jquery.min.js"></script>
<script src="js/srg-player-api.min.js"></script> <script src="{{.BaseUrl}}{{.StaticPrefix}}js/srg-player-api.min.js"></script>
<script src="js/player--srg.js"></script> <script src="{{.BaseUrl}}{{.StaticPrefix}}js/player--srg.js"></script>
</head> </head>
<body> <body>
<!-- SRG --> <!-- SRG -->
<div id="srg-player" class="player player--srg" data-urn-src="urn:srf:video:3832c22e-7a7a-4b21-be19-9916e3a9bda7"></div> <div id="srg-player" class="player player--srg" data-urn-src="{{.Id}}"></div>
</body> </body>
</html> </html>
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Media Player</title> <title>Media Player</title>
<link rel="stylesheet" type="text/css" href="css/plyr.css"> <link rel="stylesheet" type="text/css" href="{{.BaseUrl}}{{.StaticPrefix}}css/plyr.css">
<link rel="stylesheet" type="text/css" href="css/style.css"> <link rel="stylesheet" type="text/css" href="{{.BaseUrl}}{{.StaticPrefix}}css/style.css">
<script src="js/plyr.js"></script> <script src="{{.BaseUrl}}{{.StaticPrefix}}js/plyr.js"></script>
<script src="js/jquery.min.js"></script> <script src="{{.BaseUrl}}{{.StaticPrefix}}js/jquery.min.js"></script>
<script src="js/player.js"></script> <script src="{{.BaseUrl}}{{.StaticPrefix}}js/player.js"></script>
</head> </head>
<body> <body>
<!-- VIMEO --> <!-- VIMEO -->
<div class="player" data-plyr-provider="vimeo" data-plyr-embed-id="259411563"></div> <div class="player" data-plyr-provider="vimeo" data-plyr-embed-id="{{.Id}}"></div>
</body> </body>
</html> </html>
...@@ -3,16 +3,16 @@ ...@@ -3,16 +3,16 @@
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Media Player</title> <title>Media Player</title>
<link rel="stylesheet" type="text/css" href="css/plyr.css"> <link rel="stylesheet" type="text/css" href="{{.BaseUrl}}{{.StaticPrefix}}css/plyr.css">
<link rel="stylesheet" type="text/css" href="css/style.css"> <link rel="stylesheet" type="text/css" href="{{.BaseUrl}}{{.StaticPrefix}}css/style.css">
<script src="js/plyr.js"></script> <script src="{{.BaseUrl}}{{.StaticPrefix}}js/plyr.js"></script>
<script src="js/jquery.min.js"></script> <script src="{{.BaseUrl}}{{.StaticPrefix}}js/jquery.min.js"></script>
<script src="js/player.js"></script> <script src="{{.BaseUrl}}{{.StaticPrefix}}js/player.js"></script>
</head> </head>
<body> <body>
<!-- YOUTUBE --> <!-- YOUTUBE -->
<div class="player" data-plyr-provider="youtube" data-plyr-embed-id="kY1F_Y0GniQ"></div> <div class="player" data-plyr-provider="youtube" data-plyr-embed-id="{{.Id}}"></div>
</body> </body>
</html> </html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment