Commit f566e4d
Eric Bower
·
2026-04-20 21:32:16 -0400 EDT
parent 5f240f0
refactor(storage): no need for metadata just need content type
5 files changed,
+5,
-11
+1,
-1
| ... | ... | @@ -257,7 +257,7 @@ func (h *ApiAssetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |
| 257 | 257 | ||
| 258 | 258 | contentType := "" | |
| 259 | 259 | if info != nil { | |
| 260 | - | contentType = info.Metadata.Get("content-type") | |
| 260 | + | contentType = info.ContentType | |
| 261 | 261 | if info.Size != 0 { | |
| 262 | 262 | w.Header().Add("content-length", strconv.Itoa(int(info.Size))) | |
| 263 | 263 | } |
+1,
-4
| ... | ... | @@ -104,10 +104,7 @@ func newTestStorage(st storage.StorageServe) *testStorage { | |
| 104 | 104 | ||
| 105 | 105 | func (t *testStorage) GetObject(bucket storage.Bucket, fpath string) (utils.ReadAndReaderAtCloser, *storage.ObjectInfo, error) { | |
| 106 | 106 | r, info, err := t.StorageServe.GetObject(bucket, fpath) | |
| 107 | - | if info.Metadata == nil { | |
| 108 | - | info.Metadata = make(http.Header) | |
| 109 | - | } | |
| 110 | - | info.Metadata.Set("content-type", mime.GetMimeType(fpath)) | |
| 107 | + | info.ContentType = mime.GetMimeType(fpath) | |
| 111 | 108 | info.LastModified = time.Now().UTC() | |
| 112 | 109 | info.ETag = "static-etag-for-testing-purposes" | |
| 113 | 110 | return r, info, err |
+2,
-3
| ... | ... | @@ -7,7 +7,6 @@ import ( | |
| 7 | 7 | "io" | |
| 8 | 8 | "io/fs" | |
| 9 | 9 | "log/slog" | |
| 10 | - | "net/http" | |
| 11 | 10 | "os" | |
| 12 | 11 | "path" | |
| 13 | 12 | "path/filepath" |
| ... | ... | @@ -106,8 +105,8 @@ func (s *StorageFS) GetObject(bucket Bucket, fpath string) (utils.ReadAndReaderA | |
| 106 | 105 | objInfo := &ObjectInfo{ | |
| 107 | 106 | Size: 0, | |
| 108 | 107 | LastModified: time.Time{}, | |
| 109 | - | Metadata: make(http.Header), | |
| 110 | 108 | ETag: "", | |
| 109 | + | ContentType: "", | |
| 111 | 110 | } | |
| 112 | 111 | ||
| 113 | 112 | dat, err := os.Open(filepath.Join(bucket.Path, fpath)) |
| ... | ... | @@ -144,7 +143,7 @@ func (s *StorageFS) GetObject(bucket Bucket, fpath string) (utils.ReadAndReaderA | |
| 144 | 143 | objInfo.ETag = etag | |
| 145 | 144 | objInfo.Size = info.Size() | |
| 146 | 145 | objInfo.LastModified = info.ModTime() | |
| 147 | - | objInfo.Metadata.Set("content-type", mime.GetMimeType(fpath)) | |
| 146 | + | objInfo.ContentType = mime.GetMimeType(fpath) | |
| 148 | 147 | return dat, objInfo, nil | |
| 149 | 148 | } | |
| 150 | 149 |
+0,
-1
| ... | ... | @@ -93,7 +93,6 @@ func (s *StorageMemory) GetObject(bucket Bucket, fpath string) (utils.ReadAndRea | |
| 93 | 93 | ||
| 94 | 94 | objInfo := &ObjectInfo{ | |
| 95 | 95 | LastModified: time.Time{}, | |
| 96 | - | Metadata: nil, | |
| 97 | 96 | } | |
| 98 | 97 | ||
| 99 | 98 | dat, ok := s.storage[bucket.Path][fpath] |
+1,
-2