Skip to content
Open
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ require (
github.com/blevesearch/zapx/v15 v15.4.2 // indirect
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
github.com/bytedance/sonic v1.13.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0
github.com/coreos/go-semver v0.3.1 // indirect
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,6 @@ github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7Fsg
github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/halalcloud/golang-sdk-lite v0.0.0-20251006164234-3c629727c499 h1:4ovnBdiGDFi8putQGxhipuuhXItAgh4/YnzufPYkZkQ=
github.com/halalcloud/golang-sdk-lite v0.0.0-20251006164234-3c629727c499/go.mod h1:8x1h4rm3s8xMcTyJrq848sQ6BJnKzl57mDY4CNshdPM=
github.com/halalcloud/golang-sdk-lite v0.0.0-20251105081800-78cbb6786c38 h1:lsK2GVgI2Ox0NkRpQnN09GBOH7jtsjFK5tcIgxXlLr0=
github.com/halalcloud/golang-sdk-lite v0.0.0-20251105081800-78cbb6786c38/go.mod h1:8x1h4rm3s8xMcTyJrq848sQ6BJnKzl57mDY4CNshdPM=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand Down
26 changes: 26 additions & 0 deletions internal/bootstrap/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/OpenListTeam/OpenList/v4/cmd/flags"
"github.com/OpenListTeam/OpenList/v4/drivers/base"
Expand Down Expand Up @@ -184,6 +185,31 @@ func CleanTempDir() {
}
}

func CleanStaleChunks() {
chunkDir := filepath.Join(conf.Conf.TempDir, "chunks")
if !utils.Exists(chunkDir) {
return
}
files, err := os.ReadDir(chunkDir)
if err != nil {
log.Errorln("failed list chunks: ", err)
return
}
now := time.Now()
for _, file := range files {
info, err := file.Info()
if err != nil {
continue
}
// Clean up chunks older than 24 hours
if now.Sub(info.ModTime()) > 24*time.Hour {
if err := os.RemoveAll(filepath.Join(chunkDir, file.Name())); err != nil {
log.Errorln("failed delete stale chunk: ", err)
}
}
}
}

