浏览代码

Fixed firefox download iso bug

Toby Chui 2 年之前
父节点
当前提交
2773e6b20b
共有 3 个文件被更改,包括 17353 次插入58 次删除
  1. 11 0
      mod/agi/agi.go
  2. 60 58
      mod/compatibility/browser.go
  3. 17282 0
      system/agi/polyfill.js

+ 11 - 0
mod/agi/agi.go

@@ -379,6 +379,17 @@ func (g *Gateway) ExecuteAGIScriptAsUser(scriptFile string, targetUser *user.Use
 		}
 	}()
 
+	//Read the polyfill
+	/*
+		polyfill, err := os.ReadFile("system/agi/polyfill.js")
+		if err == nil {
+			_, polyfillErr := vm.Run(string(polyfill))
+			if polyfillErr != nil {
+				log.Println("[AGI] Error occured while trying to polyfill the otto VM: " + polyfillErr.Error())
+			}
+		}
+	*/
+
 	//Try to read the script content
 	scriptContent, err := ioutil.ReadFile(scriptFile)
 	if err != nil {

+ 60 - 58
mod/compatibility/browser.go

@@ -1,58 +1,60 @@
-package compatibility
-
-import (
-	"path/filepath"
-	"strconv"
-	"strings"
-)
-
-/*
-	FirefoxBrowserVersionForBypassUploadMetaHeaderCheck
-
-	This function check if Firefox version is between 84 and 93.
-	If yes, this function will return TRUE and upload logic should not need to handle
-	META header for upload. If FALSE, please extract the relative filepath from the meta header.
-	Example Firefox userAgent header:
-	Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.02021/11/23
-*/
-func FirefoxBrowserVersionForBypassUploadMetaHeaderCheck(userAgent string) bool {
-	if strings.Contains(userAgent, "Mozilla") && strings.Contains(userAgent, "Firefox/") {
-		userAgentSegment := strings.Split(userAgent, " ")
-		for _, u := range userAgentSegment {
-			if len(u) > 4 && strings.TrimSpace(u)[:3] == "rv:" {
-				//This is the firefox version code
-				versionCode := strings.TrimSpace(u)[3 : len(u)-1]
-				vcodeNumeric, err := strconv.ParseFloat(versionCode, 64)
-				if err != nil {
-					//Unknown version of Firefox. Just check for META anyway
-					return false
-				}
-
-				if vcodeNumeric >= 84 && vcodeNumeric < 94 {
-					//Special versions of Firefox. Do not check for META header
-					return true
-				} else {
-					//Newer or equal to v94. Check it
-					return false
-				}
-			}
-		}
-	}
-	//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"
-		} else if filepath.Ext(filename) == ".apk" {
-			return "application/apk"
-		}
-	}
-	return contentType
-}
+package compatibility
+
+import (
+	"path/filepath"
+	"strconv"
+	"strings"
+)
+
+/*
+	FirefoxBrowserVersionForBypassUploadMetaHeaderCheck
+
+	This function check if Firefox version is between 84 and 93.
+	If yes, this function will return TRUE and upload logic should not need to handle
+	META header for upload. If FALSE, please extract the relative filepath from the meta header.
+	Example Firefox userAgent header:
+	Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.02021/11/23
+*/
+func FirefoxBrowserVersionForBypassUploadMetaHeaderCheck(userAgent string) bool {
+	if strings.Contains(userAgent, "Mozilla") && strings.Contains(userAgent, "Firefox/") {
+		userAgentSegment := strings.Split(userAgent, " ")
+		for _, u := range userAgentSegment {
+			if len(u) > 4 && strings.TrimSpace(u)[:3] == "rv:" {
+				//This is the firefox version code
+				versionCode := strings.TrimSpace(u)[3 : len(u)-1]
+				vcodeNumeric, err := strconv.ParseFloat(versionCode, 64)
+				if err != nil {
+					//Unknown version of Firefox. Just check for META anyway
+					return false
+				}
+
+				if vcodeNumeric >= 84 && vcodeNumeric < 94 {
+					//Special versions of Firefox. Do not check for META header
+					return true
+				} else {
+					//Newer or equal to v94. Check it
+					return false
+				}
+			}
+		}
+	}
+	//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"
+		} else if filepath.Ext(filename) == ".apk" {
+			return "application/apk"
+		} else if filepath.Ext(filename) == ".iso" {
+			return "application/x-iso9660-image"
+		}
+	}
+	return contentType
+}

文件差异内容过多而无法显示
+ 17282 - 0
system/agi/polyfill.js


部分文件因为文件数量过多而无法显示