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)
|
||||
exhaust/
|
||||
exhaust_test/
|
||||
builds/
|
||||
/.idea/.gitignore
|
||||
/.idea/misc.xml
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/h2non/filetype"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"net/http"
|
||||
@ -12,6 +11,8 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/h2non/filetype"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
|
||||
"strings"
|
||||
@ -59,6 +60,10 @@ func imageExists(filename string) bool {
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
if info.Size() < 100 {
|
||||
// means something wrong in exhaust file system
|
||||
return false
|
||||
}
|
||||
log.Debugf("file %s exists!", filename)
|
||||
return !info.IsDir()
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/valyala/fasthttp"
|
||||
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -32,7 +33,7 @@ func TestFileCount(t *testing.T) {
|
||||
|
||||
func TestImageExists(t *testing.T) {
|
||||
var data = "./pics/empty.jpg"
|
||||
var result = !imageExists(data)
|
||||
var result = imageExists(data)
|
||||
|
||||
if result {
|
||||
t.Errorf("Result: [%v], Expected: [%v]", result, false)
|
||||
@ -168,7 +169,8 @@ func TestFetchRemoteImage(t *testing.T) {
|
||||
func TestCleanProxyCache(t *testing.T) {
|
||||
// test normal situation
|
||||
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))
|
||||
cleanProxyCache(fp)
|
||||
assert.False(t, imageExists(fp))
|
||||
|
Loading…
x
Reference in New Issue
Block a user