sqlite: check/sniff file content type
1 file changed, 5 insertions(+), 0 deletions(-)
M internal/storage/sqlite/writer.go → internal/storage/sqlite/writer.go
@@ -6,6 +6,7 @@ "fmt" "hash/fnv" "io" "mime" + "net/http" "path/filepath" "time"@@ -130,6 +131,10 @@ return r.LastInsertId() } 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) + } r, err := s.queries.insertFile.Exec( sql.Named("url_id", urlID), sql.Named("content_type", file.ContentType),