structural improvements

This commit is contained in:
2026-09-06 20:33:15 +02:00
parent d95b0d8b4a
commit 887a20e38a
5 changed files with 91 additions and 75 deletions
+15 -36
View File
@@ -4,16 +4,23 @@ import (
"fmt"
"io/fs"
"log"
"os"
"media-converter/convertVideo"
"media-converter/optimizeImage"
"path/filepath"
"strings"
"sync"
)
const touchedFile = ".touched"
var touched = loadTouched()
var imageExts = map[string]bool{
".jpeg": true,
".jpg": true,
".png": true,
".gif": true,
".bmp": true,
".tiff": true,
".tif": true,
".webp": true,
}
var wg sync.WaitGroup
func main() {
@@ -29,14 +36,14 @@ func main() {
switch {
case ext == ".mov":
wg.Go(func() {
ConvertVideo(path)
convertVideo.ConvertVideo(path)
})
case imageExts[ext]:
if touched[path] {
if optimizeImage.Touched[path] {
fmt.Printf("Skipping %s (already touched)\n", path)
return nil
}
wg.Go(func() { OptimizeImage(path) })
wg.Go(func() { optimizeImage.OptimizeImage(path) })
}
return nil
})
@@ -47,31 +54,3 @@ func main() {
log.Fatal(err)
}
}
func loadTouched() map[string]bool {
set := map[string]bool{}
data, err := os.ReadFile(touchedFile)
if err != nil {
return set
}
for _, line := range strings.Split(string(data), "\n") {
line = strings.TrimSpace(line)
if line != "" && !set[line] {
set[line] = true
}
}
return set
}
func markTouched(path string) {
f, err := os.OpenFile(touchedFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
fmt.Printf("Error updating %s: %v\n", touchedFile, err)
return
}
defer f.Close()
if _, err := fmt.Fprintln(f, path); err == nil {
touched[path] = true
}
}