Commit 6b64a8cc authored by Juergen Enge's avatar Juergen Enge
Browse files

iiif viewer added

parent 49490726
Pipeline #13791 passed with stages
in 3 minutes and 26 seconds
......@@ -124,7 +124,8 @@ func main() {
}
// add some helpful actions
srv.AddAction(memostream.NewImageActionIIIF(srv))
srv.AddAction(memostream.NewActionImageIIIF(srv))
srv.AddAction(memostream.NewActionMaster(srv))
go func() {
if err := srv.ListenAndServe(config.CertPEM, config.KeyPEM); err != nil {
......
......@@ -10,16 +10,16 @@ import (
)
// image Action using IIIF server for image manipulation
type ImageActionIIIF struct {
type ActionImageIIIF struct {
ms *memoServer
}
func NewImageActionIIIF(ms *memoServer) *ImageActionIIIF {
iai := &ImageActionIIIF{ms: ms}
func NewActionImageIIIF(ms *memoServer) *ActionImageIIIF {
iai := &ActionImageIIIF{ms: ms}
return iai
}
func (iai *ImageActionIIIF) GetType() []string { return []string{"image"} }
func (iai *ActionImageIIIF) GetType() []string { return []string{"image"} }
var regexpParamImageActionIIIF = []*regexp.Regexp{
regexp.MustCompile("^(size)([0-9]+)x([0-9]+)$"),
......@@ -28,11 +28,48 @@ var regexpParamImageActionIIIF = []*regexp.Regexp{
regexp.MustCompile("^(crop)$"),
}
func (iai *ImageActionIIIF) Do(w http.ResponseWriter, req *http.Request, me *MediaEntry, action string, params ...string) (bool, error) {
if action != "resize" {
return false, nil
func (iai *ActionImageIIIF) Do(w http.ResponseWriter, req *http.Request, me *MediaEntry, action string, params ...string) (bool, error) {
switch action {
case "resize":
return iai.resize(w, req, me, action, params...)
case "viewer":
return iai.viewer(w, req, me, action, params...)
default:
}
return false, nil
}
func (iai *ActionImageIIIF) viewer(w http.ResponseWriter, req *http.Request, me *MediaEntry, action string, params ...string) (bool, error) {
type vData struct {
BackgroundColor string
TileSource string
}
var err error
newtoken := ""
if me.Access != Media_Public {
newtoken, err = NewJWT(iai.ms.jwtSecret, me.Signature, iai.ms.jwtAlg[0], 7200, "", "")
if err != nil {
return false, fmt.Errorf("Cannot create token: %v", err)
}
}
tileSource := fmt.Sprintf("%s/%s/%s/iiif/info.json?auth=%s",
strings.TrimRight(iai.ms.baseUrl, "/"),
strings.Trim(iai.ms.urlPrefix, "/"),
me.Signature,
newtoken)
if me.Protocol == Media_Redirect {
tileSource = me.URI.String()
}
data := vData{
BackgroundColor: "#000000",
TileSource: tileSource,
}
iai.ms.iiifViewerTemplate.Execute(w, data)
return true, nil
}
func (iai *ActionImageIIIF) resize(w http.ResponseWriter, req *http.Request, me *MediaEntry, action string, params ...string) (bool, error) {
ps := map[string][]string{}
// create array of parameters
for _, p := range params {
......
package memostream
import (
"fmt"
"net/http"
)
// image Action using IIIF server for image manipulation
type ActionMaster struct {
ms *memoServer
}
func NewActionMaster(ms *memoServer) *ActionMaster {
am := &ActionMaster{ms: ms}
return am
}
func (am *ActionMaster) GetType() []string { return []string{"image", "video", "audio"} }
func (am *ActionMaster) Do(w http.ResponseWriter, req *http.Request, me *MediaEntry, action string, params ...string) (bool, error) {
if action != "master" {
return false, nil
}
w.Header().Set("Content-Disposition", fmt.Sprintf("filename=\"%s\"", me.Signature))
reader, modTime, err := am.ms.fspool.OpenUri(me.URI)
if err != nil {
return false, fmt.Errorf("cannot open uri %s: %v", me.URI, err)
}
defer reader.Close()
http.ServeContent(w, req, me.Signature, modTime, reader)
return true, nil
}
......@@ -144,35 +144,6 @@ func (ms *memoServer) mainHandler(w http.ResponseWriter, req *http.Request) {
ms.videoViewerTemplate.Execute(w, data)
return
}
if action == "iiif" && params == "view" {
type vData struct {
BackgroundColor string
TileSource string
}
newtoken := ""
if me.Access != Media_Public {
newtoken, err = NewJWT(ms.jwtSecret, signature, ms.jwtAlg[0], 7200, "", "")
if err != nil {
ms.DoPanicf(w, http.StatusInternalServerError, "Cannot create token: %v", err)
return
}
}
tileSource := fmt.Sprintf("%s/%s/%s/iiif/info.json?auth=%s",
strings.TrimRight(ms.baseUrl, "/"),
ms.urlPrefix,
signature,
newtoken)
if me.Protocol == Media_Redirect {
tileSource = me.URI.String()
}
data := vData{
BackgroundColor: "#000000",
TileSource: tileSource,
}
ms.iiifViewerTemplate.Execute(w, data)
return
}
if action == "iiif" && params == "info.json" {
if !ms.fspool.Exist(me.URI) {
ms.DoPanicf(w, http.StatusNotFound, "file not found: %v", me.URI)
......
Supports Markdown
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