Refactor video viewer to use HTML5 video element and remove legacy web implementation; enhance content type handling for various video formats in download handlers.
This commit is contained in:
@@ -1829,12 +1829,31 @@ func downloadOrgFileHandler(w http.ResponseWriter, r *http.Request, db *database
|
||||
fileName := path.Base(filePath)
|
||||
// Determine content type based on file extension
|
||||
contentType := "application/octet-stream"
|
||||
if strings.HasSuffix(strings.ToLower(fileName), ".pdf") {
|
||||
switch strings.ToLower(path.Ext(fileName)) {
|
||||
case ".pdf":
|
||||
contentType = "application/pdf"
|
||||
} else if strings.HasSuffix(strings.ToLower(fileName), ".png") {
|
||||
case ".png":
|
||||
contentType = "image/png"
|
||||
} else if strings.HasSuffix(strings.ToLower(fileName), ".jpg") || strings.HasSuffix(strings.ToLower(fileName), ".jpeg") {
|
||||
case ".jpg", ".jpeg":
|
||||
contentType = "image/jpeg"
|
||||
case ".mp4":
|
||||
contentType = "video/mp4"
|
||||
case ".webm":
|
||||
contentType = "video/webm"
|
||||
case ".ogg":
|
||||
contentType = "video/ogg"
|
||||
case ".avi":
|
||||
contentType = "video/avi"
|
||||
case ".mov":
|
||||
contentType = "video/quicktime"
|
||||
case ".mkv":
|
||||
contentType = "video/x-matroska"
|
||||
case ".flv":
|
||||
contentType = "video/x-flv"
|
||||
case ".wmv":
|
||||
contentType = "video/x-ms-wmv"
|
||||
case ".m4v":
|
||||
contentType = "video/x-m4v"
|
||||
}
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf("inline; filename=\"%s\"", fileName))
|
||||
if ct := resp.Header.Get("Content-Type"); ct != "" {
|
||||
@@ -1985,12 +2004,31 @@ func downloadUserFileHandler(w http.ResponseWriter, r *http.Request, db *databas
|
||||
fileName := path.Base(filePath)
|
||||
// Determine content type based on file extension
|
||||
contentType := "application/octet-stream"
|
||||
if strings.HasSuffix(strings.ToLower(fileName), ".pdf") {
|
||||
switch strings.ToLower(path.Ext(fileName)) {
|
||||
case ".pdf":
|
||||
contentType = "application/pdf"
|
||||
} else if strings.HasSuffix(strings.ToLower(fileName), ".png") {
|
||||
case ".png":
|
||||
contentType = "image/png"
|
||||
} else if strings.HasSuffix(strings.ToLower(fileName), ".jpg") || strings.HasSuffix(strings.ToLower(fileName), ".jpeg") {
|
||||
case ".jpg", ".jpeg":
|
||||
contentType = "image/jpeg"
|
||||
case ".mp4":
|
||||
contentType = "video/mp4"
|
||||
case ".webm":
|
||||
contentType = "video/webm"
|
||||
case ".ogg":
|
||||
contentType = "video/ogg"
|
||||
case ".avi":
|
||||
contentType = "video/avi"
|
||||
case ".mov":
|
||||
contentType = "video/quicktime"
|
||||
case ".mkv":
|
||||
contentType = "video/x-matroska"
|
||||
case ".flv":
|
||||
contentType = "video/x-flv"
|
||||
case ".wmv":
|
||||
contentType = "video/x-ms-wmv"
|
||||
case ".m4v":
|
||||
contentType = "video/x-m4v"
|
||||
}
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf("inline; filename=\"%s\"", fileName))
|
||||
if ct := resp.Header.Get("Content-Type"); ct != "" {
|
||||
|
||||
@@ -44,7 +44,7 @@ func CORS(allowedOrigins string) func(http.Handler) http.Handler {
|
||||
allowHeaders = append(allowHeaders, reqHeaders)
|
||||
}
|
||||
w.Header().Set("Access-Control-Allow-Headers", strings.Join(uniqueStrings(allowHeaders), ", "))
|
||||
w.Header().Set("Access-Control-Expose-Headers", "Content-Length, Content-Type, Content-Disposition")
|
||||
w.Header().Set("Access-Control-Expose-Headers", "Content-Length, Content-Type, Content-Disposition, Content-Range, Accept-Ranges")
|
||||
w.Header().Set("Access-Control-Max-Age", "3600")
|
||||
|
||||
if r.Method == http.MethodOptions {
|
||||
|
||||
Reference in New Issue
Block a user