-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d07c0c1
Showing
10 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Anders Milje <git@milje.me> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Lightweight Image Viewer | ||
A lightweight, browser-based image viewer originally made to view enormous amounts of images on headless servers. | ||
|
||
I suggest not running this on any port that is open to the internet. | ||
|
||
## How to run it | ||
|
||
```go run main.go``` | ||
|
||
The program is now listening on port `8080` | ||
|
||
## How to use it | ||
|
||
Everything after the port in the URL is considered a path to a directory. | ||
To view the example images you have to visit this URL in your browser: | ||
```http://localhost:8080/tmp/ImageLight/examples``` | ||
|
||
![](examples/example0.png) | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Image Viwer</title> | ||
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700" rel="stylesheet"> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> | ||
<!--<link rel="stylesheet" href="https://unpkg.com/purecss@0.6.2/build/pure-min.css" integrity="sha384-UQiGfs9ICog+LwheBSRCt1o5cbyKIHbwjWscjemyBMT9YCUMZffs6UqUTd0hObXD" crossorigin="anonymous">--> | ||
<style media="screen"> | ||
|
||
* { | ||
margin: 0; | ||
padding: 0; | ||
|
||
font-family: "Helvetica"; | ||
/*background-color: #FFFDFD;*/ | ||
} | ||
|
||
/* medium screens */ | ||
@media all and (min-width: 600px) { | ||
|
||
} | ||
|
||
.container { | ||
display: flex; | ||
flex-flow: row wrap; | ||
justify-content: space-around; | ||
align-content: flex-start; | ||
align-items: center; | ||
} | ||
|
||
.image { | ||
flex-basis: auto; | ||
max-width: 400px; | ||
/*background-color: blue;*/ | ||
vertical-align: middle; | ||
height: 100%; | ||
align-self: center; | ||
margin: 3px; | ||
} | ||
|
||
.image img { | ||
max-width: 400px; | ||
border: 2px solid #E7E5E5; | ||
margin: 0 auto; | ||
} | ||
|
||
.image .link a { | ||
color: #b3b3b3; | ||
text-align: center; | ||
} | ||
|
||
.dirs, #show, #hide:target { | ||
display: none; | ||
} | ||
|
||
#hide:target + #show, #hide:target ~ .dirs { | ||
display: inline; | ||
} | ||
|
||
</style> | ||
<!--<link rel="stylesheet" href="/static/main.css">--> | ||
</head> | ||
<body> | ||
<a href="#hide" id="hide">Expand directory list ></a> | ||
<a href="#show" id="show">Hide directory list <</a> | ||
<div class="dirs"> | ||
<p>Directories</p> | ||
{{ range .Dirs }} | ||
<a href="{{.}}">{{.}}</a><br> | ||
{{ end }} | ||
</div> | ||
|
||
<div class="container"> | ||
{{ range .Files }} | ||
<div class="image"> | ||
<a href="/image/{{.}}"><img src="/image/{{.}}" alt=""></a> | ||
<p class="link"><a href="/image/{{.}}">{{.}}</a></p> | ||
</div> | ||
{{ end }} | ||
</div> | ||
|
||
<script src="/static/main.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"html/template" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
type Page struct { | ||
Title string | ||
Body []byte | ||
Files []string | ||
Dirs []string | ||
CurrDir string | ||
} | ||
|
||
func serveImage(w http.ResponseWriter, r *http.Request) { | ||
filename := r.URL.Path[len("/image"):] | ||
//body := r.FormValue("fn") | ||
log.Printf("Filename: %s", filename) | ||
file, err := os.Open(filename) | ||
if err != nil { | ||
log.Printf("Error: %s", err) | ||
} | ||
file.Close() | ||
//image, err := ioutil.ReadFile(filename) | ||
//if err != nil { | ||
//fmt.Fprintf(w, "<h1>%s</h1>", err) | ||
//} | ||
http.ServeFile(w, r, filename) | ||
} | ||
|
||
func loadPage(title, directory string) (*Page, error) { | ||
searchDir := directory //"/home/syn/Dropbox/Dev/2017/ImageLight" | ||
//searchDir := "/home/syn/images/test11" | ||
fileList := []string{} | ||
dirList := []string{} | ||
dirList = append(dirList, filepath.Dir(directory)) | ||
err := filepath.Walk(searchDir, func(path string, f os.FileInfo, err error) error { | ||
ext := filepath.Ext(path) | ||
if f.IsDir() { | ||
dirList = append(dirList, path) | ||
//log.Printf("Directory: %s", path) | ||
//log.Printf("Dirdir: %s", filepath.Dir(path)) | ||
} | ||
if ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".gif" || ext == ".mp4" { | ||
fileList = append(fileList, path) | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
filename := title + ".html" | ||
body, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &Page{Title: title, Body: body, Files: fileList, Dirs: dirList}, nil | ||
} | ||
|
||
func indexHandler(w http.ResponseWriter, r *http.Request) { | ||
directory := r.URL.Path | ||
log.Printf(directory) | ||
p, err := loadPage("index", directory) | ||
if err != nil { | ||
p = &Page{Title: "index"} | ||
} | ||
t, _ := template.ParseFiles("index.html") | ||
t.Execute(w, p) | ||
} | ||
|
||
func handler(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprintf(w, "Hello %s!", r.URL.Path[1:]) | ||
} | ||
|
||
// http://www.alexedwards.net/blog/serving-static-sites-with-go | ||
func main() { | ||
|
||
http.HandleFunc("/", indexHandler) | ||
http.HandleFunc("/image/", serveImage) | ||
|
||
fs := http.FileServer(http.Dir("static")) | ||
http.Handle("/static/", http.StripPrefix("/static/", fs)) | ||
//http.HandleFunc() | ||
|
||
log.Println("Listening...") | ||
|
||
http.ListenAndServe(":8080", nil) | ||
} |