Arreglado fallo añadiendo imágenes

Las imágenes añadidas no aparecían sin reiniciar el servidor.
This commit is contained in:
danoloan 2022-02-11 19:52:56 +01:00
parent 4233703c50
commit 6fd66dbe26
1 changed files with 20 additions and 23 deletions

43
main.go
View File

@ -1,12 +1,14 @@
package main
import (
"crypto/sha512"
"encoding/hex"
"encoding/json"
"fmt"
"html/template"
"crypto/sha512"
"io"
"io/ioutil"
"mime"
"net/http"
"os"
"os/exec"
@ -15,13 +17,11 @@ import (
"strings"
"sync"
"time"
"encoding/hex"
"mime"
"github.com/google/uuid"
"github.com/gorilla/feeds"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/gorilla/feeds"
"github.com/google/uuid"
//"github.com/labstack/echo/middleware"
)
@ -36,7 +36,7 @@ type (
}
Entry struct {
Date JSTime `json:"date"`
Date JSTime `json:"date"`
Description string `json:"description"`
Post string `json:"post"`
Likes int `json:"likes"`
@ -146,9 +146,6 @@ func (list *entryMap) write() (err error) {
if err == nil {
err = ioutil.WriteFile(list.filename, data, 0644)
}
if err == nil {
list.modtime = time.Now()
}
return
}
@ -162,7 +159,7 @@ func (list *entryMap) read() (err error) {
// sort list
list.sorted = make([]*Entry, 0, len(list.mapped))
for _, entry:= range list.mapped {
for _, entry := range list.mapped {
list.sorted = append(list.sorted, entry)
}
sort.Sort(entryList(list.sorted))
@ -239,20 +236,20 @@ func (list *entryMap) getEntry(uuid string) (result *Entry, err error) {
}
func (list *entryMap) getFeed() (feed *feeds.Feed) {
feed = &feeds.Feed {
Title: "danoloan.es igar",
Link: &feeds.Link { Href: "https://danoloan.es/igar/" },
feed = &feeds.Feed{
Title: "danoloan.es igar",
Link: &feeds.Link{Href: "https://danoloan.es/igar/"},
Description: "bitácora fotográfica de danoloan",
Author: &feeds.Author { Name: "danoloan", Email: "danolo@danoloan.es" },
Author: &feeds.Author{Name: "danoloan", Email: "danolo@danoloan.es"},
}
feed.Items = make([]*feeds.Item, 0, list.Len())
for _, elem := range list.getSortedEntries() {
item := &feeds.Item {
Title: elem.Description,
Link: &feeds.Link{ Href: fmt.Sprintf("https://danoloan.es/igar/view?uuid=%s", elem.Post) },
item := &feeds.Item{
Title: elem.Description,
Link: &feeds.Link{Href: fmt.Sprintf("https://danoloan.es/igar/view?uuid=%s", elem.Post)},
Description: fmt.Sprintf("<p>%s</p>\n<div>\n", elem.Description),
Created: time.Time(elem.Date),
Created: time.Time(elem.Date),
}
for _, media := range elem.Media {
@ -344,9 +341,9 @@ func PostController(c echo.Context) (err error) {
file, err := c.FormFile("file")
entry := &Entry {
entry := &Entry{
Description: desc,
Post: genName(),
Post: genName(),
}
if date != "" {
@ -360,7 +357,7 @@ func PostController(c echo.Context) (err error) {
return
}
media := Media {
media := Media{
Type: "GraphImage",
File: genName(),
}
@ -422,7 +419,7 @@ func main() {
e.GET("/list", ListController)
e.GET("/view", ViewController)
e.GET("/rss", RSSController)
e.GET("/rss", RSSController)
e.GET("/json", JSONController)
e.GET("/atom", AtomController)
@ -432,7 +429,7 @@ func main() {
admin := e.Group("/admin", middleware.BasicAuth(auth))
admin.GET("/", func(c echo.Context) error {
return c.Render(http.StatusOK, "admin.html", struct { List entryList }{
return c.Render(http.StatusOK, "admin.html", struct{ List entryList }{
List: list.getSortedEntries(),
})
})