Set download dir from env var. validate id
This commit is contained in:
parent
2f5d2c84f0
commit
1e069fe7fa
1 changed files with 18 additions and 4 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
"html/template"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
|
@ -24,8 +25,6 @@ import (
|
|||
"sync"
|
||||
)
|
||||
|
||||
const downloadDir = "downloads/"
|
||||
|
||||
type Media struct {
|
||||
Id string
|
||||
Name string
|
||||
|
|
@ -41,6 +40,10 @@ type MediaResults struct {
|
|||
var fetchResponseTmpl = template.Must(template.ParseFiles("templates/media/response.html"))
|
||||
var fetchIndexTmpl = template.Must(template.ParseFiles("templates/media/index.html"))
|
||||
|
||||
// Where the media files are saved. Always has a trailing slash
|
||||
var downloadDir = getDownloadDir()
|
||||
var idCharSet = regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString
|
||||
|
||||
func Index(w http.ResponseWriter, _ *http.Request) {
|
||||
if err := fetchIndexTmpl.Execute(w, nil); err != nil {
|
||||
log.Error().Msgf("Error rendering template: %v", err)
|
||||
|
|
@ -213,6 +216,17 @@ func GetMD5Hash(url string) string {
|
|||
}
|
||||
|
||||
func isValidId(id string) bool {
|
||||
// TODO: Finish this
|
||||
return true
|
||||
// TODO: Finish this. Should only be alpha numeric
|
||||
return idCharSet(id)
|
||||
}
|
||||
|
||||
func getDownloadDir() string {
|
||||
dir := os.Getenv("DOWNLOAD_DIR")
|
||||
if dir != "" {
|
||||
if !strings.HasSuffix(dir, "/") {
|
||||
return dir + "/"
|
||||
}
|
||||
return dir
|
||||
}
|
||||
return "downloads/"
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue