Browse Source

Fixed issue 105 for ai files turning into pdf

Toby Chui 3 years ago
parent
commit
aab53b790e
3 changed files with 17 additions and 2 deletions
  1. 2 1
      mediaServer.go
  2. 14 0
      mod/compatibility/browser.go
  3. 1 1
      mod/filesystem/filesystem.go

+ 2 - 1
mediaServer.go

@@ -14,6 +14,7 @@ import (
 	"time"
 
 	"imuslab.com/arozos/mod/common"
+	"imuslab.com/arozos/mod/compatibility"
 	"imuslab.com/arozos/mod/filesystem"
 	fs "imuslab.com/arozos/mod/filesystem"
 	"imuslab.com/arozos/mod/network/gzipmiddleware"
@@ -187,7 +188,7 @@ func serverMedia(w http.ResponseWriter, r *http.Request) {
 		*/
 
 		w.Header().Set("Content-Disposition", "attachment; filename=\""+filename+"\"")
-		w.Header().Set("Content-Type", r.Header.Get("Content-Type"))
+		w.Header().Set("Content-Type", compatibility.BrowserCompatibilityOverrideContentType(r.UserAgent(), filename, r.Header.Get("Content-Type")))
 		if targetFsh.RequireBuffer || !filesystem.FileExists(realFilepath) {
 			//Stream it directly from remote
 			w.Header().Set("Content-Length", strconv.Itoa(int(targetFshAbs.GetFileSize(realFilepath))))

+ 14 - 0
mod/compatibility/browser.go

@@ -1,6 +1,7 @@
 package compatibility
 
 import (
+	"path/filepath"
 	"strconv"
 	"strings"
 )
@@ -40,3 +41,16 @@ func FirefoxBrowserVersionForBypassUploadMetaHeaderCheck(userAgent string) bool
 	//Not Firefox.
 	return true
 }
+
+//Handle browser compatibility issue regarding some special format type
+func BrowserCompatibilityOverrideContentType(userAgent string, filename string, contentType string) string {
+	if strings.Contains(userAgent, "Mozilla") && strings.Contains(userAgent, "Firefox/") {
+		//Firefox. Handle specal content-type serving
+		if filepath.Ext(filename) == ".ai" {
+			//Handle issue #105 for .ai file downloaded as .pdf on Firefox
+			//https://github.com/tobychui/arozos/issues/105
+			return "application/ai"
+		}
+	}
+	return contentType
+}

+ 1 - 1
mod/filesystem/filesystem.go

@@ -52,7 +52,7 @@ type FileSystemOpeningOptions struct{
 type HierarchySpecificConfig interface{}
 
 type FileSystemAbstraction interface {
-	//Fundemental Functions
+	//Fundamental Functions
 	Chmod(string, os.FileMode) error
 	Chown(string, int, int) error
 	Chtimes(string, time.Time, time.Time) error