diff --git a/cmd/errors.go b/cmd/errors.go
index 79a0bf1..336bdcf 100644
--- a/cmd/errors.go
+++ b/cmd/errors.go
@@ -54,7 +54,6 @@ func notFound(w http.ResponseWriter, r *http.Request, path string) error {
func serverError(w http.ResponseWriter, r *http.Request, i interface{}) {
startTime := time.Now()
- w.WriteHeader(http.StatusInternalServerError)
w.Header().Add("Content-Type", "text/html")
nonce := types.GetNonce()
@@ -67,8 +66,7 @@ func serverError(w http.ResponseWriter, r *http.Request, i interface{}) {
fmt.Printf("%s | ERROR: Invalid request for %s from %s\n",
startTime.Format(logDate),
r.URL.Path,
- r.RemoteAddr,
- )
+ r.RemoteAddr)
}
}
diff --git a/cmd/files.go b/cmd/files.go
index b761e03..3181609 100644
--- a/cmd/files.go
+++ b/cmd/files.go
@@ -47,7 +47,8 @@ func humanReadableSize(bytes int) string {
}
return fmt.Sprintf("%.1f %cB",
- float64(bytes)/float64(div), "kMGTPE"[exp])
+ float64(bytes)/float64(div),
+ "kMGTPE"[exp])
}
func kill(path string, index *fileIndex) error {
@@ -136,7 +137,10 @@ func tryExtensions(splitPath *splitPath, formats types.Types) (string, error) {
var path string
for extension := range formats {
- path = fmt.Sprintf("%s%s%s", splitPath.base, splitPath.number, extension)
+ path = fmt.Sprintf("%s%s%s",
+ splitPath.base,
+ splitPath.number,
+ extension)
exists, err := fileExists(path)
if err != nil {
@@ -178,8 +182,7 @@ func pathIsValid(path string, paths []string) bool {
case Verbose && !matchesPrefix:
fmt.Printf("%s | ERROR: File outside specified path(s): %s\n",
time.Now().Format(logDate),
- path,
- )
+ path)
return false
case !matchesPrefix:
@@ -423,8 +426,7 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
filesMatched+filesSkipped,
directoriesMatched,
directoriesMatched+directoriesSkipped,
- time.Since(startTime).Round(time.Microsecond),
- )
+ time.Since(startTime).Round(time.Microsecond))
}
slices.Sort(list)
@@ -478,7 +480,9 @@ func pickFile(list []string) (string, error) {
func preparePath(prefix, path string) string {
if runtime.GOOS == "windows" {
- return fmt.Sprintf("%s/%s", prefix, filepath.ToSlash(path))
+ return fmt.Sprintf("%s/%s",
+ prefix,
+ filepath.ToSlash(path))
}
return prefix + path
@@ -530,8 +534,7 @@ func validatePaths(args []string, formats types.Types) ([]string, error) {
if Verbose {
fmt.Printf("%s | PATHS: Added %s\n",
time.Now().Format(logDate),
- args[i],
- )
+ args[i])
}
paths = append(paths, path)
@@ -540,8 +543,7 @@ func validatePaths(args []string, formats types.Types) ([]string, error) {
fmt.Printf("%s | PATHS: Added %s [resolved to %s]\n",
time.Now().Format(logDate),
args[i],
- path,
- )
+ path)
}
paths = append(paths, path)
@@ -549,16 +551,14 @@ func validatePaths(args []string, formats types.Types) ([]string, error) {
if Verbose {
fmt.Printf("%s | PATHS: Skipped %s (No supported files found)\n",
time.Now().Format(logDate),
- args[i],
- )
+ args[i])
}
case !pathMatches && !hasSupportedFiles:
if Verbose {
fmt.Printf("%s | PATHS: Skipped %s [resolved to %s] (No supported files found)\n",
time.Now().Format(logDate),
args[i],
- path,
- )
+ path)
}
}
}
diff --git a/cmd/index.go b/cmd/index.go
index 151c7c6..e7083fa 100644
--- a/cmd/index.go
+++ b/cmd/index.go
@@ -251,8 +251,7 @@ func serveIndexRebuild(args []string, index *fileIndex, formats types.Types, enc
if Verbose {
fmt.Printf("%s | SERVE: Index rebuild requested by %s\n",
time.Now().Format(logDate),
- realIP(r),
- )
+ realIP(r))
}
w.Header().Add("Content-Security-Policy", "default-src 'self';")
@@ -285,9 +284,7 @@ func registerIndexInterval(args []string, index *fileIndex, formats types.Types,
select {
case <-ticker.C:
if Verbose {
- fmt.Printf("%s | INDEX: Started scheduled index rebuild\n",
- time.Now().Format(logDate),
- )
+ fmt.Printf("%s | INDEX: Started scheduled index rebuild\n", time.Now().Format(logDate))
}
rebuildIndex(args, index, formats, encoder, errorChannel)
diff --git a/cmd/info.go b/cmd/info.go
index 226d503..14bb75d 100644
--- a/cmd/info.go
+++ b/cmd/info.go
@@ -40,8 +40,7 @@ func serveExtensions(formats types.Types, available bool, errorChannel chan<- er
startTime.Format(logDate),
humanReadableSize(written),
realIP(r),
- time.Since(startTime).Round(time.Microsecond),
- )
+ time.Since(startTime).Round(time.Microsecond))
}
}
}
@@ -72,8 +71,7 @@ func serveMediaTypes(formats types.Types, available bool, errorChannel chan<- er
startTime.Format(logDate),
humanReadableSize(written),
realIP(r),
- time.Since(startTime).Round(time.Microsecond),
- )
+ time.Since(startTime).Round(time.Microsecond))
}
}
}
diff --git a/cmd/root.go b/cmd/root.go
index 50f1a99..e8d5adb 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -17,7 +17,7 @@ import (
const (
AllowedCharacters string = `^[A-z0-9.\-_]+$`
- ReleaseVersion string = "8.3.1"
+ ReleaseVersion string = "8.4.0"
)
var (
diff --git a/cmd/web.go b/cmd/web.go
index de0ccd6..8fd16e3 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -617,8 +617,7 @@ func ServePage(args []string) error {
fmt.Printf("%s | SERVE: Listening on http://%s%s/\n",
time.Now().Format(logDate),
listenHost,
- Prefix,
- )
+ Prefix)
}
err = srv.ListenAndServe()
diff --git a/types/flash/flash.go b/types/flash/flash.go
index e6030c0..795eb97 100644
--- a/types/flash/flash.go
+++ b/types/flash/flash.go
@@ -15,11 +15,7 @@ import (
type Format struct{}
func (t Format) CSP(w http.ResponseWriter) string {
- nonce := types.GetNonce()
-
- w.Header().Add("Content-Security-Policy", fmt.Sprintf("default-src 'self' 'nonce-%s'; script-src 'self' 'unsafe-inline'", nonce))
-
- return nonce
+ return ""
}
func (t Format) CSS() string {
@@ -38,8 +34,14 @@ func (t Format) Title(rootUrl, fileUri, filePath, fileName, prefix, mime string)
func (t Format) Body(rootUrl, fileUri, filePath, fileName, prefix, mime, nonce string) (string, error) {
var html strings.Builder
- html.WriteString(fmt.Sprintf(``, nonce, fileUri))
- html.WriteString(fmt.Sprintf(`
`, rootUrl))
+ html.WriteString(fmt.Sprintf(``,
+ nonce,
+ nonce,
+ nonce,
+ fileUri),
+ )
+ html.WriteString(`
`)
+ html.WriteString(fmt.Sprintf(``, nonce, rootUrl))
return html.String(), nil
}
diff --git a/types/images/images.go b/types/images/images.go
index c6163b4..2cbe1a9 100644
--- a/types/images/images.go
+++ b/types/images/images.go
@@ -136,9 +136,11 @@ func ImageDimensions(path string) (*dimensions, error) {
switch {
case errors.Is(err, os.ErrNotExist):
fmt.Printf("File %s does not exist\n", path)
+
return &dimensions{}, nil
case err != nil:
fmt.Printf("File %s open returned error: %s\n", path, err)
+
return &dimensions{}, err
}
defer file.Close()
@@ -147,9 +149,11 @@ func ImageDimensions(path string) (*dimensions, error) {
switch {
case errors.Is(err, image.ErrFormat):
fmt.Printf("File %s has invalid image format\n", path)
+
return &dimensions{width: 0, height: 0}, nil
case err != nil:
fmt.Printf("File %s decode returned error: %s\n", path, err)
+
return &dimensions{}, err
}