diff --git a/common/utils/url_checker.go b/common/utils/url_checker.go index acd5a2b..9ec38f0 100644 --- a/common/utils/url_checker.go +++ b/common/utils/url_checker.go @@ -68,7 +68,7 @@ func extractShareID(urlStr string) (string, string) { }, XunleiStr: { Domains: []string{"pan.xunlei.com"}, - Pattern: regexp.MustCompile(`https?://(?:www\.)?pan\.xunlei\.com/s/([a-zA-Z0-9-]+)`), + Pattern: regexp.MustCompile(`https?://(?:www\.)?pan\.xunlei\.com/s/([a-zA-Z0-9-_]+)`), }, BaiduStr: { Domains: []string{"pan.baidu.com", "yun.baidu.com"}, diff --git a/common/xunlei_pan.go b/common/xunlei_pan.go index f37d247..4a9ea60 100644 --- a/common/xunlei_pan.go +++ b/common/xunlei_pan.go @@ -303,6 +303,19 @@ func (x *XunleiPanService) GetServiceType() ServiceType { return Xunlei } +func extractCode(url string) string { + // 查找 pwd= 的位置 + if pwdIndex := strings.Index(url, "pwd="); pwdIndex != -1 { + code := url[pwdIndex+4:] + // 移除 # 及后面的内容(如果存在) + if hashIndex := strings.Index(code, "#"); hashIndex != -1 { + code = code[:hashIndex] + } + return code + } + return "" +} + // Transfer 转存分享链接 - 实现 PanService 接口,匹配 XunleiPan.php 的逻辑 func (x *XunleiPanService) Transfer(shareID string) (*TransferResult, error) { // 读取配置(线程安全) @@ -324,7 +337,7 @@ func (x *XunleiPanService) Transfer(shareID string) (*TransferResult, error) { } // 转存模式:实现完整的转存流程 - thisCode := strings.TrimLeft(config.URL, "#") + thisCode := extractCode(config.URL) // 获取分享详情 shareDetail, err := x.getShare(shareID, thisCode, accessToken, captchaToken) @@ -332,14 +345,6 @@ func (x *XunleiPanService) Transfer(shareID string) (*TransferResult, error) { return ErrorResult(fmt.Sprintf("获取分享详情失败: %v", err)), nil } - if shareDetail["code"].(int) != 200 { - message := "获取分享详情失败" - if shareDetail["message"] != nil { - message = shareDetail["message"].(string) - } - return ErrorResult(message), nil - } - // 检查是否为检验模式 if config.IsType == 1 { // 检验模式:直接获取分享信息 @@ -350,9 +355,7 @@ func (x *XunleiPanService) Transfer(shareID string) (*TransferResult, error) { } return SuccessResult("检验成功", urls), nil } - - shareData := shareDetail["data"].(map[string]interface{}) - files := shareData["files"].([]interface{}) + files := shareDetail["files"].([]interface{}) // 转存到网盘 parent_id := "0" // 默认存储路径 @@ -373,7 +376,7 @@ func (x *XunleiPanService) Transfer(shareID string) (*TransferResult, error) { } // 转存资源 - restoreResult, err := x.getRestore(shareID, shareData, accessToken, captchaToken, parent_id) + restoreResult, err := x.getRestore(shareID, shareDetail, accessToken, captchaToken, parent_id) if err != nil { return ErrorResult(fmt.Sprintf("转存失败: %v", err)), nil } diff --git a/web/composables/useCookie.ts b/web/composables/useCookie.ts deleted file mode 100644 index 217c5f7..0000000 --- a/web/composables/useCookie.ts +++ /dev/null @@ -1,79 +0,0 @@ -export const useCookie = () => { - const get = (name: string): string | null => { - if (process.server) { - // 服务端处理 - const { req } = useRequestEvent() - const cookies = parse(req.headers.cookie || '') - return cookies[name] || null - } else { - // 客户端处理 - const cookieString = document.cookie - const cookies = cookieString.split('; ') - for (const cookie of cookies) { - const [cookieName, cookieValue] = cookie.split('=') - if (cookieName === name) { - return decodeURIComponent(cookieValue) - } - } - return null - } - } - - const set = (name: string, value: string, options?: any) => { - if (process.server) { - // 服务端设置 cookie - const { res } = useRequestEvent() - res.setHeader('Set-Cookie', `${name}=${encodeURIComponent(value)}; ${serializeOptions(options)}`) - } else { - // 客户端设置 cookie - document.cookie = `${name}=${encodeURIComponent(value)}; ${serializeOptions(options)}` - } - } - - const remove = (name: string) => { - set(name, '', { maxAge: -1 }) - } - - // 序列化 cookie 选项 - const serializeOptions = (options: any = {}): string => { - const { - maxAge, - expires, - path = '/', - domain, - secure, - httpOnly, - sameSite - } = options - - let result = '' - - if (maxAge !== undefined) result += `Max-Age=${maxAge}; ` - if (expires instanceof Date) result += `Expires=${expires.toUTCString()}; ` - if (path) result += `Path=${path}; ` - if (domain) result += `Domain=${domain}; ` - if (secure) result += 'Secure; ' - if (httpOnly) result += 'HttpOnly; ' - if (sameSite) result += `SameSite=${sameSite}; ` - - return result - } - - // 解析 cookie 字符串 - const parse = (cookieString: string): Record => { - const cookies: Record = {} - cookieString.split(';').forEach(cookie => { - const [name, value] = cookie.split('=') - if (name && value) { - cookies[name.trim()] = decodeURIComponent(value.trim()) - } - }) - return cookies - } - - return { - get, - set, - remove - } - } \ No newline at end of file diff --git a/web/pages/admin/accounts.vue b/web/pages/admin/accounts.vue index 496d743..b25e19b 100644 --- a/web/pages/admin/accounts.vue +++ b/web/pages/admin/accounts.vue @@ -265,11 +265,9 @@ const form = ref({ remark: '' }) -const cookie = useCookie() const panEnables = ref(['quark']) -const xunleiEnable = cookie.get('xunleiEnable') -console.log(xunleiEnable) -if (xunleiEnable && xunleiEnable === 'true') { +const xunleiEnable = useCookie('xunleiEnable', { default: () => false }) +if (xunleiEnable.value && xunleiEnable.value === 'true') { panEnables.value.push('xunlei') }