Feat: async monitor OneDrive resume upload progress

This commit is contained in:
HFO4
2020-01-21 11:49:46 +08:00
parent dd5f6e3d25
commit 6aee31341f
8 changed files with 321 additions and 59 deletions

View File

@@ -47,7 +47,7 @@ func Init() {
// Debug模式下输出所有 SQL 日志
if conf.SystemConfig.Debug {
db.LogMode(true)
db.LogMode(false)
}
//db.SetLogger(util.Log())

View File

@@ -107,6 +107,8 @@ solid #e9e9e9;"bgcolor="#fff"><tbody><tr style="font-family: 'Helvetica Neue',He
{Name: "upload_credential_timeout", Value: `1800`, Type: "timeout"},
{Name: "upload_session_timeout", Value: `86400`, Type: "timeout"},
{Name: "slave_api_timeout", Value: `60`, Type: "timeout"},
{Name: "onedrive_monitor_timeout", Value: `600`, Type: "timeout"},
{Name: "onedrive_callback_check", Value: `20`, Type: "timeout"},
{Name: "allowdVisitorDownload", Value: `false`, Type: "share"},
{Name: "login_captcha", Value: `0`, Type: "login"},
{Name: "qq_login", Value: `0`, Type: "login"},

View File

@@ -180,7 +180,8 @@ func (policy *Policy) GetUploadURL() string {
var controller *url.URL
switch policy.Type {
case "local":
case "local", "onedrive":
server = GetSiteURL()
controller, _ = url.Parse("/api/v3/file/upload")
case "remote":
controller, _ = url.Parse("/api/v3/slave/upload")

View File

@@ -3,6 +3,7 @@ package model
import (
"encoding/json"
"github.com/DATA-DOG/go-sqlmock"
"github.com/HFO4/cloudreve/pkg/cache"
"github.com/stretchr/testify/assert"
"strconv"
"testing"
@@ -15,13 +16,13 @@ func TestGetPolicyByID(t *testing.T) {
// 缓存未命中
{
rows := sqlmock.NewRows([]string{"name", "type", "options"}).
AddRow("默认存储策略", "local", "{\"op_name\":\"123\"}")
AddRow("默认存储策略", "local", "{\"od_redirect\":\"123\"}")
mock.ExpectQuery("^SELECT(.+)").WillReturnRows(rows)
policy, err := GetPolicyByID(uint(22))
asserts.NoError(err)
asserts.NoError(mock.ExpectationsWereMet())
asserts.Equal("默认存储策略", policy.Name)
asserts.Equal("123", policy.OptionsSerialized.OPName)
asserts.Equal("123", policy.OptionsSerialized.OdRedirect)
rows = sqlmock.NewRows([]string{"name", "type", "options"})
mock.ExpectQuery("^SELECT(.+)").WillReturnRows(rows)
@@ -35,7 +36,7 @@ func TestGetPolicyByID(t *testing.T) {
policy, err := GetPolicyByID(uint(22))
asserts.NoError(err)
asserts.Equal("默认存储策略", policy.Name)
asserts.Equal("123", policy.OptionsSerialized.OPName)
asserts.Equal("123", policy.OptionsSerialized.OdRedirect)
}
@@ -46,7 +47,7 @@ func TestPolicy_BeforeSave(t *testing.T) {
testPolicy := Policy{
OptionsSerialized: PolicyOption{
OPName: "123",
OdRedirect: "123",
},
}
expected, _ := json.Marshal(testPolicy.OptionsSerialized)
@@ -163,6 +164,7 @@ func TestPolicy_GetUploadURL(t *testing.T) {
// 本地
{
cache.Set("setting_siteURL", "http://127.0.0.1", 0)
policy := Policy{Type: "local", Server: "http://127.0.0.1"}
asserts.Equal("http://127.0.0.1/api/v3/file/upload", policy.GetUploadURL())
}