10000 add URLNoCached by zhangshanwen · Pull Request #491 · qor5/admin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add URLNoCached #491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions media/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func (b Base) URL(styles ...string) string {
return b.Url
}

func (b Base) URLNoCached(styles ...string) string {
return b.URL(styles...) + "?" + fmt.Sprint(time.Now().Nanosecond())
}

// String return file's url
func (b Base) String() string {
return b.URL()
Expand Down
17 changes: 16 additions & 1 deletion media/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/qor5/admin/v3/media"
"github.com/qor5/web/v3"
"os"
"strings"
"testing"

"github.com/qor/oss/filesystem"
Expand Down Expand Up @@ -130,7 +131,6 @@ func TestCrop(t *testing.T) {
return
}
}

func TestCopy(t *testing.T) {
db := setup()
f, err := box.ReadFile("testfile.png")
Expand Down Expand Up @@ -176,3 +176,18 @@ func TestCopy(t *testing.T) {
}

}
func TestUnCachedURL(t *testing.T) {
b := media_library.MediaBox{
Url: "test.jpg",
}
if !strings.Contains(b.URLNoCached(), "test.jpg?") {
t.Fatalf("set uncached url error %v", b.URLNoCached())
return
}
m := media_library.MediaLibrary{}
m.File.Url = "test2.jpg"
if !strings.Contains(m.File.URLNoCached(), "test2.jpg?") {
t.Fatalf("set uncached url error %v", m.File.URLNoCached())
return
}
}
4 changes: 4 additions & 0 deletions media/media_library/media_box.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"path"
"strings"
"time"

"github.com/qor5/admin/v3/media/base"
)
Expand Down Expand Up @@ -81,6 +82,9 @@ func (mediaBox *MediaBox) URL(styles ...string) string {
}
return mediaBox.Url
}
func (mediaBox *MediaBox) URLNoCached(styles ...string) string {
return mediaBox.URL(styles...) + "?" + fmt.Sprint(time.Now().Nanosecond())
}

func (mediaBox MediaBox) WebpURL(styles ...string) string {
url := mediaBox.URL(styles...)
Expand Down
Loading
0