package storage
import (
"io"
"strings"
"time"
"alin.ovh/homestead/domain/content/builder/template"
"alin.ovh/homestead/shared/buffer"
"github.com/Southclaws/fault"
"github.com/Southclaws/fault/fmsg"
)
type File struct {
Path string
FSPath string
ContentType string
LastModified time.Time
Etag string
Title string
StyleHash string
Headers map[string]string
Encodings map[string]*buffer.Buffer
}
func (f *File) AvailableEncodings() []string {
encs := make([]string, 0, len(f.Encodings))
for enc := range f.Encodings {
encs = append(encs, enc)
}
return encs
}
func (f *File) CalculateStyleHash() (err error) {
buf := f.Encodings["identity"]
if buf == nil {
return fault.New("buffer not initialised")
}
if _, err := buf.Seek(0, io.SeekStart); err != nil {
return fault.Wrap(err, fmsg.With("could not seek buffer"))
}
mime, _, _ := strings.Cut(f.ContentType, ";")
switch mime {
case "text/html":
f.StyleHash, err = template.GetHTMLStyleHash(buf)
if err != nil {
return fault.Wrap(err, fmsg.With("could not calculate HTML style hash"))
}
default:
return
}
if _, err := buf.Seek(0, io.SeekStart); err != nil {
return fault.Wrap(err, fmsg.With("could not seek buffer"))
}
return
}
shared/storage/file.go (view raw)