mirror of
https://github.com/woodchen-ink/webp_server_go.git
synced 2025-07-18 13:42:02 +08:00
check image size (#170)
* check image size could be useful for #169 * Remove more deprecated ioutil lib, and fix CI problem * Fix deps * Write a bigger file for testing --------- Co-authored-by: n0vad3v <n0vad3v@riseup.net>
This commit is contained in:
parent
16ff497ade
commit
a53f0ac44a
1
.gitignore
vendored
1
.gitignore
vendored
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
# Dependency directories (remove the comment below to include it)
|
# Dependency directories (remove the comment below to include it)
|
||||||
exhaust/
|
exhaust/
|
||||||
|
exhaust_test/
|
||||||
builds/
|
builds/
|
||||||
/.idea/.gitignore
|
/.idea/.gitignore
|
||||||
/.idea/misc.xml
|
/.idea/misc.xml
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/h2non/filetype"
|
|
||||||
"hash/crc32"
|
"hash/crc32"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -12,6 +11,8 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/h2non/filetype"
|
||||||
|
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
|
|
||||||
"strings"
|
"strings"
|
||||||
@ -59,6 +60,10 @@ func imageExists(filename string) bool {
|
|||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if info.Size() < 100 {
|
||||||
|
// means something wrong in exhaust file system
|
||||||
|
return false
|
||||||
|
}
|
||||||
log.Debugf("file %s exists!", filename)
|
log.Debugf("file %s exists!", filename)
|
||||||
return !info.IsDir()
|
return !info.IsDir()
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -32,7 +33,7 @@ func TestFileCount(t *testing.T) {
|
|||||||
|
|
||||||
func TestImageExists(t *testing.T) {
|
func TestImageExists(t *testing.T) {
|
||||||
var data = "./pics/empty.jpg"
|
var data = "./pics/empty.jpg"
|
||||||
var result = !imageExists(data)
|
var result = imageExists(data)
|
||||||
|
|
||||||
if result {
|
if result {
|
||||||
t.Errorf("Result: [%v], Expected: [%v]", result, false)
|
t.Errorf("Result: [%v], Expected: [%v]", result, false)
|
||||||
@ -168,7 +169,8 @@ func TestFetchRemoteImage(t *testing.T) {
|
|||||||
func TestCleanProxyCache(t *testing.T) {
|
func TestCleanProxyCache(t *testing.T) {
|
||||||
// test normal situation
|
// test normal situation
|
||||||
fp := filepath.Join("./exhaust", "sample.png.12345.webp")
|
fp := filepath.Join("./exhaust", "sample.png.12345.webp")
|
||||||
_ = os.WriteFile(fp, []byte("1234"), 0755)
|
buf := make([]byte, 0x1000)
|
||||||
|
_ = os.WriteFile(fp, buf, 0755)
|
||||||
assert.True(t, imageExists(fp))
|
assert.True(t, imageExists(fp))
|
||||||
cleanProxyCache(fp)
|
cleanProxyCache(fp)
|
||||||
assert.False(t, imageExists(fp))
|
assert.False(t, imageExists(fp))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user