mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-07-18 17:38:07 +08:00

* fix(crypt): bug caused by link cache * perf(crypt,mega,halalcloud,quark,uc): optimize concurrent response link * chore: 删除无用代码 * ftp * 修复bug;资源释放 * 添加SyncClosers * local,sftp,smb * 重构,优化,增强 * Update internal/stream/util.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: j2rong4cn <36783515+j2rong4cn@users.noreply.github.com> * chore * chore * 优化,修复bug * . --------- Signed-off-by: j2rong4cn <36783515+j2rong4cn@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
108 lines
2.1 KiB
Go
108 lines
2.1 KiB
Go
package model
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"io"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/OpenListTeam/OpenList/v4/pkg/http_range"
|
|
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
|
|
)
|
|
|
|
type ListArgs struct {
|
|
ReqPath string
|
|
S3ShowPlaceholder bool
|
|
Refresh bool
|
|
}
|
|
|
|
type LinkArgs struct {
|
|
IP string
|
|
Header http.Header
|
|
Type string
|
|
Redirect bool
|
|
}
|
|
|
|
type Link struct {
|
|
URL string `json:"url"` // most common way
|
|
Header http.Header `json:"header"` // needed header (for url)
|
|
RangeReader RangeReaderIF `json:"-"` // recommended way if can't use URL
|
|
MFile File `json:"-"` // best for local,smb... file system, which exposes MFile
|
|
|
|
Expiration *time.Duration // local cache expire Duration
|
|
|
|
//for accelerating request, use multi-thread downloading
|
|
Concurrency int `json:"concurrency"`
|
|
PartSize int `json:"part_size"`
|
|
|
|
utils.SyncClosers `json:"-"`
|
|
}
|
|
|
|
func (l *Link) Close() error {
|
|
if clr, ok := l.MFile.(io.Closer); ok {
|
|
return errors.Join(clr.Close(), l.SyncClosers.Close())
|
|
}
|
|
return l.SyncClosers.Close()
|
|
}
|
|
|
|
type OtherArgs struct {
|
|
Obj Obj
|
|
Method string
|
|
Data interface{}
|
|
}
|
|
|
|
type FsOtherArgs struct {
|
|
Path string `json:"path" form:"path"`
|
|
Method string `json:"method" form:"method"`
|
|
Data interface{} `json:"data" form:"data"`
|
|
}
|
|
|
|
type ArchiveArgs struct {
|
|
Password string
|
|
LinkArgs
|
|
}
|
|
|
|
type ArchiveInnerArgs struct {
|
|
ArchiveArgs
|
|
InnerPath string
|
|
}
|
|
|
|
type ArchiveMetaArgs struct {
|
|
ArchiveArgs
|
|
Refresh bool
|
|
}
|
|
|
|
type ArchiveListArgs struct {
|
|
ArchiveInnerArgs
|
|
Refresh bool
|
|
}
|
|
|
|
type ArchiveDecompressArgs struct {
|
|
ArchiveInnerArgs
|
|
CacheFull bool
|
|
PutIntoNewDir bool
|
|
}
|
|
|
|
type RangeReaderIF interface {
|
|
RangeRead(ctx context.Context, httpRange http_range.Range) (io.ReadCloser, error)
|
|
}
|
|
|
|
type RangeReadCloserIF interface {
|
|
RangeReaderIF
|
|
utils.ClosersIF
|
|
}
|
|
|
|
var _ RangeReadCloserIF = (*RangeReadCloser)(nil)
|
|
|
|
type RangeReadCloser struct {
|
|
RangeReader RangeReaderIF
|
|
utils.Closers
|
|
}
|
|
|
|
func (r *RangeReadCloser) RangeRead(ctx context.Context, httpRange http_range.Range) (io.ReadCloser, error) {
|
|
rc, err := r.RangeReader.RangeRead(ctx, httpRange)
|
|
r.Add(rc)
|
|
return rc, err
|
|
}
|