Fix launch problem when directories doesn't exist
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
nemunaire 2022-09-07 10:43:13 +02:00
parent 15be0cf465
commit 3c14a3685c

13
main.go
View File

@ -6,6 +6,7 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"path"
) )
var mux = http.NewServeMux() var mux = http.NewServeMux()
@ -30,7 +31,7 @@ func main() {
if htpasswd, err = NewHtpasswd(*htpasswd_file); htpasswd == nil { if htpasswd, err = NewHtpasswd(*htpasswd_file); htpasswd == nil {
log.Fatal("Unable to parse htpasswd:", err) log.Fatal("Unable to parse htpasswd:", err)
} }
} else if *nextImgDir == "./images/next/" { } else if *nextImgDir == "next/" {
log.Println("Disable admin interface, images will be published without moderation") log.Println("Disable admin interface, images will be published without moderation")
nextImgDir = publishedImgDir nextImgDir = publishedImgDir
} }
@ -57,6 +58,16 @@ func main() {
var storage_backend FileBackend var storage_backend FileBackend
if backend == nil || *backend == "local" { if backend == nil || *backend == "local" {
storage_backend = &LocalFileBackend{*baseDir} storage_backend = &LocalFileBackend{*baseDir}
if _, err := os.Stat(path.Join(*baseDir, *publishedImgDir)); os.IsNotExist(err) {
if err := os.MkdirAll(path.Join(*baseDir, *publishedImgDir), 0755); err != nil {
log.Fatal(err)
}
}
if _, err := os.Stat(path.Join(*baseDir, *nextImgDir)); os.IsNotExist(err) {
if err := os.MkdirAll(path.Join(*baseDir, *nextImgDir), 0755); err != nil {
log.Fatal(err)
}
}
} else if *backend == "s3" { } else if *backend == "s3" {
storage_backend = &S3FileBackend{s3_endpoint, s3_region, s3_bucket, s3_access_key, s3_secret_key, s3_path_style, *baseDir} storage_backend = &S3FileBackend{s3_endpoint, s3_region, s3_bucket, s3_access_key, s3_secret_key, s3_path_style, *baseDir}
} else { } else {