Repository: AlistGo/alist (language: go)

Issue:
lanzhou driver: not find file sgin failed get link
### Please make sure of the following things

- [X] I have read the [documentation](https://alist.nn.ci).
我已经阅读了[文档](https://alist.nn.ci)。

- [X] I'm sure there are no duplicate issues or discussions.
我确定没有重复的issue或讨论。

- [X] I'm sure it's due to `AList` and not something else(such as [Network](https://alist.nn.ci/faq/howto.html#tls-handshake-timeout-read-connection-reset-by-peer-dns-lookup-failed-connect-connection-refused-client-timeout-exceeded-while-awaiting-headers-no-such-host) ,`Dependencies` or `Operational`).
我确定是`AList`的问题，而不是其他原因（例如[网络](https://alist.nn.ci/zh/faq/howto.html#tls-handshake-timeout-read-connection-reset-by-peer-dns-lookup-failed-connect-connection-refused-client-timeout-exceeded-while-awaiting-headers-no-such-host)，`依赖`或`操作`）。

- [X] I'm sure this issue is not fixed in the latest version.
我确定这个问题在最新版本中没有被修复。


### AList Version / AList 版本

v3.25.1

### Driver used / 使用的存储驱动

lanzhou

### Describe the bug / 问题描述

```
[GIN] 2023/08/19 - 16:19:28 | 200 |       98.23µs | 120.204.169.240 | GET      "/@manage/storages"
[31mERRO[0m[2023-08-19 16:19:28] failed link /LanCloud/App/Ximalaya_7.3.3.3.apk: not find file sgin
failed get link
github.com/alist-org/alist/v3/internal/op.Link.func1
	/workspaces/alist-web/alist/internal/op/fs.go:253
github.com/alist-org/alist/v3/pkg/singleflight.(*Group[...]).doCall.func2
	/workspaces/alist-web/alist/pkg/singleflight/singleflight.go:193
github.com/alist-org/alist/v3/pkg/singleflight.(*Group[...]).doCall
	/workspaces/alist-web/alist/pkg/singleflight/singleflight.go:195
github.com/alist-org/alist/v3/pkg/singleflight.(*Group[...]).Do
	/workspaces/alist-web/alist/pkg/singleflight/singleflight.go:108
github.com/alist-org/alist/v3/internal/op.Link
	/workspaces/alist-web/alist/internal/op/fs.go:260
github.com/alist-org/alist/v3/internal/fs.link
	/workspaces/alist-web/alist/internal/fs/link.go:19
github.com/alist-org/alist/v3/internal/fs.Link
	/workspaces/alist-web/alist/internal/fs/fs.go:48
github.com/alist-org/alist/v3/server/handles.FsGet
	/workspaces/alist-web/alist/server/handles/fsread.go:289
github.com/gin-gonic/gin.(*Context).Next
	/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/alist-org/alist/v3/server/middlewares.Auth
	/workspaces/alist-web/alist/server/middlewares/auth.go:67
github.com/gin-gonic/gin.(*Context).Next
	/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/alist-org/alist/v3/server/middlewares.StoragesLoaded
	/workspaces/alist-web/alist/server/middlewares/check.go:14
github.com/gin-gonic/gin.(*Context).Next
	/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/gin-gonic/gin.CustomRecoveryWithWriter.func1
	/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/recovery.go:102
github.com/gin-gonic/gin.(*Context).Next
	/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/gin-gonic/gin.LoggerWithConfig.func1
	/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/logger.go:240
github.com/gin-gonic/gin.(*Context).Next
	/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/context.go:174
github.com/gin-gonic/gin.(*Engine).handleHTTPRequest
	/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/gin.go:620
github.com/gin-gonic/gin.(*Engine).ServeHTTP
	/go/pkg/mod/github.com/gin-gonic/gin@v1.9.1/gin.go:576
net/http.serverHandler.ServeHTTP
	/usr/local/go/src/net/http/server.go:2936
net/http.(*conn).serve
	/usr/local/go/src/net/http/server.go:1995
runtime.goexit
	/usr/local/go/src/runtime/asm_amd64.s:1598
failed link 
```

### Reproduction / 复现链接

http://xxx.com/lanzhou/aa

### Config / 配置

```

{
  "force": false,
  "address": "0.0.0.0",
  "port": 5244,
  "https_port": 5245,
  "site_url": "https://xxx",
  "cdn": "",
  "jwt_secret": "xx",
  "token_expires_in": 48,
  "database": {
    "type": "sqlite3",
    "host": "",
    "port": 0,
    "user": "",
    "password": "",
    "name": "",
    "db_file": "data/daxxta.db",
    "table_prefix": "x_",
    "ssl_mode": ""
  },
  "scheme": {
    "disable_http": false,
    "https": false,
    "force_https": false,
    "cert_file": "",
    "key_file": ""
  },
  "temp_dir": "data/temp",
  "bleve_dir": "data/bleve",
  "log": {
    "enable": true,
    "name": "data/log/log.log",
    "max_size": 10,
    "max_backups": 5,
    "max_age": 28,
    "compress": false
  },
  "delayed_start": 0,
  "max_connections": 0,
  "tls_insecure_skip_verify": false
}
```

### Logs / 日志

_No response_


Discussion / hints:
### See
1. 66% #1843
2. 59% #4419

<!-- Created by actions-cool/issues-similarity-analysis. Do not remove. -->
> 请提供您的AList应用的配置文件，并截图相关存储配置。(隐藏隐私字段)


@xhofe config 上面已经发了

![image](https://github.com/alist-org/alist/assets/11532015/94a58ed3-2181-4b20-9e13-85aadbec43fa)

老版本的也有问题了。通过账号，cookie都有问题。

**具体问题：**

可以列目录，查看到所有文件，但是不能下载。

![image](https://github.com/alist-org/alist/assets/11532015/1523b930-7b43-4aef-a074-ecbf92600a2a)

并截图**相关存储**配置
我这里也是。
v3.25.1
vps，docker部署，nginx反代，alist的config.json中仅修改/设置`site_url` 字段为反代的域名，其他保持默认。

添加`存储`时，类型选`账户`，并填入`账号` 和 `密码` ，其他均为默认。

添加后，目录及列表均显示正常，点击具体内容就会出现同样提示。
![lanz](https://i.imgur.com/NBW5zd3.png)


Fix patch:
diff --git a/drivers/lanzou/help.go b/drivers/lanzou/help.go
index 89f8e0711c3..f5b8ce42b9a 100644
--- a/drivers/lanzou/help.go
+++ b/drivers/lanzou/help.go
@@ -125,6 +125,83 @@ func findJSVarFunc(key, data string) string {
 	return values[1]
 }
 
+var findFunction = regexp.MustCompile(`(?ims)^function[^{]+`)
+var findFunctionAll = regexp.MustCompile(`(?is)function[^{]+`)
+
+// 查找所有方法位置
+func findJSFunctionIndex(data string, all bool) [][2]int {
+	findFunction := findFunction
+	if all {
+		findFunction = findFunctionAll
+	}
+
+	indexs := findFunction.FindAllStringIndex(data, -1)
+	fIndexs := make([][2]int, 0, len(indexs))
+
+	for _, index := range indexs {
+		if len(index) != 2 {
+			continue
+		}
+		count, data := 0, data[index[1]:]
+		for ii, v := range data {
+			if v == ' ' && count == 0 {
+				continue
+			}
+			if v == '{' {
+				count++
+			}
+
+			if v == '}' {
+				count--
+			}
+			if count == 0 {
+				fIndexs = append(fIndexs, [2]int{index[0], index[1] + ii + 1})
+				break
+			}
+		}
+	}
+	return fIndexs
+}
+
+// 删除JS全局方法
+func removeJSGlobalFunction(html string) string {
+	indexs := findJSFunctionIndex(html, false)
+	block := make([]string, len(indexs))
+	for i, next := len(indexs)-1, len(html); i >= 0; i-- {
+		index := indexs[i]
+		block[i] = html[index[1]:next]
+		next = index[0]
+	}
+	return strings.Join(block, "")
+}
+
+// 根据名称获取方法
+func getJSFunctionByName(html string, name string) (string, error) {
+	indexs := findJSFunctionIndex(html, true)
+	for _, index := range indexs {
+		data := html[index[0]:index[1]]
+		if regexp.MustCompile(`function\s+` + name + `[()\s]+{`).MatchString(data) {
+			return data, nil
+		}
+	}
+	return "", fmt.Errorf("not find %s function", name)
+}
+
+// 解析html中的JSON,选择最长的数据
+func htmlJsonToMap2(html string) (map[string]string, error) {
+	datas := findDataReg.FindAllStringSubmatch(html, -1)
+	var sData string
+	for _, data := range datas {
+		if len(datas) > 0 && len(data[1]) > len(sData) {
+			sData = data[1]
+		}
+	}
+	if sData == "" {
+		return nil, fmt.Errorf("not find data")
+	}
+	return jsonToMap(sData, html), nil
+}
+
 // 解析html中的JSON
 func htmlJsonToMap(html string) (map[string]string, error) {
 	datas := findDataReg.FindStringSubmatch(html)
diff --git a/drivers/lanzou/util.go b/drivers/lanzou/util.go
index 6e2f05cc56f..272cbbfe2bd 100644
--- a/drivers/lanzou/util.go
+++ b/drivers/lanzou/util.go
@@ -346,7 +346,11 @@ func (d *LanZou) getFilesByShareUrl(shareID, pwd string, sharePageData string) (
 
 	// 需要密码
 	if strings.Contains(sharePageData, "pwdload") || strings.Contains(sharePageData, "passwddiv") {
-		param, err := htmlFormToMap(sharePageData)
+		sharePageData, err := getJSFunctionByName(sharePageData, "down_p")
+		if err != nil {
+			return nil, err
+		}
+		param, err := htmlJsonToMap(sharePageData)
 		if err != nil {
 			return nil, err
 		}
@@ -370,8 +374,7 @@ func (d *LanZou) getFilesByShareUrl(shareID, pwd string, sharePageData string) (
 		if err != nil {
 			return nil, err
 		}
-		nextPageData := RemoveNotes(string(data))
-
+		nextPageData := removeJSGlobalFunction(RemoveNotes(string(data)))
 		param, err = htmlJsonToMap(nextPageData)
 		if err != nil {
 			return nil, err


Test patch: