fix: 初验针对修改
This commit is contained in:
77
internal/storage/backend.go
Normal file
77
internal/storage/backend.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInsufficientSpace = errors.New("文件存储空间不足")
|
||||
ErrUploadLocked = errors.New("文件正在上传")
|
||||
ErrObjectNotFound = errors.New("文件对象不存在")
|
||||
)
|
||||
|
||||
type UploadRequest struct {
|
||||
FileID string
|
||||
ObjectKey string
|
||||
ContentType string
|
||||
ExpectedSize int64
|
||||
ExpiresAt time.Time
|
||||
}
|
||||
|
||||
type UploadInstruction struct {
|
||||
Method string `json:"method"`
|
||||
URL string `json:"url"`
|
||||
Headers map[string]string `json:"headers"`
|
||||
ExpiresAt time.Time `json:"expires_at"`
|
||||
}
|
||||
|
||||
type ByteRange struct {
|
||||
Start int64
|
||||
End int64
|
||||
}
|
||||
|
||||
func (r ByteRange) Length() int64 {
|
||||
return r.End - r.Start + 1
|
||||
}
|
||||
|
||||
type ObjectInfo struct {
|
||||
Size int64
|
||||
StorageETag string
|
||||
LastModified time.Time
|
||||
}
|
||||
|
||||
type DiskStatus struct {
|
||||
Path string `json:"path"`
|
||||
TotalBytes uint64 `json:"total_bytes"`
|
||||
UsedBytes uint64 `json:"used_bytes"`
|
||||
FreeBytes uint64 `json:"free_bytes"`
|
||||
UsedPercent float64 `json:"used_percent"`
|
||||
MinimumFreeBytes uint64 `json:"minimum_free_bytes"`
|
||||
Level string `json:"level"`
|
||||
}
|
||||
|
||||
type RuntimeStatus struct {
|
||||
Provider string `json:"provider"`
|
||||
Container string `json:"container"`
|
||||
Writable bool `json:"writable"`
|
||||
Disk *DiskStatus `json:"disk,omitempty"`
|
||||
}
|
||||
|
||||
type Backend interface {
|
||||
Provider() string
|
||||
Container() string
|
||||
PrepareUpload(context.Context, UploadRequest) (UploadInstruction, error)
|
||||
Open(context.Context, string, *ByteRange) (io.ReadCloser, error)
|
||||
Stat(context.Context, string) (ObjectInfo, error)
|
||||
Delete(context.Context, string) error
|
||||
Status(context.Context) (RuntimeStatus, error)
|
||||
}
|
||||
|
||||
type UploadReceiver interface {
|
||||
AcquireUpload(context.Context, string) (release func() error, err error)
|
||||
ReceiveUpload(context.Context, UploadRequest, io.Reader) (ObjectInfo, error)
|
||||
DiscardUpload(context.Context, string) error
|
||||
}
|
||||
Reference in New Issue
Block a user