🚧 Serve Page Resource bytes
This commit is contained in:
parent
5c75e6f9e9
commit
860d56cfc5
24
main.go
24
main.go
|
@ -5,10 +5,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"log"
|
||||
"net"
|
||||
|
@ -113,8 +115,7 @@ func NewApp(ctx context.Context, config *domain.Config) (*App, error) {
|
|||
|
||||
if s.DefaultLanguage != domain.LanguageUnd {
|
||||
supported = append(
|
||||
[]language.Tag{language.Make(s.DefaultLanguage.Code())},
|
||||
supported...,
|
||||
[]language.Tag{language.Make(s.DefaultLanguage.Code())}, supported...,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -163,7 +164,24 @@ func NewApp(ctx context.Context, config *domain.Config) (*App, error) {
|
|||
return
|
||||
}
|
||||
|
||||
http.ServeContent(w, r, res.Name(), domain.ResourceModTime(res), res)
|
||||
// TODO(toby3d) : ugly workaround, must be refactored
|
||||
resFile, err := contentDir.Open(res.File.Path())
|
||||
if err != nil {
|
||||
http.Error(w, "cannot open: "+err.Error(), http.StatusInternalServerError)
|
||||
|
||||
return
|
||||
}
|
||||
defer resFile.Close()
|
||||
|
||||
resBytes, err := io.ReadAll(resFile)
|
||||
if err != nil {
|
||||
http.Error(w, "cannot read all: "+err.Error(), http.StatusInternalServerError)
|
||||
|
||||
return
|
||||
}
|
||||
defer resFile.Close()
|
||||
|
||||
http.ServeContent(w, r, res.Name(), domain.ResourceModTime(res), bytes.NewReader(resBytes))
|
||||
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue