Fix launch problem when directories doesn't exist
continuous-integration/drone/push Build is passing Details

This commit is contained in:
nemunaire 2022-09-07 10:43:13 +02:00
parent 15be0cf465
commit 3c14a3685c
1 changed files with 12 additions and 1 deletions

13
main.go
View File

@ -6,6 +6,7 @@ import (
"log"
"net/http"
"os"
"path"
)
var mux = http.NewServeMux()
@ -30,7 +31,7 @@ func main() {
if htpasswd, err = NewHtpasswd(*htpasswd_file); htpasswd == nil {
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")
nextImgDir = publishedImgDir
}
@ -57,6 +58,16 @@ func main() {
var storage_backend FileBackend
if backend == nil || *backend == "local" {
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" {
storage_backend = &S3FileBackend{s3_endpoint, s3_region, s3_bucket, s3_access_key, s3_secret_key, s3_path_style, *baseDir}
} else {