now using propper URL redirects, media path now created if not found, now checking for templates directory

This commit is contained in:
TheLastBilly 2023-05-21 23:06:37 -04:00
parent 0431580dd6
commit 78aa6bea18
2 changed files with 16 additions and 3 deletions

View File

@ -1,9 +1,11 @@
package main
import (
"os"
"log"
"fmt"
"flag"
"errors"
"strconv"
"strings"
"math/rand"
@ -90,6 +92,17 @@ func (o * Options) Parse() error {
flag.Parse()
if _, err := os.Stat(o.TemplatesPath); errors.Is(err, os.ErrNotExist) {
log.Fatal(err)
}
if _, err := os.Stat(o.MediaPath); errors.Is(err, os.ErrNotExist) {
err := os.Mkdir(o.MediaPath, os.ModePerm)
if err != nil {
log.Fatal(err)
}
}
return nil
}

View File

@ -114,14 +114,14 @@ func managerRemoveView(w http.ResponseWriter, r * http.Request) {
return
}
http.Redirect(w, r, fmt.Sprintf("http://%s:%d", options.Address, options.Port), http.StatusSeeOther)
http.Redirect(w, r, "/", http.StatusSeeOther)
}
func managerPublishView(w http.ResponseWriter, r * http.Request) {
var err error
if r.Method == "GET" {
http.Redirect(w, r, fmt.Sprintf("http://%s:%d", options.Address, options.Port), http.StatusSeeOther)
http.Redirect(w, r, "/", http.StatusSeeOther)
return
}
if r.Method != "POST" {
@ -162,7 +162,7 @@ func managerPublishView(w http.ResponseWriter, r * http.Request) {
return
}
http.Redirect(w, r, fmt.Sprintf("http://%s:%d", options.Address, options.Port), http.StatusSeeOther)
http.Redirect(w, r, "/", http.StatusSeeOther)
}
func managerEditView(w http.ResponseWriter, r * http.Request) {