2022-10-08 14:16:41 +00:00
|
|
|
package mega
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
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
|
|
|
"time"
|
2022-10-08 14:16:41 +00:00
|
|
|
|
2023-11-06 08:56:55 +00:00
|
|
|
"github.com/alist-org/alist/v3/pkg/http_range"
|
2024-05-22 15:28:14 +00:00
|
|
|
"github.com/pquerna/otp/totp"
|
2023-11-06 08:56:55 +00:00
|
|
|
"github.com/rclone/rclone/lib/readers"
|
|
|
|
|
2022-10-08 14:16:41 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/driver"
|
|
|
|
"github.com/alist-org/alist/v3/internal/errs"
|
|
|
|
"github.com/alist-org/alist/v3/internal/model"
|
2022-12-21 07:03:09 +00:00
|
|
|
"github.com/alist-org/alist/v3/pkg/utils"
|
2022-10-08 14:16:41 +00:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/t3rm1n4l/go-mega"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Mega struct {
|
|
|
|
model.Storage
|
|
|
|
Addition
|
|
|
|
c *mega.Mega
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Mega) Config() driver.Config {
|
|
|
|
return config
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Mega) GetAddition() driver.Additional {
|
2022-12-13 10:03:30 +00:00
|
|
|
return &d.Addition
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
|
|
|
|
2022-12-13 10:03:30 +00:00
|
|
|
func (d *Mega) Init(ctx context.Context) error {
|
2024-05-22 15:28:14 +00:00
|
|
|
var twoFACode = d.TwoFACode
|
2022-10-08 14:16:41 +00:00
|
|
|
d.c = mega.New()
|
2024-05-22 15:28:14 +00:00
|
|
|
if d.TwoFASecret != "" {
|
|
|
|
code, err := totp.GenerateCode(d.TwoFASecret, time.Now())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("generate totp code failed: %w", err)
|
|
|
|
}
|
|
|
|
twoFACode = code
|
|
|
|
}
|
|
|
|
return d.c.MultiFactorLogin(d.Email, d.Password, twoFACode)
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Mega) Drop(ctx context.Context) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Mega) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([]model.Obj, error) {
|
|
|
|
if node, ok := dir.(*MegaNode); ok {
|
2023-08-27 13:14:23 +00:00
|
|
|
nodes, err := d.c.FS.GetChildren(node.n)
|
2022-10-08 14:16:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
res := make([]model.Obj, 0)
|
|
|
|
for i := range nodes {
|
|
|
|
n := nodes[i]
|
|
|
|
if n.GetType() == mega.FILE || n.GetType() == mega.FOLDER {
|
|
|
|
res = append(res, &MegaNode{n})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
log.Errorf("can't convert: %+v", dir)
|
2023-08-27 13:14:23 +00:00
|
|
|
return nil, fmt.Errorf("unable to convert dir to mega n")
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
|
|
|
|
2022-12-17 11:49:05 +00:00
|
|
|
func (d *Mega) GetRoot(ctx context.Context) (model.Obj, error) {
|
|
|
|
n := d.c.FS.GetRoot()
|
|
|
|
log.Debugf("mega root: %+v", *n)
|
|
|
|
return &MegaNode{n}, nil
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Mega) Link(ctx context.Context, file model.Obj, args model.LinkArgs) (*model.Link, error) {
|
|
|
|
if node, ok := file.(*MegaNode); ok {
|
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
|
|
|
|
2023-08-27 13:14:23 +00:00
|
|
|
//down, err := d.c.NewDownload(n.Node)
|
2022-10-08 14:16:41 +00:00
|
|
|
//if err != nil {
|
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
|
|
|
// return nil, fmt.Errorf("open download file failed: %w", err)
|
2022-10-08 14:16:41 +00:00
|
|
|
//}
|
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
|
|
|
|
|
|
|
size := file.GetSize()
|
2023-08-27 13:14:23 +00:00
|
|
|
resultRangeReader := func(ctx context.Context, httpRange http_range.Range) (io.ReadCloser, error) {
|
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
|
|
|
length := httpRange.Length
|
|
|
|
if httpRange.Length >= 0 && httpRange.Start+httpRange.Length >= size {
|
|
|
|
length = -1
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
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
|
|
|
var down *mega.Download
|
|
|
|
err := utils.Retry(3, time.Second, func() (err error) {
|
2023-08-27 13:14:23 +00:00
|
|
|
down, err = d.c.NewDownload(node.n)
|
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
|
|
|
return err
|
|
|
|
})
|
2022-10-08 14:16:41 +00:00
|
|
|
if err != nil {
|
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
|
|
|
return nil, fmt.Errorf("open download file failed: %w", err)
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
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
|
|
|
oo := &openObject{
|
|
|
|
ctx: ctx,
|
|
|
|
d: down,
|
|
|
|
skip: httpRange.Start,
|
|
|
|
}
|
|
|
|
|
|
|
|
return readers.NewLimitedReadCloser(oo, length), nil
|
|
|
|
}
|
2025-01-27 12:08:39 +00:00
|
|
|
resultRangeReadCloser := &model.RangeReadCloser{RangeReader: resultRangeReader}
|
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
|
|
|
resultLink := &model.Link{
|
2023-08-27 13:14:23 +00:00
|
|
|
RangeReadCloser: resultRangeReadCloser,
|
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
|
|
|
}
|
|
|
|
return resultLink, nil
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
2023-08-27 13:14:23 +00:00
|
|
|
return nil, fmt.Errorf("unable to convert dir to mega n")
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Mega) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) error {
|
|
|
|
if parentNode, ok := parentDir.(*MegaNode); ok {
|
2023-08-27 13:14:23 +00:00
|
|
|
_, err := d.c.CreateDir(dirName, parentNode.n)
|
2022-10-08 14:16:41 +00:00
|
|
|
return err
|
|
|
|
}
|
2023-08-27 13:14:23 +00:00
|
|
|
return fmt.Errorf("unable to convert dir to mega n")
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Mega) Move(ctx context.Context, srcObj, dstDir model.Obj) error {
|
|
|
|
if srcNode, ok := srcObj.(*MegaNode); ok {
|
|
|
|
if dstNode, ok := dstDir.(*MegaNode); ok {
|
2023-08-27 13:14:23 +00:00
|
|
|
return d.c.Move(srcNode.n, dstNode.n)
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-27 13:14:23 +00:00
|
|
|
return fmt.Errorf("unable to convert dir to mega n")
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Mega) Rename(ctx context.Context, srcObj model.Obj, newName string) error {
|
|
|
|
if srcNode, ok := srcObj.(*MegaNode); ok {
|
2023-08-27 13:14:23 +00:00
|
|
|
return d.c.Rename(srcNode.n, newName)
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
2023-08-27 13:14:23 +00:00
|
|
|
return fmt.Errorf("unable to convert dir to mega n")
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Mega) Copy(ctx context.Context, srcObj, dstDir model.Obj) error {
|
|
|
|
return errs.NotImplement
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Mega) Remove(ctx context.Context, obj model.Obj) error {
|
|
|
|
if node, ok := obj.(*MegaNode); ok {
|
2023-08-27 13:14:23 +00:00
|
|
|
return d.c.Delete(node.n, false)
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
2023-08-27 13:14:23 +00:00
|
|
|
return fmt.Errorf("unable to convert dir to mega n")
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *Mega) Put(ctx context.Context, dstDir model.Obj, stream model.FileStreamer, up driver.UpdateProgress) error {
|
|
|
|
if dstNode, ok := dstDir.(*MegaNode); ok {
|
2023-08-27 13:14:23 +00:00
|
|
|
u, err := d.c.NewUpload(dstNode.n, stream.GetName(), stream.GetSize())
|
2022-10-08 14:16:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for id := 0; id < u.Chunks(); id++ {
|
2022-12-21 07:03:09 +00:00
|
|
|
if utils.IsCanceled(ctx) {
|
|
|
|
return ctx.Err()
|
|
|
|
}
|
2022-10-08 14:16:41 +00:00
|
|
|
_, chkSize, err := u.ChunkLocation(id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
chunk := make([]byte, chkSize)
|
|
|
|
n, err := io.ReadFull(stream, chunk)
|
|
|
|
if err != nil && err != io.EOF {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if n != len(chunk) {
|
|
|
|
return errors.New("chunk too short")
|
|
|
|
}
|
|
|
|
|
|
|
|
err = u.UploadChunk(id, chunk)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-11-06 08:56:55 +00:00
|
|
|
up(float64(id) * 100 / float64(u.Chunks()))
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_, err = u.Finish()
|
|
|
|
return err
|
|
|
|
}
|
2023-08-27 13:14:23 +00:00
|
|
|
return fmt.Errorf("unable to convert dir to mega n")
|
2022-10-08 14:16:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//func (d *Mega) Other(ctx context.Context, args model.OtherArgs) (interface{}, error) {
|
|
|
|
// return nil, errs.NotSupport
|
|
|
|
//}
|
|
|
|
|
|
|
|
var _ driver.Driver = (*Mega)(nil)
|