filer: added QR code to transfer files with mobile devices
This commit is contained in:
@@ -2,6 +2,9 @@ package weed_server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"github.com/skip2/go-qrcode"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -65,21 +68,30 @@ func (fs *FilerServer) listDirectoryHandler(w http.ResponseWriter, r *http.Reque
|
||||
lastFileName,
|
||||
shouldDisplayLoadMore,
|
||||
})
|
||||
} else {
|
||||
ui.StatusTpl.Execute(w, struct {
|
||||
Path string
|
||||
Breadcrumbs []ui.Breadcrumb
|
||||
Entries interface{}
|
||||
Limit int
|
||||
LastFileName string
|
||||
ShouldDisplayLoadMore bool
|
||||
}{
|
||||
path,
|
||||
ui.ToBreadcrumb(path),
|
||||
entries,
|
||||
limit,
|
||||
lastFileName,
|
||||
shouldDisplayLoadMore,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var qrImageString string
|
||||
img, err := qrcode.Encode(fmt.Sprintf("http://%s:%d%s", fs.option.Host, fs.option.Port, r.URL.Path), qrcode.Medium, 128)
|
||||
if err == nil {
|
||||
qrImageString = base64.StdEncoding.EncodeToString(img)
|
||||
}
|
||||
|
||||
ui.StatusTpl.Execute(w, struct {
|
||||
Path string
|
||||
Breadcrumbs []ui.Breadcrumb
|
||||
Entries interface{}
|
||||
Limit int
|
||||
LastFileName string
|
||||
ShouldDisplayLoadMore bool
|
||||
QrImage string
|
||||
}{
|
||||
path,
|
||||
ui.ToBreadcrumb(path),
|
||||
entries,
|
||||
limit,
|
||||
lastFileName,
|
||||
shouldDisplayLoadMore,
|
||||
qrImageString,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -21,9 +21,11 @@ var funcMap = template.FuncMap{
|
||||
var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>SeaweedFS Filer</title>
|
||||
<link rel="stylesheet" href="/seaweedfsstatic/bootstrap/3.3.1/css/bootstrap.min.css">
|
||||
<title>SeaweedFS Filer</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" href="/seaweedfsstatic/bootstrap/3.3.1/css/bootstrap.min.css">
|
||||
<style>
|
||||
body { padding-bottom: 70px; }
|
||||
#drop-area {
|
||||
border: 1px transparent;
|
||||
}
|
||||
@@ -46,6 +48,11 @@ var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOC
|
||||
#fileElem {
|
||||
display: none;
|
||||
}
|
||||
.qrImage {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -116,6 +123,14 @@ var StatusTpl = template.Must(template.New("status").Funcs(funcMap).Parse(`<!DOC
|
||||
</a>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<div class="navbar navbar-fixed-bottom">
|
||||
<img src="data:image/png;base64,{{.QrImage}}" class="qrImage" />
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
<script type="text/javascript">
|
||||
|
||||
Reference in New Issue
Block a user