Add another UA for original image (#40)

This commit is contained in:
Nova Kwok 2020-05-12 17:44:02 +08:00 committed by GitHub
parent 8784918f8e
commit acb020fb7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,13 +1,14 @@
package main package main
import ( import (
log "github.com/sirupsen/logrus"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
log "github.com/sirupsen/logrus"
"github.com/gofiber/fiber" "github.com/gofiber/fiber"
) )
@ -18,10 +19,9 @@ func Convert(ImgPath string, ExhaustPath string, AllowedTypes []string, QUALITY
var RawImageAbs = path.Join(ImgPath, reqURI) // /home/xxx/mypic/123.jpg var RawImageAbs = path.Join(ImgPath, reqURI) // /home/xxx/mypic/123.jpg
var ImgFilename = path.Base(reqURI) // pure filename, 123.jpg var ImgFilename = path.Base(reqURI) // pure filename, 123.jpg
var finalFile string // We'll only need one c.sendFile() var finalFile string // We'll only need one c.sendFile()
// Check for Safari users. If they're Safari, just simply ignore everything. // Check for Safari users. If they're Safari or the UA contains `AppleWebKit`(Might be the WeChat Browser), just simply ignore everything.
UA := c.Get("User-Agent") UA := c.Get("User-Agent")
if strings.Contains(UA, "Safari") && !strings.Contains(UA, "Chrome") && if (strings.Contains(UA, "Safari") && !strings.Contains(UA, "Chrome") && !strings.Contains(UA, "Firefox")) || (strings.Contains(UA, "AppleWebKit")) {
!strings.Contains(UA, "Firefox") {
log.Info("A Safari user has arrived...") log.Info("A Safari user has arrived...")
c.SendFile(RawImageAbs) c.SendFile(RawImageAbs)
return return