2022-08-31 13:01:15 +00:00
|
|
|
package op
|
2022-06-07 10:13:55 +00:00
|
|
|
|
|
|
|
import (
|
2022-06-11 11:01:20 +00:00
|
|
|
"reflect"
|
|
|
|
"strings"
|
|
|
|
|
2022-08-07 05:23:15 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/conf"
|
|
|
|
|
2022-06-09 09:11:46 +00:00
|
|
|
"github.com/alist-org/alist/v3/internal/driver"
|
|
|
|
"github.com/pkg/errors"
|
2022-06-07 10:13:55 +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
|
|
|
type DriverConstructor func() driver.Driver
|
2022-06-07 10:13:55 +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 driverMap = map[string]DriverConstructor{}
|
2022-08-30 06:39:10 +00:00
|
|
|
var driverInfoMap = map[string]driver.Info{}
|
2022-06-07 10:13:55 +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
|
|
|
func RegisterDriver(driver DriverConstructor) {
|
2022-08-07 05:23:15 +00:00
|
|
|
// log.Infof("register driver: [%s]", config.Name)
|
2022-12-13 10:03:30 +00:00
|
|
|
tempDriver := driver()
|
|
|
|
tempConfig := tempDriver.Config()
|
|
|
|
registerDriverItems(tempConfig, tempDriver.GetAddition())
|
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
|
|
|
driverMap[tempConfig.Name] = driver
|
2022-06-07 10:13:55 +00:00
|
|
|
}
|
2022-06-08 08:20:58 +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
|
|
|
func GetDriver(name string) (DriverConstructor, error) {
|
|
|
|
n, ok := driverMap[name]
|
2022-06-09 09:11:46 +00:00
|
|
|
if !ok {
|
|
|
|
return nil, errors.Errorf("no driver named: %s", name)
|
|
|
|
}
|
|
|
|
return n, nil
|
|
|
|
}
|
|
|
|
|
2022-06-26 12:25:02 +00:00
|
|
|
func GetDriverNames() []string {
|
|
|
|
var driverNames []string
|
2022-08-30 06:39:10 +00:00
|
|
|
for k := range driverInfoMap {
|
2022-06-26 12:25:02 +00:00
|
|
|
driverNames = append(driverNames, k)
|
|
|
|
}
|
|
|
|
return driverNames
|
|
|
|
}
|
|
|
|
|
2022-08-30 06:39:10 +00:00
|
|
|
func GetDriverInfoMap() map[string]driver.Info {
|
|
|
|
return driverInfoMap
|
2022-06-14 11:44:25 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 09:11:46 +00:00
|
|
|
func registerDriverItems(config driver.Config, addition driver.Additional) {
|
2022-08-07 05:23:15 +00:00
|
|
|
// log.Debugf("addition of %s: %+v", config.Name, addition)
|
2022-06-08 08:20:58 +00:00
|
|
|
tAddition := reflect.TypeOf(addition)
|
2022-12-13 10:03:30 +00:00
|
|
|
for tAddition.Kind() == reflect.Pointer {
|
|
|
|
tAddition = tAddition.Elem()
|
|
|
|
}
|
2022-06-08 08:20:58 +00:00
|
|
|
mainItems := getMainItems(config)
|
2022-07-19 09:07:12 +00:00
|
|
|
additionalItems := getAdditionalItems(tAddition, config.DefaultRoot)
|
2022-08-30 06:39:10 +00:00
|
|
|
driverInfoMap[config.Name] = driver.Info{
|
2022-07-27 03:43:49 +00:00
|
|
|
Common: mainItems,
|
2022-06-11 11:01:20 +00:00
|
|
|
Additional: additionalItems,
|
2022-08-30 06:39:10 +00:00
|
|
|
Config: config,
|
2022-06-11 11:01:20 +00:00
|
|
|
}
|
2022-06-08 08:20:58 +00:00
|
|
|
}
|
|
|
|
|
2022-06-09 09:11:46 +00:00
|
|
|
func getMainItems(config driver.Config) []driver.Item {
|
|
|
|
items := []driver.Item{{
|
2022-07-12 10:41:16 +00:00
|
|
|
Name: "mount_path",
|
2022-06-27 06:32:21 +00:00
|
|
|
Type: conf.TypeString,
|
2022-06-08 08:20:58 +00:00
|
|
|
Required: true,
|
2023-05-11 10:40:56 +00:00
|
|
|
Help: "The path you want to mount to, it is unique and cannot be repeated",
|
2022-06-08 08:20:58 +00:00
|
|
|
}, {
|
2022-09-07 07:55:15 +00:00
|
|
|
Name: "order",
|
2022-06-27 06:32:21 +00:00
|
|
|
Type: conf.TypeNumber,
|
2022-06-08 08:20:58 +00:00
|
|
|
Help: "use to sort",
|
2022-07-12 10:41:16 +00:00
|
|
|
}, {
|
|
|
|
Name: "remark",
|
|
|
|
Type: conf.TypeText,
|
2022-06-08 08:20:58 +00:00
|
|
|
}}
|
2022-08-07 05:33:53 +00:00
|
|
|
if !config.NoCache {
|
|
|
|
items = append(items, driver.Item{
|
|
|
|
Name: "cache_expiration",
|
|
|
|
Type: conf.TypeNumber,
|
|
|
|
Default: "30",
|
|
|
|
Required: true,
|
|
|
|
Help: "The cache expiration time for this storage",
|
|
|
|
})
|
|
|
|
}
|
2022-06-08 08:20:58 +00:00
|
|
|
if !config.OnlyProxy && !config.OnlyLocal {
|
2022-06-09 09:11:46 +00:00
|
|
|
items = append(items, []driver.Item{{
|
2022-06-08 08:20:58 +00:00
|
|
|
Name: "web_proxy",
|
2022-06-27 06:32:21 +00:00
|
|
|
Type: conf.TypeBool,
|
2022-06-08 08:20:58 +00:00
|
|
|
}, {
|
2022-06-27 05:58:21 +00:00
|
|
|
Name: "webdav_policy",
|
2022-06-27 06:32:21 +00:00
|
|
|
Type: conf.TypeSelect,
|
2022-09-04 06:48:21 +00:00
|
|
|
Options: "302_redirect,use_proxy_url,native_proxy",
|
2022-07-23 13:19:27 +00:00
|
|
|
Default: "302_redirect",
|
2022-06-27 05:58:21 +00:00
|
|
|
Required: true,
|
2022-06-08 08:20:58 +00:00
|
|
|
},
|
|
|
|
}...)
|
2022-06-27 05:58:21 +00:00
|
|
|
} else {
|
|
|
|
items = append(items, driver.Item{
|
|
|
|
Name: "webdav_policy",
|
2022-06-27 06:32:21 +00:00
|
|
|
Type: conf.TypeSelect,
|
2022-07-23 13:19:27 +00:00
|
|
|
Default: "native_proxy",
|
2022-09-04 06:48:21 +00:00
|
|
|
Options: "use_proxy_url,native_proxy",
|
2022-06-27 05:58:21 +00:00
|
|
|
Required: true,
|
|
|
|
})
|
2022-06-08 08:20:58 +00:00
|
|
|
}
|
2022-09-07 07:55:15 +00:00
|
|
|
items = append(items, driver.Item{
|
|
|
|
Name: "down_proxy_url",
|
|
|
|
Type: conf.TypeText,
|
|
|
|
})
|
2022-06-08 08:20:58 +00:00
|
|
|
if config.LocalSort {
|
2022-06-09 09:11:46 +00:00
|
|
|
items = append(items, []driver.Item{{
|
2022-08-26 07:08:31 +00:00
|
|
|
Name: "order_by",
|
|
|
|
Type: conf.TypeSelect,
|
|
|
|
Options: "name,size,modified",
|
2022-06-08 08:20:58 +00:00
|
|
|
}, {
|
2022-08-26 07:08:31 +00:00
|
|
|
Name: "order_direction",
|
|
|
|
Type: conf.TypeSelect,
|
|
|
|
Options: "asc,desc",
|
2022-06-08 08:20:58 +00:00
|
|
|
}}...)
|
|
|
|
}
|
2022-06-09 09:11:46 +00:00
|
|
|
items = append(items, driver.Item{
|
2022-08-26 07:08:31 +00:00
|
|
|
Name: "extract_folder",
|
|
|
|
Type: conf.TypeSelect,
|
|
|
|
Options: "front,back",
|
2022-06-08 08:20:58 +00:00
|
|
|
})
|
2023-03-24 14:44:33 +00:00
|
|
|
items = append(items, driver.Item{
|
|
|
|
Name: "enable_sign",
|
|
|
|
Type: conf.TypeBool,
|
|
|
|
Default: "false",
|
|
|
|
Required: true,
|
|
|
|
})
|
2022-06-08 08:20:58 +00:00
|
|
|
return items
|
|
|
|
}
|
2022-07-19 09:07:12 +00:00
|
|
|
func getAdditionalItems(t reflect.Type, defaultRoot string) []driver.Item {
|
2022-06-09 09:11:46 +00:00
|
|
|
var items []driver.Item
|
2022-06-08 08:20:58 +00:00
|
|
|
for i := 0; i < t.NumField(); i++ {
|
2022-06-08 08:32:20 +00:00
|
|
|
field := t.Field(i)
|
2022-06-26 12:18:12 +00:00
|
|
|
if field.Type.Kind() == reflect.Struct {
|
2022-07-19 09:07:12 +00:00
|
|
|
items = append(items, getAdditionalItems(field.Type, defaultRoot)...)
|
2022-06-26 12:18:12 +00:00
|
|
|
continue
|
|
|
|
}
|
2022-06-08 08:32:20 +00:00
|
|
|
tag := field.Tag
|
2022-08-30 13:52:06 +00:00
|
|
|
ignore, ok1 := tag.Lookup("ignore")
|
|
|
|
name, ok2 := tag.Lookup("json")
|
|
|
|
if (ok1 && ignore == "true") || !ok2 {
|
2022-06-08 08:20:58 +00:00
|
|
|
continue
|
|
|
|
}
|
2022-06-09 09:11:46 +00:00
|
|
|
item := driver.Item{
|
2022-08-30 13:52:06 +00:00
|
|
|
Name: name,
|
2022-06-08 09:01:36 +00:00
|
|
|
Type: strings.ToLower(field.Type.Name()),
|
2022-06-08 08:20:58 +00:00
|
|
|
Default: tag.Get("default"),
|
2022-08-26 07:08:31 +00:00
|
|
|
Options: tag.Get("options"),
|
2022-06-08 08:20:58 +00:00
|
|
|
Required: tag.Get("required") == "true",
|
|
|
|
Help: tag.Get("help"),
|
|
|
|
}
|
2022-06-08 08:32:20 +00:00
|
|
|
if tag.Get("type") != "" {
|
|
|
|
item.Type = tag.Get("type")
|
|
|
|
}
|
2022-09-11 08:23:46 +00:00
|
|
|
if item.Name == "root_folder_id" || item.Name == "root_folder_path" {
|
|
|
|
if item.Default == "" {
|
|
|
|
item.Default = defaultRoot
|
|
|
|
}
|
|
|
|
item.Required = item.Default != ""
|
2022-07-19 09:07:12 +00:00
|
|
|
}
|
2022-06-08 08:20:58 +00:00
|
|
|
// set default type to string
|
|
|
|
if item.Type == "" {
|
|
|
|
item.Type = "string"
|
|
|
|
}
|
|
|
|
items = append(items, item)
|
|
|
|
}
|
|
|
|
return items
|
|
|
|
}
|