Commit der ersten lauffähigen version
This commit is contained in:
commit
e437becb7d
36
.gitignore
vendored
Normal file
36
.gitignore
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
# ---> VisualStudioCode
|
||||
.settings
|
||||
|
||||
|
||||
# ---> Go
|
||||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
||||
|
||||
.vscode/*
|
||||
.history
|
||||
Fotos/*
|
||||
|
||||
debug
|
||||
fboxgal.arm
|
37
README.md
Normal file
37
README.md
Normal file
@ -0,0 +1,37 @@
|
||||
# Go Fotobox Galerie
|
||||
|
||||
Zum Kompilieren folgende Go-Abhängigkeiten installieren:
|
||||
- `go get github.com/gorilla/mux`
|
||||
- `go get github.com/disintegration/imaging`
|
||||
|
||||
Kompilieren mit: `go build main.go -o fboxgal.bin`
|
||||
Kompilieren unter Windows (Powesrhell) mit Zielsystem Linux/ARM: `$env:GOOS="linux"; $env:GOARCH="arm"; go build -o fboxgal.arm`
|
||||
|
||||
|
||||
**API-Endpunkte:**
|
||||
|
||||
* `/` - Ruft den Statischen Content im `web`-Verzeichnis auf
|
||||
* z.B.: http://127.0.0.1:8000/index.html
|
||||
* `/folder/{foldername:.*}` - Listet die Dateien im verzeichnis `foldername` auf
|
||||
* z.B.: http://127.0.0.1:8000/folder/2019-11-15
|
||||
* `/thumb/{imgname:.*}` - Erstellt ein Thumnail eines des Bildes `imgname` und zeigt dieses dann an
|
||||
* z.B.: http://127.0.0.1:8000/thumb/2019-11-15/IMG_4186.JPG
|
||||
* `/imgdl/{imgname:.*}` - Nimmt das Bild `imgname` und bietet es zum Download an
|
||||
* z.B.: http://127.0.0.1:8000/imgdl/2019-11-15/IMG_4186.JPG
|
||||
* `/img/`- Zeigt ein Bild aus dem Statischen Bilder-verzeichnis an
|
||||
* z.B.: http://127.0.0.1:8000/img/2019-11-15/IMG_4186.JPG
|
||||
|
||||
|
||||
**Konfiguration**
|
||||
Die Konfiguration erfolgt in der Datei `config.json`, z.B:
|
||||
```
|
||||
{
|
||||
"Host":"http://127.0.0.1",
|
||||
"Port":"8000",
|
||||
"IMGPath":"./Fotos"
|
||||
}
|
||||
```
|
||||
|
||||
**Anwendung**
|
||||
Wenn man nur die index.html aufruft (http://127.0.0.1:8000), dan bekommt man eine Auflistung der Ordner angezeigt.
|
||||
Übergibt man den Parameter `?dir` (http://127.0.0.1:8000/?dir=2019-11-15), dann bekommt man nur den Inhalt dieses Ordners angezeigt.
|
5
config.json
Normal file
5
config.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"Host":"http://127.0.0.1",
|
||||
"Port":"8000",
|
||||
"IMGPath":"./Fotos"
|
||||
}
|
141
main.go
Normal file
141
main.go
Normal file
@ -0,0 +1,141 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"image/png"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
var config = readConfig("./config.json")
|
||||
|
||||
type Configuration struct {
|
||||
Host string
|
||||
Port string
|
||||
IMGPath string
|
||||
}
|
||||
|
||||
// our main function
|
||||
func main() {
|
||||
|
||||
fmt.Println("Version: 0.1")
|
||||
fmt.Println("Host: " + config.Host)
|
||||
fmt.Println("Post: " + config.Port)
|
||||
fmt.Println("ImgPath: " + config.IMGPath)
|
||||
|
||||
router := mux.NewRouter()
|
||||
router.HandleFunc("/folder/{foldername:.*}", getFolderContent).Methods("GET")
|
||||
router.HandleFunc("/thumb/{imgname:.*}", getThumbNail).Methods("GET")
|
||||
router.HandleFunc("/imgdl/{imgname:.*}", getImageDownload).Methods("GET")
|
||||
router.PathPrefix("/img/").Handler(http.StripPrefix("/img/", http.FileServer(http.Dir(config.IMGPath)))).Methods("GET")
|
||||
router.PathPrefix("/").Handler(http.FileServer(http.Dir("web"))).Methods("GET")
|
||||
log.Fatal(http.ListenAndServe(":"+config.Port, router))
|
||||
|
||||
}
|
||||
|
||||
func getFolderContent(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
params := mux.Vars(r)
|
||||
pFolder := params["foldername"]
|
||||
fmt.Println(path.Join(config.IMGPath, pFolder))
|
||||
files, err := ioutil.ReadDir(path.Join(config.IMGPath, pFolder))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var dateien []string
|
||||
for _, f := range files {
|
||||
if !strings.HasSuffix(f.Name(), ".thumb.jpg") {
|
||||
dateien = append(dateien, f.Name())
|
||||
}
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(dateien)
|
||||
}
|
||||
|
||||
func getThumbNail(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Variablen auswerten
|
||||
params := mux.Vars(r)
|
||||
pIMGName := params["imgname"]
|
||||
|
||||
// Das Thumbnail soll nur generiert werden wenn es noch nicht existiert
|
||||
if !fileExists(config.IMGPath + "/" + pIMGName + ".thumb.jpg") {
|
||||
// Originaldatei öffnen, welche angefragt wird
|
||||
src, err := imaging.Open(config.IMGPath + "/" + pIMGName)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to open image: %v", err)
|
||||
}
|
||||
|
||||
// Thumbanil von Foto auf 200px skalieren mit 50% Qualität
|
||||
src = imaging.Resize(src, 200, 0, imaging.NearestNeighbor)
|
||||
err = imaging.Save(src, config.IMGPath+"/"+pIMGName+".thumb.jpg", imaging.JPEGQuality(50))
|
||||
if err != nil {
|
||||
log.Fatalf("failed to save image: %v", err)
|
||||
}
|
||||
|
||||
// Datei ausgeben
|
||||
png.Encode(w, src)
|
||||
} else {
|
||||
|
||||
src, err := imaging.Open(config.IMGPath + "/" + pIMGName + ".thumb.jpg")
|
||||
if err != nil {
|
||||
log.Fatalf("failed to open image: %v", err)
|
||||
}
|
||||
|
||||
// Datei ausgeben
|
||||
png.Encode(w, src)
|
||||
}
|
||||
}
|
||||
|
||||
func getImageDownload(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Variablen auswerten
|
||||
params := mux.Vars(r)
|
||||
pIMGName := params["imgname"]
|
||||
|
||||
// Originaldatei öffnen, welche angefragt wird
|
||||
src, err := imaging.Open(config.IMGPath + "/" + pIMGName)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to open image: %v", err)
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Disposition", "attachment; filename=Fotobox_"+pIMGName)
|
||||
|
||||
png.Encode(w, src)
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Hilfsfunktionen
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
func fileExists(filename string) bool {
|
||||
info, err := os.Stat(filename)
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return !info.IsDir()
|
||||
}
|
||||
|
||||
func readConfig(filename string) *Configuration {
|
||||
// initialize conf with default values.
|
||||
conf := &Configuration{Host: "http://127.0.0.1", Port: "8000", IMGPath: "./Fotos"}
|
||||
|
||||
b, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return conf
|
||||
}
|
||||
if err = json.Unmarshal(b, conf); err != nil {
|
||||
return conf
|
||||
}
|
||||
return conf
|
||||
}
|
113
web/index.html
Normal file
113
web/index.html
Normal file
@ -0,0 +1,113 @@
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link href="/misc/font.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="Ordner"></div>
|
||||
|
||||
|
||||
<script src="/misc/jquery.min.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
var Orderdirekt = getUrlParameter('dir');
|
||||
|
||||
if(Orderdirekt==undefined)
|
||||
{
|
||||
// Wenn kein Ordner übergeben wurde, dann zeigen wir die Startseite an
|
||||
ShowHomePage();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Wenn ein Order übergeben wurde, wollen wir diesen anzeigen
|
||||
ShowFolderPics(Orderdirekt);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
function ShowHomePage() {
|
||||
|
||||
$("#Ordner").empty();
|
||||
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
contentType:'application/json; charset=utf-8',
|
||||
url: '/folder/',
|
||||
dataType: "json",
|
||||
data: "",
|
||||
success: function(content){
|
||||
|
||||
//http://127.0.0.1:8000/img/2019-11-15/IMG_4186.JPG
|
||||
for ( var i = 0, l = content.length; i < l; i++ ) {
|
||||
var ObjInhalt = content[i];
|
||||
$("#Ordner").append(""+
|
||||
"<span style=\"color: gray; font-size: 30pt\" class=\"icon-folder\"></span> | "+
|
||||
"<a href=\"#\" onclick=\"ShowFolderPics('"+ObjInhalt+"')\">"+
|
||||
ObjInhalt+"</a><hr>");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function ShowFolderPics(folder) {
|
||||
|
||||
// Ordner div leeren
|
||||
$("#Ordner").empty();
|
||||
|
||||
var Orderdirekt = getUrlParameter('dir');
|
||||
if(Orderdirekt==undefined) {
|
||||
$("#Ordner").append('<a href="#" onclick=ShowHomePage()>Zurück</a><hr>');
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
contentType:'application/json; charset=utf-8',
|
||||
url: '/folder/'+folder,
|
||||
dataType: "json",
|
||||
data: "",
|
||||
success: function(content){
|
||||
|
||||
//http://127.0.0.1:8000/img/2019-11-15/IMG_4186.JPG
|
||||
for ( var i = 0, l = content.length; i < l; i++ ) {
|
||||
var ObjInhalt = content[i];
|
||||
$("#Ordner").append(""+
|
||||
"<img src=\"/thumb/"+folder+"/"+ObjInhalt+"\" width=200>"+
|
||||
"<a href=\"/imgdl/"+folder+"/"+ObjInhalt+"\">"+
|
||||
ObjInhalt+"</a><hr>");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Hilfsfunktionen
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
function getUrlParameter(sParam) {
|
||||
var sPageURL = window.location.search.substring(1),
|
||||
sURLVariables = sPageURL.split('&'),
|
||||
sParameterName,
|
||||
i;
|
||||
|
||||
for (i = 0; i < sURLVariables.length; i++) {
|
||||
sParameterName = sURLVariables[i].split('=');
|
||||
|
||||
if (sParameterName[0] === sParam) {
|
||||
return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
1500
web/misc/font.css
Normal file
1500
web/misc/font.css
Normal file
File diff suppressed because it is too large
Load Diff
BIN
web/misc/fonts/icomoon.eot
Normal file
BIN
web/misc/fonts/icomoon.eot
Normal file
Binary file not shown.
501
web/misc/fonts/icomoon.svg
Normal file
501
web/misc/fonts/icomoon.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 297 KiB |
BIN
web/misc/fonts/icomoon.ttf
Normal file
BIN
web/misc/fonts/icomoon.ttf
Normal file
Binary file not shown.
BIN
web/misc/fonts/icomoon.woff
Normal file
BIN
web/misc/fonts/icomoon.woff
Normal file
Binary file not shown.
6
web/misc/jquery.min.js
vendored
Normal file
6
web/misc/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user