fix style hash not calculated for pages
1 file changed, 25 insertions(+), 20 deletions(-)
changed files
M internal/storage/sqlite/writer.go → internal/storage/sqlite/writer.go
@@ -133,7 +133,13 @@ func (s *Writer) storeFile(urlID int64, file *storage.File) (int64, error) { if file.ContentType == "" { file.ContentType = http.DetectContentType(file.Encodings["identity"].Bytes()) - s.log.Warn("file has no content type, sniffing", "path", file.Path, "sniffed", file.ContentType) + s.log.Warn( + "file has no content type, sniffing", + "path", + file.Path, + "sniffed", + file.ContentType, + ) } r, err := s.queries.insertFile.Exec( sql.Named("url_id", urlID),@@ -178,38 +184,26 @@ func contentType(pathname string) string { return mime.TypeByExtension(filepath.Ext(pathNameToFileName(pathname))) } -func (s *Writer) WritePost(post *content.Post, content *buffer.Buffer) error { - s.log.Debug("storing post", "title", post.Title) - bytes := content.Bytes() - etag, err := etag(bytes) - if err != nil { - return errors.WithMessage(err, "calculating etag") - } - +func (s *Writer) NewFileFromPost(post *content.Post) *storage.File { file := &storage.File{ Path: post.URL, - ContentType: contentType(post.URL), LastModified: post.Date, - Etag: etag, Encodings: map[string]*buffer.Buffer{}, } - return s.WriteFile(file, content) + return file } -func (s *Writer) Write(pathname string, content *buffer.Buffer) error { - bytes := content.Bytes() +func (s *Writer) WritePost(post *content.Post, content *buffer.Buffer) error { + s.log.Debug("storing post", "title", post.Title) - etag, err := etag(bytes) - if err != nil { - return errors.WithMessage(err, "calculating etag") - } + return s.WriteFile(s.NewFileFromPost(post), content) +} +func (s *Writer) Write(pathname string, content *buffer.Buffer) error { file := &storage.File{ Path: pathname, - ContentType: contentType(pathname), LastModified: time.Now(), - Etag: etag, Encodings: map[string]*buffer.Buffer{}, }@@ -228,6 +222,17 @@ if file.Encodings == nil { file.Encodings = map[string]*buffer.Buffer{} } file.Encodings["identity"] = content + + if file.ContentType == "" { + file.ContentType = contentType(file.Path) + } + + if file.Etag == "" { + file.Etag, err = etag(content.Bytes()) + if err != nil { + return errors.WithMessage(err, "could not calculate file etag") + } + } err = file.CalculateStyleHash() if err != nil {