Skip to content

Commit

Permalink
feat: Crypt driver, improve http/webdav handling (#4884)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Andy Hsu <[email protected]>
  • Loading branch information
3 people authored Aug 2, 2023
1 parent 1dc1dd1 commit 3c21a9a
Show file tree
Hide file tree
Showing 38 changed files with 2,858 additions and 332 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ English | [中文](./README_cn.md)| [日本語](./README_ja.md) | [Contributing]
- [x] Web upload(Can allow visitors to upload), delete, mkdir, rename, move and copy
- [x] Offline download
- [x] Copy files between two storage
- [x] Multi-thread downloading acceleration for single-thread download/stream

## Document

Expand Down
1 change: 1 addition & 0 deletions drivers/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
_ "github.com/alist-org/alist/v3/drivers/baidu_photo"
_ "github.com/alist-org/alist/v3/drivers/baidu_share"
_ "github.com/alist-org/alist/v3/drivers/cloudreve"
_ "github.com/alist-org/alist/v3/drivers/crypt"
_ "github.com/alist-org/alist/v3/drivers/dropbox"
_ "github.com/alist-org/alist/v3/drivers/ftp"
_ "github.com/alist-org/alist/v3/drivers/google_drive"
Expand Down
9 changes: 4 additions & 5 deletions drivers/baidu_photo/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package baiduphoto
import (
"context"
"fmt"
"io"
"net/http"

"github.com/alist-org/alist/v3/drivers/base"
Expand Down Expand Up @@ -400,7 +399,7 @@ func (d *BaiduPhoto) linkFile(ctx context.Context, file *File, args model.LinkAr
return link, nil
}

func (d *BaiduPhoto) linkStreamAlbum(ctx context.Context, file *AlbumFile) (*model.Link, error) {
/*func (d *BaiduPhoto) linkStreamAlbum(ctx context.Context, file *AlbumFile) (*model.Link, error) {
return &model.Link{
Header: http.Header{},
Writer: func(w io.Writer) error {
Expand All @@ -421,9 +420,9 @@ func (d *BaiduPhoto) linkStreamAlbum(ctx context.Context, file *AlbumFile) (*mod
return err
},
}, nil
}
}*/

func (d *BaiduPhoto) linkStream(ctx context.Context, file *File) (*model.Link, error) {
/*func (d *BaiduPhoto) linkStream(ctx context.Context, file *File) (*model.Link, error) {
return &model.Link{
Header: http.Header{},
Writer: func(w io.Writer) error {
Expand All @@ -441,7 +440,7 @@ func (d *BaiduPhoto) linkStream(ctx context.Context, file *File) (*model.Link, e
return err
},
}, nil
}
}*/

// 获取uk
func (d *BaiduPhoto) uInfo() (*UInfo, error) {
Expand Down
35 changes: 12 additions & 23 deletions drivers/base/util.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
package base

import (
"io"
"net/http"
"strconv"
import "io"

"github.com/alist-org/alist/v3/internal/model"
"github.com/alist-org/alist/v3/pkg/http_range"
"github.com/alist-org/alist/v3/pkg/utils"
)
type Closers struct {
closers []io.Closer
}

func HandleRange(link *model.Link, file io.ReadSeekCloser, header http.Header, size int64) {
if header.Get("Range") != "" {
r, err := http_range.ParseRange(header.Get("Range"), size)
if err == nil && len(r) > 0 {
_, err := file.Seek(r[0].Start, io.SeekStart)
if err == nil {
link.Data = utils.NewLimitReadCloser(file, func() error {
return file.Close()
}, r[0].Length)
link.Status = http.StatusPartialContent
link.Header = http.Header{
"Content-Range": []string{r[0].ContentRange(size)},
"Content-Length": []string{strconv.FormatInt(r[0].Length, 10)},
}
}
func (c *Closers) Close() (err error) {
for _, closer := range c.closers {
if closer != nil {
_ = closer.Close()
}
}
return nil
}
func (c *Closers) Add(closer io.Closer) {
c.closers = append(c.closers, closer)
}
Loading

0 comments on commit 3c21a9a

Please sign in to comment.