implement tempaltes
BIN
Advertisement_Panel
Executable file
12
README.md
@@ -1,9 +1,17 @@
|
|||||||
# Advertisement_Panel
|
# Advertisement_Panel
|
||||||
|
|
||||||
## How To Run This Project
|
## How To Run This Project
|
||||||
```bash
|
```bash
|
||||||
go run main.go
|
go run main.go
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Make the screen not turn off by
|
||||||
|
```bash
|
||||||
|
xset -dpms
|
||||||
|
xset s off
|
||||||
|
xset s noblank
|
||||||
|
```
|
||||||
|
|
||||||
## How To Add To This Project
|
## How To Add To This Project
|
||||||
This project is written with go, and has hot realoding (rebuilding when sensing changes) for the main.go
|
This project is written with go, and has hot realoding (rebuilding when sensing changes) for the main.go
|
||||||
|
|
||||||
@@ -23,7 +31,9 @@ $(go env GOPATH)/bin/air -c .air.toml
|
|||||||
- [ ] ATB integration
|
- [ ] ATB integration
|
||||||
- [ ] ASCII ART support
|
- [ ] ASCII ART support
|
||||||
- [ ] show more spicy images after kl 22:00
|
- [ ] show more spicy images after kl 22:00
|
||||||
- [ ] more images???
|
- [ ] Hide mouse cursor
|
||||||
|
- [ ] more images and memes???
|
||||||
|
|
||||||
|
|
||||||
# NB!!!!
|
# NB!!!!
|
||||||
Changes in the static directory will not rebuild the project, simple workaround is to just make a small change in main.go and save, for example adding a space
|
Changes in the static directory will not rebuild the project, simple workaround is to just make a small change in main.go and save, for example adding a space
|
||||||
|
58
file_handlers.go
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const staticDir = "static"
|
||||||
|
|
||||||
|
// move FileData and AsciiEntry here if you want, or leave in main.go
|
||||||
|
func file_handler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
data := FileData{
|
||||||
|
ImageNames: []string{},
|
||||||
|
SpicyImageNames: []string{},
|
||||||
|
AsciiFiles: []AsciiEntry{},
|
||||||
|
}
|
||||||
|
|
||||||
|
dirs, err := os.ReadDir(staticDir)
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, dir := range dirs {
|
||||||
|
dirName := dir.Name()
|
||||||
|
|
||||||
|
if strings.EqualFold(dirName, "images") {
|
||||||
|
|
||||||
|
files, _ := os.ReadDir(filepath.Join(staticDir, dirName))
|
||||||
|
for _, file := range files {
|
||||||
|
fileName := file.Name()
|
||||||
|
data.ImageNames = append(data.ImageNames, filepath.Join(staticDir, dirName, fileName))
|
||||||
|
}
|
||||||
|
} else if strings.EqualFold(dirName, "spicy") {
|
||||||
|
|
||||||
|
files, _ := os.ReadDir(filepath.Join(staticDir, dirName))
|
||||||
|
for _, file := range files {
|
||||||
|
fileName := file.Name()
|
||||||
|
data.SpicyImageNames = append(data.SpicyImageNames, filepath.Join(staticDir, dirName, fileName))
|
||||||
|
}
|
||||||
|
} else if strings.EqualFold(dirName, "ascii_art") {
|
||||||
|
|
||||||
|
files, _ := os.ReadDir(filepath.Join(staticDir, dirName))
|
||||||
|
for _, file := range files {
|
||||||
|
fileName := file.Name()
|
||||||
|
data.AsciiFiles = append(data.AsciiFiles,
|
||||||
|
AsciiEntry{Name: filepath.Join(staticDir, dirName, fileName), FontSize: 12},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(data)
|
||||||
|
}
|
52
main.go
@@ -1,48 +1,48 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type FileData struct {
|
||||||
|
ImageNames []string
|
||||||
|
SpicyImageNames []string
|
||||||
|
AsciiFiles []AsciiEntry
|
||||||
|
}
|
||||||
|
|
||||||
|
type AsciiEntry struct {
|
||||||
|
Name string
|
||||||
|
FontSize int
|
||||||
|
}
|
||||||
|
|
||||||
|
var templ *template.Template
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Print("Now running server!")
|
templ, _ = template.ParseGlob("templates/*.html")
|
||||||
|
|
||||||
|
fmt.Print("Now running server!\n")
|
||||||
// Serves index
|
// Serves index
|
||||||
http.HandleFunc("/", index_handler)
|
http.HandleFunc("/", index_handler)
|
||||||
|
|
||||||
// Serves json for html to find file names
|
// Serves json for html to find file names
|
||||||
http.HandleFunc("/files", files_handler)
|
http.HandleFunc("/files", file_handler)
|
||||||
|
|
||||||
|
// Serves ascii page
|
||||||
|
http.HandleFunc("/ascii", ascii_handler)
|
||||||
|
|
||||||
// Serves images
|
// Serves images
|
||||||
http.Handle("/images/", http.StripPrefix("/images/", http.FileServer(http.Dir("./static"))))
|
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static"))))
|
||||||
|
|
||||||
// Serves what ever the user is requesting based on above urls
|
// Serves what ever the user is requesting base on above urls
|
||||||
http.ListenAndServe(":8080", nil)
|
http.ListenAndServe(":8080", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func index_handler(w http.ResponseWriter, r *http.Request) {
|
func index_handler(w http.ResponseWriter, r *http.Request) {
|
||||||
http.ServeFile(w, r, "./static/index.html")
|
templ.ExecuteTemplate(w, "images.html", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func files_handler(w http.ResponseWriter, r *http.Request) {
|
func ascii_handler(w http.ResponseWriter, r *http.Request) {
|
||||||
files, err := os.ReadDir("./static")
|
templ.ExecuteTemplate(w, "ascii.html", nil)
|
||||||
if err != nil {
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var names []string
|
|
||||||
for _, f := range files {
|
|
||||||
name := f.Name()
|
|
||||||
if strings.HasSuffix(name, ".jpg") ||
|
|
||||||
strings.HasSuffix(name, ".png") ||
|
|
||||||
strings.HasSuffix(name, ".gif") {
|
|
||||||
names = append(names, "/images/"+name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
json.NewEncoder(w).Encode(names)
|
|
||||||
}
|
}
|
||||||
|
29
static/ascii_art/horse.txt
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
Y8baadP""""""""Yba,_
|
||||||
|
aaadP"' `""Yb,
|
||||||
|
`Y8( `"Yb,
|
||||||
|
`Y, `Yba,
|
||||||
|
Y, (O) `Yba,
|
||||||
|
`Y, ""Yba,________,,aaddddbbbaa,,____,aa,_
|
||||||
|
`Y, ,aa `""""""""""'' ``""""'' "Y,
|
||||||
|
Y, d'8 "Ya `Y,
|
||||||
|
`b 8 8 `Y, Y,
|
||||||
|
Ya o ,8 8 b `b
|
||||||
|
Yb,_,dP 8 Y 8
|
||||||
|
`"""" Y 8 8
|
||||||
|
I, 8 8
|
||||||
|
`b P [
|
||||||
|
`b d' [
|
||||||
|
d ,P [
|
||||||
|
,d' ,PY, ,P"YaaaaaaP"Ybaaa,,_ d' [
|
||||||
|
d" ,P" Y, d' 8' `""db, d' 8
|
||||||
|
d' ,P" `Y, 8 I, d'"b, 8a P
|
||||||
|
d( ( `Y, P `b ,P `Y, 8`Ya___d'
|
||||||
|
"Y, "b, `Y, ,I 8 d' `8 8 `"""'
|
||||||
|
"Y, "b, __ `8, d' ,8 ,P 8 8
|
||||||
|
"Y, "bd88b `b 8 I' d' Y, 8
|
||||||
|
"Y, 888b 8 8 8 ,P `b 8
|
||||||
|
"Ya,,d888b8 P d' ,P' 8 Y,
|
||||||
|
`"""",d" ,I ,adPb__aP' Y `b
|
||||||
|
,a8P,__aP' d888888P' ,d 8
|
||||||
|
d8888888' 88888888 ,d888bbaaP
|
||||||
|
88888888 88888888'
|
45
static/ascii_art/pvv_logo.txt
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
'''''''''''''''''''''''''''''''''''''
|
||||||
|
.1!!!!!!!!!!!1?ab?!!1aba?!!!!!!!!!!!1;
|
||||||
|
,!'''''''''=!!;+=.''.,=:!!;,'''''''',!
|
||||||
|
,! ,!!+' .:!:' ,!
|
||||||
|
,! :!+ .:!= ,!
|
||||||
|
,! ';;' ,!+ ,!
|
||||||
|
,! '??;!;;!!;;;;;;;;;;;;;+;;+!: ,!
|
||||||
|
,! ';a=:!,,;!,,,,,,=!!!!+?!==!=!+ +!
|
||||||
|
,! :;!'+; +: .1++;:!. ,!=!,.1:
|
||||||
|
,! =!.!'+; :: .! +:!. ::=!.1:
|
||||||
|
,! !='!'+; :: .!' +:!. +: ;:=!
|
||||||
|
,!+; '!'+; :: .!' +:!. +: .!=!
|
||||||
|
,!!= '!'+; :: .!' +:!. +: ;;!
|
||||||
|
,1!' '!'+; :: .!' +:!. +: ,1!
|
||||||
|
,a: '!'+; :: .!' +:!. +: '11
|
||||||
|
,b= '!.+;'':;'.....,1!!1:!. +: !?
|
||||||
|
,b. '!..;!!1?!!!!!!!!111!; +: :a
|
||||||
|
,?' '!.';!!!!!!!!!!!!!!!!;;;+ +: =?
|
||||||
|
,! '!.=!,================,=!'+: ,!
|
||||||
|
,! '!'+; '!'+: ,!
|
||||||
|
,! '!'+; '!'+: ,!
|
||||||
|
,?' '!'+; .,,' '' '''' '' '!'+: =?
|
||||||
|
,b. '!'+; d00e,ba d!ab c? '!'+: :a
|
||||||
|
,b= '!'+; fd10;ed g?cf fc '!'+: !?
|
||||||
|
,a: '!'+; fd10;bg;0:?0:01 '!'+: '11
|
||||||
|
,1!' '!'+; f$0e,+0ff ,gfg. '!'+: ,1!
|
||||||
|
,!!= '!'+; fb.' e@? c@b '!'+: ;;!
|
||||||
|
,!+; '!'+; d? 1f= ;g: '!'+: .!=!
|
||||||
|
,! !='!'+; ,. ', ',' '!'+: ;:,!
|
||||||
|
,! =!.!=:; '!=::=!',!
|
||||||
|
,! :;??a; '?1a;!, ,!
|
||||||
|
,! ';baa1=++===============+a?ba+ ,!
|
||||||
|
,! '?a!1!!!!!!!!!!!!!!!!!!!1!a; ,!
|
||||||
|
,! ';;' ,!+ ,!
|
||||||
|
,! :!+ .:!= ,!
|
||||||
|
,! ,!!+' .:!:' ,!
|
||||||
|
,!'''''''''=;?1+=.''.,=;?1;,'''''''',!
|
||||||
|
.1!!!!!!!!!!!1?bb?!!1aba11!!!!!!!!!!1;
|
||||||
|
''''''''''''' ''''''''' '''''''''''''
|
||||||
|
|
||||||
|
|
||||||
|
|
12
static/ascii_art/test.txt
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
a@@@@a
|
||||||
|
a@@@@@@@@@@@@a
|
||||||
|
a@@@@@@by@@@@@@@@a
|
||||||
|
a@@@@@S@C@E@S@W@@@@@@a
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
`@@@@@@`\\//'@@@@@@'
|
||||||
|
,, || ,, S.C.E.S.W.
|
||||||
|
/(-\ || /.)m
|
||||||
|
,---' /`-'||`-'\ `----,
|
||||||
|
/( )__)) || ((,==( )\
|
||||||
|
_ /_//___\\ __|| ___\\ __\\ ____
|
||||||
|
`` `` /MM\ '' ''
|
Before Width: | Height: | Size: 939 KiB After Width: | Height: | Size: 939 KiB |
Before Width: | Height: | Size: 1.7 MiB After Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 829 KiB After Width: | Height: | Size: 829 KiB |
Before Width: | Height: | Size: 275 KiB After Width: | Height: | Size: 275 KiB |
Before Width: | Height: | Size: 2.0 MiB After Width: | Height: | Size: 2.0 MiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 317 KiB After Width: | Height: | Size: 317 KiB |
75
templates/ascii.html
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<link rel="icon" type="image/x-icon" href="/static/images/pvv_logo.png">
|
||||||
|
<title>ASCII</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
background: black;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
color: white;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre {
|
||||||
|
white-space: pre;
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.2;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<pre id="ascii">
|
||||||
|
a@@@@a
|
||||||
|
a@@@@@@@@@@@@a
|
||||||
|
a@@@@@@by@@@@@@@@a
|
||||||
|
a@@@@@S@C@E@S@W@@@@@@a
|
||||||
|
@@@@@@@@@@@@@@@@@@@@@@
|
||||||
|
`@@@@@@`\\//'@@@@@@'
|
||||||
|
,, || ,, S.C.E.S.W.
|
||||||
|
/(-\ || /.)m
|
||||||
|
,---' /`-'||`-'\ `----,
|
||||||
|
/( )__)) || ((,==( )\
|
||||||
|
_ /_//___\\ __|| ___\\ __\\ ____
|
||||||
|
`` `` /MM\ '' ''
|
||||||
|
</pre>
|
||||||
|
<script>
|
||||||
|
fetch("/files")
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(files => {
|
||||||
|
const AsciiObj = files.AsciiFiles
|
||||||
|
|
||||||
|
let index = 0;
|
||||||
|
const preElement = document.getElementById("ascii");
|
||||||
|
|
||||||
|
const nextAscii = () => {
|
||||||
|
const filePath = AsciiObj[index].Name;
|
||||||
|
fetch(filePath)
|
||||||
|
.then(res => {return res.text();})
|
||||||
|
.then(fileContent => {preElement.textContent = fileContent;})
|
||||||
|
.catch(err => {
|
||||||
|
console.error("PANIC FETCH .txt FAILED PANIC!!")
|
||||||
|
preElement.textContent = fileContent;
|
||||||
|
})
|
||||||
|
index = (index + 1) % AsciiObj.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
nextAscii();
|
||||||
|
setInterval(nextAscii, 1000);
|
||||||
|
}).catch(err => {
|
||||||
|
console.error("PANIC FETCH of file list FAILED!", err);
|
||||||
|
preElement.textContent = "Error loading file list.";
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<link rel="icon" type="image/x-icon" href="/static/images/pvv_logo.png">
|
||||||
<title>IMAGES</title>
|
<title>IMAGES</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
@@ -22,17 +23,18 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<img id="images" src="base.png" alt="images">
|
<img id="images" src="/static/images/pvv_logo.png" alt="images">
|
||||||
<script>
|
<script>
|
||||||
fetch("/files")
|
fetch("/files")
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(files => {
|
.then(files => {
|
||||||
const images = files
|
const images = files.ImageNames
|
||||||
|
console.log(images)
|
||||||
let index = 0;
|
let index = 0;
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
index = (index + 1) % images.length;
|
index = (index + 1) % images.length;
|
||||||
document.getElementById("images").src = images[index];
|
document.getElementById("images").src = images[index];
|
||||||
}, 10000);
|
}, 1000);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|