mirror of
https://github.com/ctwj/urldb.git
synced 2025-11-25 03:15:04 +08:00
update: 优化网盘操作,移除特殊操作
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ctwj/urldb/db/entity"
|
||||
"github.com/ctwj/urldb/db/repo"
|
||||
"github.com/ctwj/urldb/utils"
|
||||
)
|
||||
|
||||
@@ -405,6 +406,9 @@ func (a *AlipanService) getAlipan4(shareData map[string]interface{}) (*AlipanSha
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (u *AlipanService) SetCKSRepository(cksRepo repo.CksRepository, entity entity.Cks) {
|
||||
}
|
||||
|
||||
// manageAccessToken 管理access token
|
||||
func (a *AlipanService) manageAccessToken() (string, error) {
|
||||
if a.accessToken != "" {
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ctwj/urldb/db/entity"
|
||||
"github.com/ctwj/urldb/db/repo"
|
||||
)
|
||||
|
||||
// BaiduPanService 百度网盘服务
|
||||
@@ -108,3 +109,6 @@ func (b *BaiduPanService) GetUserInfo(cookie *string) (*UserInfo, error) {
|
||||
func (b *BaiduPanService) GetUserInfoByEntity(cks entity.Cks) (*UserInfo, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (u *BaiduPanService) SetCKSRepository(cksRepo repo.CksRepository, entity entity.Cks) {
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/ctwj/urldb/db/entity"
|
||||
"github.com/ctwj/urldb/db/repo"
|
||||
)
|
||||
|
||||
// ServiceType 定义网盘服务类型
|
||||
@@ -93,10 +94,10 @@ type PanService interface {
|
||||
// GetUserInfo 获取用户信息
|
||||
GetUserInfo(ck *string) (*UserInfo, error)
|
||||
|
||||
GetUserInfoByEntity(entity entity.Cks) (*UserInfo, error)
|
||||
|
||||
// GetServiceType 获取服务类型
|
||||
GetServiceType() ServiceType
|
||||
|
||||
SetCKSRepository(cksRepo repo.CksRepository, entity entity.Cks)
|
||||
}
|
||||
|
||||
// PanFactory 网盘工厂
|
||||
|
||||
@@ -1024,9 +1024,7 @@ func (q *QuarkPanService) GetUserInfo(cookie *string) (*UserInfo, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetUserInfoByEntity 根据 entity.Cks 获取用户信息(待实现)
|
||||
func (q *QuarkPanService) GetUserInfoByEntity(cks entity.Cks) (*UserInfo, error) {
|
||||
return nil, nil
|
||||
func (xq *QuarkPanService) SetCKSRepository(cksRepo repo.CksRepository, entity entity.Cks) {
|
||||
}
|
||||
|
||||
// formatBytes 格式化字节数为可读格式
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ctwj/urldb/db/entity"
|
||||
"github.com/ctwj/urldb/db/repo"
|
||||
)
|
||||
|
||||
// UCService UC网盘服务
|
||||
@@ -106,3 +107,6 @@ func (u *UCService) GetUserInfo(cookie *string) (*UserInfo, error) {
|
||||
func (u *UCService) GetUserInfoByEntity(cks entity.Cks) (*UserInfo, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (u *UCService) SetCKSRepository(cksRepo repo.CksRepository, entity entity.Cks) {
|
||||
}
|
||||
|
||||
@@ -323,20 +323,8 @@ func (x *XunleiPanService) Transfer(shareID string) (*TransferResult, error) {
|
||||
return ErrorResult(fmt.Sprintf("获取captchaToken失败: %v", err)), nil
|
||||
}
|
||||
|
||||
// 检查是否为检验模式
|
||||
if config.IsType == 1 {
|
||||
// 检验模式:直接获取分享信息
|
||||
urls := map[string]interface{}{
|
||||
"title": "",
|
||||
"share_url": config.URL,
|
||||
"stoken": "",
|
||||
}
|
||||
return SuccessResult("检验成功", urls), nil
|
||||
}
|
||||
|
||||
// 转存模式:实现完整的转存流程
|
||||
shareID = strings.TrimRight(shareID, "#/")
|
||||
thisCode := strings.TrimLeft(x.config.Code, "#")
|
||||
thisCode := strings.TrimLeft(config.URL, "#")
|
||||
|
||||
// 获取分享详情
|
||||
shareDetail, err := x.getShare(shareID, thisCode, accessToken, captchaToken)
|
||||
@@ -352,6 +340,17 @@ func (x *XunleiPanService) Transfer(shareID string) (*TransferResult, error) {
|
||||
return ErrorResult(message), nil
|
||||
}
|
||||
|
||||
// 检查是否为检验模式
|
||||
if config.IsType == 1 {
|
||||
// 检验模式:直接获取分享信息
|
||||
urls := map[string]interface{}{
|
||||
"title": "",
|
||||
"share_url": config.URL,
|
||||
"stoken": "",
|
||||
}
|
||||
return SuccessResult("检验成功", urls), nil
|
||||
}
|
||||
|
||||
shareData := shareDetail["data"].(map[string]interface{})
|
||||
files := shareData["files"].([]interface{})
|
||||
|
||||
|
||||
@@ -345,13 +345,15 @@ func RefreshCapacity(c *gin.Context) {
|
||||
}
|
||||
|
||||
var userInfo *panutils.UserInfo
|
||||
switch s := service.(type) {
|
||||
case *panutils.XunleiPanService:
|
||||
s.SetCKSRepository(repoManager.CksRepository, *cks) // 迅雷需要初始化 token 后才能获取,
|
||||
userInfo, err = s.GetUserInfo(nil)
|
||||
default:
|
||||
userInfo, err = service.GetUserInfo(&cks.Ck)
|
||||
}
|
||||
service.SetCKSRepository(repoManager.CksRepository, *cks) // 迅雷需要初始化 token 后才能获取,
|
||||
userInfo, err = service.GetUserInfo(&cks.Ck)
|
||||
// switch s := service.(type) {
|
||||
// case *panutils.XunleiPanService:
|
||||
|
||||
// userInfo, err = s.GetUserInfo(nil)
|
||||
// default:
|
||||
// userInfo, err = service.GetUserInfo(&cks.Ck)
|
||||
// }
|
||||
if err != nil {
|
||||
ErrorResponse(c, "无法获取用户信息,刷新失败: "+err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
|
||||
@@ -386,8 +386,8 @@ func GetResourceLink(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 如果不是夸克网盘,直接返回原链接
|
||||
if panInfo.Name != "quark" {
|
||||
utils.Info("非夸克资源,直接返回原链接")
|
||||
if panInfo.Name != "quark" && panInfo.Name != "xunlei" {
|
||||
utils.Info("非夸克和迅雷资源,直接返回原链接")
|
||||
SuccessResponse(c, gin.H{
|
||||
"url": resource.URL,
|
||||
"type": "original",
|
||||
@@ -397,9 +397,6 @@ func GetResourceLink(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
// 夸克资源处理逻辑
|
||||
utils.Info("夸克资源处理开始")
|
||||
|
||||
// 如果已存在转存链接,直接返回
|
||||
if resource.SaveURL != "" {
|
||||
utils.Info("已存在转存链接,直接返回: %s", resource.SaveURL)
|
||||
@@ -475,18 +472,11 @@ type TransferResult struct {
|
||||
func performAutoTransfer(resource *entity.Resource) TransferResult {
|
||||
utils.Info("开始执行资源转存 - ID: %d, URL: %s", resource.ID, resource.URL)
|
||||
|
||||
// 获取夸克平台ID
|
||||
quarkPanID, err := getQuarkPanID()
|
||||
if err != nil {
|
||||
utils.Error("获取夸克平台ID失败: %v", err)
|
||||
return TransferResult{
|
||||
Success: false,
|
||||
ErrorMsg: fmt.Sprintf("获取夸克平台ID失败: %v", err),
|
||||
}
|
||||
}
|
||||
// 平台ID
|
||||
panID := resource.PanID
|
||||
|
||||
// 获取可用的夸克账号
|
||||
accounts, err := repoManager.CksRepository.FindAll()
|
||||
accounts, err := repoManager.CksRepository.FindByPanID(*panID)
|
||||
if err != nil {
|
||||
utils.Error("获取网盘账号失败: %v", err)
|
||||
return TransferResult{
|
||||
@@ -495,34 +485,36 @@ func performAutoTransfer(resource *entity.Resource) TransferResult {
|
||||
}
|
||||
}
|
||||
|
||||
// 测试阶段,移除最小限制
|
||||
// 获取最小存储空间配置
|
||||
autoTransferMinSpace, err := repoManager.SystemConfigRepository.GetConfigInt(entity.ConfigKeyAutoTransferMinSpace)
|
||||
if err != nil {
|
||||
utils.Error("获取最小存储空间配置失败: %v", err)
|
||||
autoTransferMinSpace = 5 // 默认5GB
|
||||
}
|
||||
// autoTransferMinSpace, err := repoManager.SystemConfigRepository.GetConfigInt(entity.ConfigKeyAutoTransferMinSpace)
|
||||
// if err != nil {
|
||||
// utils.Error("获取最小存储空间配置失败: %v", err)
|
||||
// autoTransferMinSpace = 5 // 默认5GB
|
||||
// }
|
||||
|
||||
// 过滤:只保留已激活、夸克平台、剩余空间足够的账号
|
||||
minSpaceBytes := int64(autoTransferMinSpace) * 1024 * 1024 * 1024
|
||||
var validAccounts []entity.Cks
|
||||
for _, acc := range accounts {
|
||||
if acc.IsValid && acc.PanID == quarkPanID && acc.LeftSpace >= minSpaceBytes {
|
||||
validAccounts = append(validAccounts, acc)
|
||||
}
|
||||
}
|
||||
// // 过滤:只保留已激活、夸克平台、剩余空间足够的账号
|
||||
// minSpaceBytes := int64(autoTransferMinSpace) * 1024 * 1024 * 1024
|
||||
// var validAccounts []entity.Cks
|
||||
// for _, acc := range accounts {
|
||||
// if acc.IsValid && acc.PanID == *panID && acc.LeftSpace >= minSpaceBytes {
|
||||
// validAccounts = append(validAccounts, acc)
|
||||
// }
|
||||
// }
|
||||
|
||||
if len(validAccounts) == 0 {
|
||||
utils.Info("没有可用的夸克网盘账号")
|
||||
return TransferResult{
|
||||
Success: false,
|
||||
ErrorMsg: "没有可用的夸克网盘账号",
|
||||
}
|
||||
}
|
||||
// if len(validAccounts) == 0 {
|
||||
// utils.Info("没有可用的网盘账号")
|
||||
// return TransferResult{
|
||||
// Success: false,
|
||||
// ErrorMsg: "没有可用的网盘账号",
|
||||
// }
|
||||
// }
|
||||
|
||||
utils.Info("找到 %d 个可用夸克网盘账号,开始转存处理...", len(validAccounts))
|
||||
// utils.Info("找到 %d 个可用网盘账号,开始转存处理...", len(validAccounts))
|
||||
|
||||
// 使用第一个可用账号进行转存
|
||||
account := validAccounts[0]
|
||||
// account := validAccounts[0]
|
||||
account := accounts[0]
|
||||
|
||||
// 创建网盘服务工厂
|
||||
factory := pan.NewPanFactory()
|
||||
@@ -566,6 +558,9 @@ func transferSingleResource(resource *entity.Resource, account entity.Cks, facto
|
||||
}
|
||||
}
|
||||
|
||||
// 设置账号信息
|
||||
service.SetCKSRepository(repoManager.CksRepository, account)
|
||||
|
||||
// 提取分享ID
|
||||
shareID, _ := commonutils.ExtractShareIdString(resource.URL)
|
||||
if shareID == "" {
|
||||
@@ -576,7 +571,7 @@ func transferSingleResource(resource *entity.Resource, account entity.Cks, facto
|
||||
}
|
||||
|
||||
// 执行转存
|
||||
transferResult, err := service.Transfer(shareID)
|
||||
transferResult, err := service.Transfer(shareID) // 有些链接还需要其他信息从 url 中自行解析
|
||||
if err != nil {
|
||||
utils.Error("转存失败: %v", err)
|
||||
return TransferResult{
|
||||
|
||||
Reference in New Issue
Block a user