url with non-ascii fix, bump version

This commit has fixed issue reported in PR 57, add test case
This commit is contained in:
BennyThink 2020-11-24 18:22:54 +08:00
parent 08c333f3cd
commit a67de53ae6
No known key found for this signature in database
GPG Key ID: 6CD0DBDA5235D481
6 changed files with 15 additions and 12 deletions

BIN
pics/太神啦.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 KiB

View File

@ -16,7 +16,7 @@ func TestPrefetchImages(t *testing.T) {
_ = os.Mkdir(fp, 0755) _ = os.Mkdir(fp, 0755)
prefetchImages("./pics", "./prefetch", "80") prefetchImages("./pics", "./prefetch", "80")
count := fileCount("./prefetch") count := fileCount("./prefetch")
assert.Equal(t, 6, count) assert.Equal(t, 7, count)
_ = os.RemoveAll(fp) _ = os.RemoveAll(fp)
// concurrency // concurrency
@ -24,6 +24,6 @@ func TestPrefetchImages(t *testing.T) {
_ = os.Mkdir(fp, 0755) _ = os.Mkdir(fp, 0755)
prefetchImages("./pics", "./prefetch", "80") prefetchImages("./pics", "./prefetch", "80")
count = fileCount("./prefetch") count = fileCount("./prefetch")
assert.Equal(t, 4, count) assert.Equal(t, 5, count)
_ = os.RemoveAll(fp) _ = os.RemoveAll(fp)
} }

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"net/url"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -14,7 +15,7 @@ import (
func convert(c *fiber.Ctx) error { func convert(c *fiber.Ctx) error {
//basic vars //basic vars
var reqURI = c.Path() // /mypic/123.jpg var reqURI, _ = url.QueryUnescape(c.Path()) // /mypic/123.jpg
var rawImageAbs = path.Join(config.ImgPath, reqURI) // /home/xxx/mypic/123.jpg var rawImageAbs = path.Join(config.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()

View File

@ -28,6 +28,8 @@ func TestConvert(t *testing.T) {
"http://127.0.0.1:3333/png.jpg": "image/webp", "http://127.0.0.1:3333/png.jpg": "image/webp",
"http://127.0.0.1:3333/12314.jpg": "text/plain; charset=utf-8", "http://127.0.0.1:3333/12314.jpg": "text/plain; charset=utf-8",
"http://127.0.0.1:3333/dir1/inside.jpg": "image/webp", "http://127.0.0.1:3333/dir1/inside.jpg": "image/webp",
"http://127.0.0.1:3333/%e5%a4%aa%e7%a5%9e%e5%95%a6.png": "image/webp",
"http://127.0.0.1:3333/太神啦.png": "image/webp",
} }
var testSafariLink = map[string]string{ var testSafariLink = map[string]string{

View File

@ -1,5 +1,5 @@
Name: webp-server Name: webp-server
Version: 0.2.1 Version: 0.2.2
Release: 1%{?dist} Release: 1%{?dist}
Summary: Go version of WebP Server. A tool that will serve your JPG/PNGs as WebP format with compression, on-the-fly. Summary: Go version of WebP Server. A tool that will serve your JPG/PNGs as WebP format with compression, on-the-fly.

View File

@ -28,7 +28,7 @@ var (
proxyMode bool proxyMode bool
config Config config Config
version = "0.2.1" version = "0.2.2"
) )
const ( const (