CalculateExpiry determines expiry time based on file type
(mimeType, path string)
| 125 | |
| 126 | // CalculateExpiry determines expiry time based on file type |
| 127 | func CalculateExpiry(mimeType, path string) time.Time { |
| 128 | now := time.Now() |
| 129 | |
| 130 | // Determine file type from extension |
| 131 | filename := filepath.Base(path) |
| 132 | ext := strings.ToLower(filepath.Ext(filename)) |
| 133 | |
| 134 | // Images |
| 135 | if strings.HasPrefix(mimeType, "image/") || |
| 136 | ext == ".jpg" || ext == ".jpeg" || ext == ".png" || |
| 137 | ext == ".gif" || ext == ".webp" || ext == ".svg" { |
| 138 | return now.Add(ImageCacheExpiry) |
| 139 | } |
| 140 | |
| 141 | // Text files |
| 142 | if strings.HasPrefix(mimeType, "text/") || |
| 143 | strings.Contains(mimeType, "javascript") || |
| 144 | strings.Contains(mimeType, "json") || |
| 145 | ext == ".html" || ext == ".css" || ext == ".js" || |
| 146 | ext == ".txt" || ext == ".md" || ext == ".xml" { |
| 147 | return now.Add(TextCacheExpiry) |
| 148 | } |
| 149 | |
| 150 | // Video files |
| 151 | if strings.HasPrefix(mimeType, "video/") || |
| 152 | ext == ".mp4" || ext == ".webm" || ext == ".ogg" { |
| 153 | return now.Add(VideoCacheExpiry) |
| 154 | } |
| 155 | |
| 156 | // Default for other files |
| 157 | return now.Add(DefaultCacheExpiry) |
| 158 | } |
| 159 | |
| 160 | func GenerateETag(content []byte, modTime time.Time) string { |
| 161 | hash := md5.New() |
no test coverage detected