2022-06-15 12:31:23 +00:00
|
|
|
package fs
|
|
|
|
|
2022-06-23 15:03:11 +00:00
|
|
|
import (
|
|
|
|
"context"
|
2022-06-28 10:00:11 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/driver"
|
2022-06-23 15:03:11 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/model"
|
2022-08-31 13:01:15 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/op"
|
2024-11-01 15:32:26 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/task"
|
2022-06-23 15:03:11 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
2025-01-18 15:28:12 +00:00
|
|
|
"io"
|
2022-06-23 15:03:11 +00:00
|
|
|
)
|
|
|
|
|
2022-08-31 14:08:12 +00:00
|
|
|
// the param named path of functions in this package is a mount path
|
|
|
|
// So, the purpose of this package is to convert mount path to actual path
|
2022-08-31 13:01:15 +00:00
|
|
|
// then pass the actual path to the op package
|
2022-06-23 15:03:11 +00:00
|
|
|
|
2023-04-06 16:02:07 +00:00
|
|
|
type ListArgs struct {
|
|
|
|
Refresh bool
|
|
|
|
NoLog bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func List(ctx context.Context, path string, args *ListArgs) ([]model.Obj, error) {
|
|
|
|
res, err := list(ctx, path, args)
|
2022-06-23 15:03:11 +00:00
|
|
|
if err != nil {
|
2023-04-09 06:06:04 +00:00
|
|
|
if !args.NoLog {
|
|
|
|
log.Errorf("failed list %s: %+v", path, err)
|
|
|
|
}
|
2022-06-23 15:03:11 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
2023-04-06 16:02:07 +00:00
|
|
|
type GetArgs struct {
|
|
|
|
NoLog bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func Get(ctx context.Context, path string, args *GetArgs) (model.Obj, error) {
|
2022-06-23 15:03:11 +00:00
|
|
|
res, err := get(ctx, path)
|
2023-04-09 06:06:04 +00:00
|
|
|
if err != nil {
|
|
|
|
if !args.NoLog {
|
feat: Crypt driver, improve http/webdav handling (#4884)
this PR has several enhancements, fixes, and features:
- [x] Crypt: a transparent encryption driver. Anyone can easily, and safely store encrypted data on the remote storage provider. Consider your data is safely stored in the safe, and the storage provider can only see the safe, but not your data.
- [x] Optional: compatible with [Rclone Crypt](https://rclone.org/crypt/). More ways to manipulate the encrypted data.
- [x] directory and filename encryption
- [x] server-side encryption mode (server encrypts & decrypts all data, all data flows thru the server)
- [x] obfuscate sensitive information internally
- [x] introduced a server memory-cached multi-thread downloader.
- [x] Driver: **Quark** enabled this feature, faster load in any single thread scenario. e.g. media player directly playing from the link, now it's faster.
- [x] general improvement on HTTP/WebDAV stream processing & header handling & response handling
- [x] Driver: **Mega** driver support ranged http header
- [x] Driver: **Quark** fix bug of not closing HTTP request to Quark server while user end has closed connection to alist
## Crypt, a transparent Encrypt/Decrypt Driver. (Rclone Crypt compatible)
e.g.
Crypt mount path -> /vault
Crypt remote path -> /ali/encrypted
Aliyun mount paht -> /ali
when the user uploads a.jpg to /vault, the data will be encrypted and saved to /ali/encrypted/xxxxx. And when the user wants to access a.jpg, it's automatically decrypted, and the user can do anything with it.
Since it's Rclone Crypt compatible, users can download /ali/encrypted/xxxxx and decrypt it with rclone crypt tool. Or the user can mount this folder using rclone, then mount the decrypted folder in Linux...
NB. Some breaking changes is made to make it follow global standard, e.g. processing the HTTP header properly.
close #4679
close #4827
Co-authored-by: Sean He <866155+seanhe26@users.noreply.github.com>
Co-authored-by: Andy Hsu <i@nn.ci>
2023-08-02 06:40:36 +00:00
|
|
|
log.Warnf("failed get %s: %s", path, err)
|
2023-04-09 06:06:04 +00:00
|
|
|
}
|
2022-06-23 15:03:11 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
2022-06-28 13:58:46 +00:00
|
|
|
func Link(ctx context.Context, path string, args model.LinkArgs) (*model.Link, model.Obj, error) {
|
|
|
|
res, file, err := link(ctx, path, args)
|
2022-06-23 15:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed link %s: %+v", path, err)
|
2022-06-28 13:58:46 +00:00
|
|
|
return nil, nil, err
|
2022-06-23 15:03:11 +00:00
|
|
|
}
|
2022-06-28 13:58:46 +00:00
|
|
|
return res, file, nil
|
2022-06-23 15:03:11 +00:00
|
|
|
}
|
|
|
|
|
2022-12-20 07:02:40 +00:00
|
|
|
func MakeDir(ctx context.Context, path string, lazyCache ...bool) error {
|
|
|
|
err := makeDir(ctx, path, lazyCache...)
|
2022-06-23 15:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed make dir %s: %+v", path, err)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-12-20 07:02:40 +00:00
|
|
|
func Move(ctx context.Context, srcPath, dstDirPath string, lazyCache ...bool) error {
|
|
|
|
err := move(ctx, srcPath, dstDirPath, lazyCache...)
|
2022-06-23 15:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed move %s to %s: %+v", srcPath, dstDirPath, err)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-12-25 13:09:54 +00:00
|
|
|
func Copy(ctx context.Context, srcObjPath, dstDirPath string, lazyCache ...bool) (task.TaskExtensionInfo, error) {
|
2022-12-20 07:02:40 +00:00
|
|
|
res, err := _copy(ctx, srcObjPath, dstDirPath, lazyCache...)
|
2022-06-23 15:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed copy %s to %s: %+v", srcObjPath, dstDirPath, err)
|
|
|
|
}
|
|
|
|
return res, err
|
|
|
|
}
|
|
|
|
|
2022-12-20 07:02:40 +00:00
|
|
|
func Rename(ctx context.Context, srcPath, dstName string, lazyCache ...bool) error {
|
|
|
|
err := rename(ctx, srcPath, dstName, lazyCache...)
|
2022-06-23 15:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed rename %s to %s: %+v", srcPath, dstName, err)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func Remove(ctx context.Context, path string) error {
|
|
|
|
err := remove(ctx, path)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed remove %s: %+v", path, err)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-08-27 13:14:23 +00:00
|
|
|
func PutDirectly(ctx context.Context, dstDirPath string, file model.FileStreamer, lazyCache ...bool) error {
|
2022-12-20 07:02:40 +00:00
|
|
|
err := putDirectly(ctx, dstDirPath, file, lazyCache...)
|
2022-06-24 06:21:28 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed put %s: %+v", dstDirPath, err)
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-12-25 13:09:54 +00:00
|
|
|
func PutAsTask(ctx context.Context, dstDirPath string, file model.FileStreamer) (task.TaskExtensionInfo, error) {
|
2024-11-01 15:32:26 +00:00
|
|
|
t, err := putAsTask(ctx, dstDirPath, file)
|
2022-06-23 15:03:11 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed put %s: %+v", dstDirPath, err)
|
|
|
|
}
|
2023-12-03 06:44:20 +00:00
|
|
|
return t, err
|
2022-06-23 15:03:11 +00:00
|
|
|
}
|
2022-06-28 10:00:11 +00:00
|
|
|
|
2025-01-18 15:28:12 +00:00
|
|
|
func ArchiveMeta(ctx context.Context, path string, args model.ArchiveMetaArgs) (*model.ArchiveMetaProvider, error) {
|
|
|
|
meta, err := archiveMeta(ctx, path, args)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed get archive meta %s: %+v", path, err)
|
|
|
|
}
|
|
|
|
return meta, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func ArchiveList(ctx context.Context, path string, args model.ArchiveListArgs) ([]model.Obj, error) {
|
|
|
|
objs, err := archiveList(ctx, path, args)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed list archive [%s]%s: %+v", path, args.InnerPath, err)
|
|
|
|
}
|
|
|
|
return objs, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func ArchiveDecompress(ctx context.Context, srcObjPath, dstDirPath string, args model.ArchiveDecompressArgs, lazyCache ...bool) (task.TaskExtensionInfo, error) {
|
|
|
|
t, err := archiveDecompress(ctx, srcObjPath, dstDirPath, args, lazyCache...)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed decompress [%s]%s: %+v", srcObjPath, args.InnerPath, err)
|
|
|
|
}
|
|
|
|
return t, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func ArchiveDriverExtract(ctx context.Context, path string, args model.ArchiveInnerArgs) (*model.Link, model.Obj, error) {
|
|
|
|
l, obj, err := archiveDriverExtract(ctx, path, args)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed extract [%s]%s: %+v", path, args.InnerPath, err)
|
|
|
|
}
|
|
|
|
return l, obj, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func ArchiveInternalExtract(ctx context.Context, path string, args model.ArchiveInnerArgs) (io.ReadCloser, int64, error) {
|
|
|
|
l, obj, err := archiveInternalExtract(ctx, path, args)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed extract [%s]%s: %+v", path, args.InnerPath, err)
|
|
|
|
}
|
|
|
|
return l, obj, err
|
|
|
|
}
|
|
|
|
|
2023-04-06 16:02:07 +00:00
|
|
|
type GetStoragesArgs struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetStorage(path string, args *GetStoragesArgs) (driver.Driver, error) {
|
2022-08-31 13:01:15 +00:00
|
|
|
storageDriver, _, err := op.GetStorageAndActualPath(path)
|
2023-04-09 06:06:04 +00:00
|
|
|
if err != nil {
|
2022-06-28 10:00:11 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2022-07-10 06:45:39 +00:00
|
|
|
return storageDriver, nil
|
2022-06-28 10:00:11 +00:00
|
|
|
}
|
2022-08-03 06:14:37 +00:00
|
|
|
|
|
|
|
func Other(ctx context.Context, args model.FsOtherArgs) (interface{}, error) {
|
|
|
|
res, err := other(ctx, args)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf("failed remove %s: %+v", args.Path, err)
|
|
|
|
}
|
|
|
|
return res, err
|
|
|
|
}
|