// validateProxyConfig validates proxy configuration and displays status at startup
func validateProxyConfig() {
if conf.Conf.ProxyAddress != "" {
Expand Down
9 changes: 9 additions & 0 deletions internal/bootstrap/data/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ func InitialSettings() []model.SettingItem {
{Key: conf.StreamMaxClientUploadSpeed, Value: "-1", Type: conf.TypeNumber, Group: model.TRAFFIC, Flag: model.PRIVATE},
{Key: conf.StreamMaxServerDownloadSpeed, Value: "-1", Type: conf.TypeNumber, Group: model.TRAFFIC, Flag: model.PRIVATE},
{Key: conf.StreamMaxServerUploadSpeed, Value: "-1", Type: conf.TypeNumber, Group: model.TRAFFIC, Flag: model.PRIVATE},

// HTTP Server configuration (for large file transfers)
{Key: conf.HTTPServerReadTimeout, Value: "0", Type: conf.TypeNumber, Group: model.TRAFFIC, Flag: model.PRIVATE, Help: "HTTP read request timeout (seconds), 0 means no limit. Recommended to set to 0 to support large file uploads."},
{Key: conf.HTTPServerWriteTimeout, Value: "0", Type: conf.TypeNumber, Group: model.TRAFFIC, Flag: model.PRIVATE, Help: "HTTP write response timeout (seconds), 0 means no limit. Recommended to set to 0 to support large file downloads."},
{Key: conf.HTTPServerIdleTimeout, Value: "120", Type: conf.TypeNumber, Group: model.TRAFFIC, Flag: model.PRIVATE, Help: "HTTP idle connection timeout (seconds). Recommended to set to 120 seconds to allow for brief network fluctuations."},
{Key: conf.HTTPServerReadHeaderTimeout, Value: "30", Type: conf.TypeNumber, Group: model.TRAFFIC, Flag: model.PRIVATE, Help: "HTTP read header timeout (seconds) to prevent slow attacks. Recommended to set to 30 seconds."},
{Key: conf.HTTPServerMaxHeaderBytes, Value: "1048576", Type: conf.TypeNumber, Group: model.TRAFFIC, Flag: model.PRIVATE, Help: "Maximum bytes for HTTP header, defaults to 1MB (1048576)."},
// Chunked upload configuration (to bypass Cloudflare CDN limits)
{Key: conf.ChunkedUploadChunkSize, Value: "95", Type: conf.TypeNumber, Group: model.TRAFFIC, Flag: model.PUBLIC, Help: "Chunked upload threshold (MB). Files exceeding this size will be uploaded in chunks. Recommended to set to 95 to bypass Cloudflare's 100MB limit."},
}
additionalSettingItems := tool.Tools.Items()
// 固定顺序
Expand Down
10 changes: 10 additions & 0 deletions internal/bootstrap/task.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package bootstrap

import (
"time"

"github.com/OpenListTeam/OpenList/v4/internal/conf"
"github.com/OpenListTeam/OpenList/v4/internal/db"
"github.com/OpenListTeam/OpenList/v4/internal/fs"
"github.com/OpenListTeam/OpenList/v4/internal/offline_download/tool"
"github.com/OpenListTeam/OpenList/v4/internal/op"
"github.com/OpenListTeam/OpenList/v4/internal/setting"
"github.com/OpenListTeam/OpenList/v4/pkg/cron"
"github.com/OpenListTeam/tache"
)

Expand Down Expand Up @@ -49,4 +52,11 @@ func InitTaskManager() {
op.RegisterSettingChangingCallback(func() {
fs.ArchiveContentUploadTaskManager.SetWorkersNumActive(taskFilterNegative(setting.GetInt(conf.TaskDecompressUploadThreadsNum, conf.Conf.Tasks.DecompressUpload.Workers)))
})

// Start background task to clean stale chunks every 10 minutes
go func() {
c := cron.NewCron(10 * time.Minute)
c.Do(CleanStaleChunks)
}()
}

14 changes: 11 additions & 3 deletions internal/conf/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ const (
// 115
Pan115TempDir = "115_temp_dir"

// 123
Pan123TempDir = "123_temp_dir"

// 115_open
Pan115OpenTempDir = "115_open_temp_dir"

Expand Down Expand Up @@ -139,6 +136,7 @@ const (
// 123 open offline download
Pan123OpenOfflineDownloadCallbackUrl = "123_open_callback_url"
Pan123OpenTempDir = "123_open_temp_dir"
Pan123TempDir = "123_temp_dir"

// ftp
FTPPublicHost = "ftp_public_host"
Expand All @@ -161,6 +159,16 @@ const (
StreamMaxClientUploadSpeed = "max_client_upload_speed"
StreamMaxServerDownloadSpeed = "max_server_download_speed"
StreamMaxServerUploadSpeed = "max_server_upload_speed"

// HTTP Server Timeouts (传输超时配置)
HTTPServerReadTimeout = "http_server_read_timeout" // 读取请求超时(秒),0表示无限制
HTTPServerWriteTimeout = "http_server_write_timeout" // 写入响应超时(秒),0表示无限制
HTTPServerIdleTimeout = "http_server_idle_timeout" // 空闲连接超时(秒)
HTTPServerReadHeaderTimeout = "http_server_read_header_timeout" // 读取Header超时(秒)
HTTPServerMaxHeaderBytes = "http_server_max_header_bytes" // Header最大字节数

// Chunked Upload (分片上传配置)
ChunkedUploadChunkSize = "chunked_upload_chunk_size" // 分片大小(MB),超过此大小的文件将自动分片上传
)

const (
Expand Down
13 changes: 13 additions & 0 deletions pkg/utils/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import (
"encoding/json"
"errors"
"hash"
"hash/crc32"
"hash/crc64"
"io"
"iter"

"github.com/OpenListTeam/OpenList/v4/internal/errs"
"github.com/cespare/xxhash/v2"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -90,6 +93,15 @@ var (

// SHA256 indicates SHA-256 support
SHA256 = RegisterHash("sha256", "SHA-256", 64, sha256.New)

// CRC32 indicates CRC-32 support (IEEE polynomial)
CRC32 = RegisterHash("crc32", "CRC-32", 8, func() hash.Hash { return crc32.NewIEEE() })

// CRC64 indicates CRC-64 support (ECMA polynomial)
CRC64 = RegisterHash("crc64", "CRC-64", 16, func() hash.Hash { return crc64.New(crc64.MakeTable(crc64.ECMA)) })

// XXH64 indicates xxHash64 support
XXH64 = RegisterHash("xxh64", "XXH64", 16, func() hash.Hash { return xxhash.New() })
)

// HashData get hash of one hashType
Expand Down Expand Up @@ -242,3 +254,4 @@ func (hi HashInfo) All() iter.Seq2[*HashType, string] {
}
}
}

Loading