Commit b18549a

Eric Bower  ·  2026-07-16 19:59:19 -0400 EDT
parent 4af7648
fix: mime type case statement fallthrough
2 files changed,  +8, -12
+4, -8
......@@ -18,11 +18,9 @@ func GetMimeType(fpath string) string {
1818 return "image/x-icon"
1919 case ".pdf":
2020 return "application/pdf"
21- case ".htm":
22- case ".html":
21+ case ".htm", ".html":
2322 return "text/html"
24- case ".jpeg":
25- case ".jpg":
23+ case ".jpeg", ".jpg":
2624 return "image/jpeg"
2725 case ".png":
2826 return "image/png"
......@@ -40,8 +38,7 @@ func GetMimeType(fpath string) string {
4038 return "font/ttf"
4139 case ".md":
4240 return "text/markdown; charset=UTF-8"
43- case ".map":
44- case ".json":
41+ case ".map", ".json":
4542 return "application/json"
4643 case ".rss":
4744 return "application/rss+xml"
......@@ -75,8 +72,7 @@ func GetMimeType(fpath string) string {
7572 return "text/x-opml"
7673 case ".eot":
7774 return "application/vnd.ms-fontobject"
78- case ".yaml":
79- case ".yml":
75+ case ".yaml", ".yml":
8076 return "text/x-yaml"
8177 case ".zip":
8278 return "application/zip"
+4, -4
......@@ -102,11 +102,12 @@ func (s *StorageFS) DeleteBucket(bucket Bucket) error {
102102 }
103103
104104 func (s *StorageFS) GetObject(bucket Bucket, fpath string) (utils.ReadAndReaderAtCloser, *ObjectInfo, error) {
105+ contentType := mime.GetMimeType(fpath)
105106 objInfo := &ObjectInfo{
106107 Size: 0,
107108 LastModified: time.Time{},
108109 ETag: "",
109- ContentType: "",
110+ ContentType: contentType,
110111 }
111112
112113 dat, err := os.Open(filepath.Join(bucket.Path, fpath))
......@@ -119,6 +120,8 @@ func (s *StorageFS) GetObject(bucket Bucket, fpath string) (utils.ReadAndReaderA
119120 _ = dat.Close()
120121 return nil, objInfo, err
121122 }
123+ objInfo.Size = info.Size()
124+ objInfo.LastModified = info.ModTime()
122125
123126 etag := ""
124127 // only generate etag if file is less than 10MB
......@@ -141,9 +144,6 @@ func (s *StorageFS) GetObject(bucket Bucket, fpath string) (utils.ReadAndReaderA
141144 }
142145
143146 objInfo.ETag = etag
144- objInfo.Size = info.Size()
145- objInfo.LastModified = info.ModTime()
146- objInfo.ContentType = mime.GetMimeType(fpath)
147147 return dat, objInfo, nil
148148 }
149149