Compare commits
52 Commits
3d3cda319d
...
v0.15.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b100483de | |||
| 7b9438233e | |||
| ff36d65cc3 | |||
| e03fd78ea9 | |||
| 370ef205a9 | |||
| d328ddb749 | |||
| 5dc5590da9 | |||
| 364112a0a4 | |||
| a38523e933 | |||
| 200672dae2 | |||
| 3d3aad88c8 | |||
| e4e43d1a83 | |||
| 737a9ec314 | |||
| 1ebe0380ee | |||
| d62d71b5d1 | |||
| b36e0ea503 | |||
| bc4d8fa37e | |||
| d2b21e7405 | |||
| e3c192359f | |||
| 46532e4c85 | |||
| c722135a56 | |||
| 887fa863bc | |||
| 74d71cfb6a | |||
| ca7e7cddd3 | |||
| 94431a2aa9 | |||
| 5b1f20c5bc | |||
| d0c566f8df | |||
| 5e586aa49a | |||
| 66b2743d3d | |||
| 3723b2b5e6 | |||
| ce788bfd50 | |||
| 230a6278cc | |||
| 42d6e0c198 | |||
| e1af2979af | |||
| f6dedc6f10 | |||
| cdf0a49550 | |||
| c3c0650210 | |||
| d077f700d8 | |||
| ec752b1c66 | |||
| 46aef4f12f | |||
| 1b29e328cf | |||
| e50cb819f3 | |||
| c32e38ca10 | |||
| d7c8c7a43a | |||
| 1cd3edc90c | |||
| 0e768c9f61 | |||
| 1fcd775cc5 | |||
| 203a1ed147 | |||
| ef1914ee5c | |||
| 084b101e31 | |||
| b2db128aa9 | |||
| 081e880fb6 |
@@ -1,10 +1,16 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"image"
|
||||
"io"
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/chai2010/webp"
|
||||
"github.com/disintegration/imaging"
|
||||
@@ -30,7 +36,7 @@ func SaveImage(src io.Reader, maxHeight, maxWidth int, path string) (string, err
|
||||
}
|
||||
|
||||
filename := fmt.Sprint(uuid.New(), ".webp")
|
||||
file, err := os.Create(path + filename)
|
||||
file, err := os.Create(filepath.Join(path, filename))
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error creating new image file: %v", err)
|
||||
}
|
||||
@@ -42,3 +48,59 @@ func SaveImage(src io.Reader, maxHeight, maxWidth int, path string) (string, err
|
||||
|
||||
return filename, nil
|
||||
}
|
||||
|
||||
func CleanUpImages(c *Config) {
|
||||
for {
|
||||
if err := filepath.Walk(c.PicsDir, func(path string, info fs.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !info.IsDir() {
|
||||
imageName := info.Name()
|
||||
absImageName := path
|
||||
|
||||
if err = filepath.Walk(c.ArticleDir, func(path string, info fs.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !info.IsDir() {
|
||||
mdFile, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer mdFile.Close()
|
||||
|
||||
scanner := bufio.NewScanner(mdFile)
|
||||
imageWasFound := false
|
||||
|
||||
for scanner.Scan() {
|
||||
if strings.Contains(scanner.Text(), imageName) {
|
||||
imageWasFound = true
|
||||
}
|
||||
}
|
||||
|
||||
if !imageWasFound {
|
||||
if err = os.Remove(absImageName); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return scanner.Err()
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
time.Sleep(time.Hour)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ func main() {
|
||||
sessions, sessionExpiryChan := f.StartSessions()
|
||||
defer close(sessionExpiryChan)
|
||||
|
||||
go b.CleanUpImages(config)
|
||||
// go b.CleanUpImages(config)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/web/static/", http.StripPrefix("/web/static/",
|
||||
|
||||
Reference in New Issue
Block a user