Compare commits
No commits in common. "0f1325bb6f22026fe40c46bd1f6f3f8447f607d2" and "84d43e1bb0ea3962f66af4383332c7d57e0d1530" have entirely different histories.
0f1325bb6f
...
84d43e1bb0
5 changed files with 19 additions and 24 deletions
|
@ -10,13 +10,11 @@ import (
|
|||
)
|
||||
|
||||
type PictureData struct {
|
||||
Name string `json:"name"`
|
||||
Date time.Time `json:"date"`
|
||||
Album string `json:"album"`
|
||||
name string
|
||||
date time.Time
|
||||
album string
|
||||
}
|
||||
|
||||
var picd []PictureData
|
||||
|
||||
func listFiles(path string, actualdir string, picd []PictureData) []PictureData {
|
||||
entries, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
|
@ -53,9 +51,9 @@ func isPicture(s string) bool {
|
|||
func getFileInfo(info fs.FileInfo, picd []PictureData, actualdir string) []PictureData {
|
||||
if isPicture(info.Name()) {
|
||||
picd = append(picd, PictureData{
|
||||
Name: info.Name(),
|
||||
Date: info.ModTime(),
|
||||
Album: actualdir,
|
||||
name: info.Name(),
|
||||
date: info.ModTime(),
|
||||
album: actualdir,
|
||||
})
|
||||
util.Logformatrn(util.INFO, "Reading %d files...", len(picd))
|
||||
}
|
||||
|
@ -63,19 +61,16 @@ func getFileInfo(info fs.FileInfo, picd []PictureData, actualdir string) []Pictu
|
|||
return picd
|
||||
}
|
||||
|
||||
func ListFiles(path string) error {
|
||||
func ListFiles(path string) ([]PictureData, error) {
|
||||
var picd []PictureData
|
||||
start := time.Now()
|
||||
picd = listFiles(path, "", picd)
|
||||
if len(picd) == 0 {
|
||||
return errors.New("ListFiles(): Could not gather any file")
|
||||
return nil, errors.New("ListFiles(): Could not gather any file")
|
||||
} else {
|
||||
elapsed := time.Since(start)
|
||||
print("\n")
|
||||
util.Logformat(util.CORRECT, "Gathered %d files in %dms.\n", len(picd), elapsed.Milliseconds())
|
||||
return nil
|
||||
return picd, nil
|
||||
}
|
||||
}
|
||||
|
||||
func GetPictureData() []PictureData {
|
||||
return picd
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ func main() {
|
|||
|
||||
// Reading files
|
||||
util.Logformat(util.INFO, "Reading folder '%s'\n", cfg.PhotoPath)
|
||||
err = core.ListFiles(cfg.PhotoPath)
|
||||
_, err = core.ListFiles(cfg.PhotoPath)
|
||||
if err != nil {
|
||||
util.Logformat(util.ERROR, "%s\n", err.Error())
|
||||
os.Exit(3)
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"backend/core"
|
||||
"backend/util"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func getphoto(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != "GET" {
|
||||
util.Logformat(util.ERROR, "%s: Only GET is accepted (%s received)", util.GetFunctionName(), r.Method)
|
||||
http.Error(w, "Only GET method is accepted", http.StatusBadRequest)
|
||||
idStr := r.URL.Query().Get("id")
|
||||
if idStr == "" {
|
||||
util.Logformat(util.ERROR, "%s: Missing 'id' parameter.", util.GetFunctionName())
|
||||
http.Error(w, "Missing or invalid parameters : id", http.StatusBadRequest)
|
||||
} else {
|
||||
sendResponse(w, core.GetPictureData())
|
||||
sendResponse(w, 0)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
func Start(port int64) {
|
||||
// Creating endpoints
|
||||
http.HandleFunc("/photo", wrapHeader(getphoto))
|
||||
http.HandleFunc("/getphoto", wrapHeader(getphoto))
|
||||
|
||||
util.Logformat(util.INFO, "Starting server on port %d...\n", port)
|
||||
if err := http.ListenAndServe(":"+strconv.FormatInt(port, 10), nil); err != nil {
|
||||
|
|
|
@ -33,11 +33,11 @@ h2 {
|
|||
--color-pill: #D0D4CA;
|
||||
|
||||
--palette-pink: #ad62aa;
|
||||
--palette-red: #872341;
|
||||
--palette-red: #9A031E;
|
||||
--palette-orange: #FF5B22;
|
||||
--palette-yellow: #ff9843;
|
||||
--palette-green: #0d9276;
|
||||
--palette-purple: #7c4585;
|
||||
--palette-purple: #4B1E78;
|
||||
--palette-brown: #3c2317;
|
||||
|
||||
--background-light: linear-gradient(180deg, rgba(248, 241, 241, 1) 0%, rgba(15, 11, 17, 0.1) 100%);
|
||||
|
|
Loading…
Add table
Reference in a new issue