mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-27 01:51:56 +08:00
enhance(download): Use just-in-time host in download URl, instead of SiteURL in site settings
This commit is contained in:
@@ -91,7 +91,6 @@ func (handler Driver) Get(ctx context.Context, path string) (response.RSCloser,
|
||||
downloadURL, err := handler.Source(
|
||||
ctx,
|
||||
path,
|
||||
url.URL{},
|
||||
60,
|
||||
false,
|
||||
0,
|
||||
@@ -164,7 +163,6 @@ func (handler Driver) Thumb(ctx context.Context, file *model.File) (*response.Co
|
||||
func (handler Driver) Source(
|
||||
ctx context.Context,
|
||||
path string,
|
||||
baseURL url.URL,
|
||||
ttl int64,
|
||||
isDownload bool,
|
||||
speed int,
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -106,7 +105,7 @@ func TestDriver_Source(t *testing.T) {
|
||||
|
||||
// 失败
|
||||
{
|
||||
res, err := handler.Source(context.Background(), "123.jpg", url.URL{}, 1, true, 0)
|
||||
res, err := handler.Source(context.Background(), "123.jpg", 1, true, 0)
|
||||
asserts.Error(err)
|
||||
asserts.Empty(res)
|
||||
}
|
||||
@@ -116,7 +115,7 @@ func TestDriver_Source(t *testing.T) {
|
||||
handler.Client.Credential.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix()
|
||||
handler.Client.Credential.AccessToken = "1"
|
||||
cache.Set("onedrive_source_0_123.jpg", "res", 1)
|
||||
res, err := handler.Source(context.Background(), "123.jpg", url.URL{}, 0, true, 0)
|
||||
res, err := handler.Source(context.Background(), "123.jpg", 0, true, 0)
|
||||
cache.Deletes([]string{"0_123.jpg"}, "onedrive_source_")
|
||||
asserts.NoError(err)
|
||||
asserts.Equal("res", res)
|
||||
@@ -131,7 +130,7 @@ func TestDriver_Source(t *testing.T) {
|
||||
handler.Client.Credential.ExpiresIn = time.Now().Add(time.Duration(100) * time.Hour).Unix()
|
||||
handler.Client.Credential.AccessToken = "1"
|
||||
cache.Set(fmt.Sprintf("onedrive_source_file_%d_1", file.UpdatedAt.Unix()), "res", 0)
|
||||
res, err := handler.Source(ctx, "123.jpg", url.URL{}, 1, true, 0)
|
||||
res, err := handler.Source(ctx, "123.jpg", 1, true, 0)
|
||||
cache.Deletes([]string{"0_123.jpg"}, "onedrive_source_")
|
||||
asserts.NoError(err)
|
||||
asserts.Equal("res", res)
|
||||
@@ -156,7 +155,7 @@ func TestDriver_Source(t *testing.T) {
|
||||
})
|
||||
handler.Client.Request = clientMock
|
||||
handler.Client.Credential.AccessToken = "1"
|
||||
res, err := handler.Source(context.Background(), "123.jpg", url.URL{}, 1, true, 0)
|
||||
res, err := handler.Source(context.Background(), "123.jpg", 1, true, 0)
|
||||
asserts.NoError(err)
|
||||
asserts.Equal("123321", res)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user