Repository: AlistGo/alist (language: go)

Issue:
添加针对Mega网盘的2FA的支持
### Please make sure of the following things

- [X] I have read the [documentation](https://alist.nn.ci).
- [X] I'm sure there are no duplicate issues or discussions.
- [X] I'm sure this feature is not implemented.
- [ ] I'm sure it's a reasonable and popular requirement.

### Description of the feature / 需求描述

现在的Mega驱动不支持Mega网盘的2FA功能，导致如果要正常使用就必须降低账号安全性。希望能够添加针对Mega的2FA功能的支持

### Suggested solution / 实现思路

[这个issue的讨论](https://github.com/t3rm1n4l/go-mega/issues/25)可能有帮助，由于我没有研究过go语言，所以只能贴出此issue的讨论供参考

### Additional context / 附件

_No response_


Discussion / hints:
Thanks for opening your first issue here! Be sure to follow the issue template!


Fix patch:
diff --git a/drivers/mega/driver.go b/drivers/mega/driver.go
index 9fa1d0eeafa..162aeef37e0 100644
--- a/drivers/mega/driver.go
+++ b/drivers/mega/driver.go
@@ -8,6 +8,7 @@ import (
 	"time"
 
 	"github.com/alist-org/alist/v3/pkg/http_range"
+	"github.com/pquerna/otp/totp"
 	"github.com/rclone/rclone/lib/readers"
 
 	"github.com/alist-org/alist/v3/internal/driver"
@@ -33,8 +34,16 @@ func (d *Mega) GetAddition() driver.Additional {
 }
 
 func (d *Mega) Init(ctx context.Context) error {
+	var twoFACode = d.TwoFACode
 	d.c = mega.New()
-	return d.c.Login(d.Email, d.Password)
+	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)
 }
 
 func (d *Mega) Drop(ctx context.Context) error {
diff --git a/drivers/mega/meta.go b/drivers/mega/meta.go
index 77e768f0542..d0758637bb3 100644
--- a/drivers/mega/meta.go
+++ b/drivers/mega/meta.go
@@ -9,8 +9,10 @@ type Addition struct {
 	// Usually one of two
 	//driver.RootPath
 	//driver.RootID
-	Email    string `json:"email" required:"true"`
-	Password string `json:"password" required:"true"`
+	Email       string `json:"email" required:"true"`
+	Password    string `json:"password" required:"true"`
+	TwoFACode   string `json:"two_fa_code" required:"false" help:"2FA 6-digit code, filling in the 2FA code alone will not support reloading driver"`
+	TwoFASecret string `json:"two_fa_secret" required:"false" help:"2FA secret"`
 }
 
 var config = driver.Config{


Test patch: