mirror of
https://github.com/fish2018/pansou.git
synced 2025-11-25 03:14:59 +08:00
返回参数指定网盘类型
This commit is contained in:
30
README.md
30
README.md
@@ -26,18 +26,19 @@ PanSou是一个高性能的网盘资源搜索API服务,支持TG搜索和自定
|
||||
|
||||
## 支持的网盘类型
|
||||
|
||||
- 百度网盘 (`pan.baidu.com`)
|
||||
- 阿里云盘 (`aliyundrive.com`, `alipan.com`)
|
||||
- 夸克网盘 (`pan.quark.cn`)
|
||||
- 天翼云盘 (`cloud.189.cn`)
|
||||
- UC网盘 (`drive.uc.cn`)
|
||||
- 移动云盘 (`caiyun.139.com`)
|
||||
- 115网盘 (`115.com`, `115cdn.com`, `anxia.com`)
|
||||
- PikPak (`mypikpak.com`)
|
||||
- 迅雷网盘 (`pan.xunlei.com`)
|
||||
- 123网盘 (`123684.com`, `123685.com`, `123912.com`, `123pan.com`, `123pan.cn`, `123592.com`)
|
||||
- 磁力链接 (`magnet:?xt=urn:btih:`)
|
||||
- 电驴链接 (`ed2k://`)
|
||||
- 百度网盘 (`baidu`)
|
||||
- 阿里云盘 (`aliyun`)
|
||||
- 夸克网盘 (`quark`)
|
||||
- 天翼云盘 (`tianyi`)
|
||||
- UC网盘 (`uc`)
|
||||
- 移动云盘 (`mobile`)
|
||||
- 115网盘 (`115`)
|
||||
- PikPak (`pikpak`)
|
||||
- 迅雷网盘 (`xunlei`)
|
||||
- 123网盘 (`123`)
|
||||
- 磁力链接 (`magnet`)
|
||||
- 电驴链接 (`ed2k`)
|
||||
- 其他 (`others`)
|
||||
|
||||
## API文档
|
||||
|
||||
@@ -60,6 +61,7 @@ PanSou是一个高性能的网盘资源搜索API服务,支持TG搜索和自定
|
||||
| res | string | 否 | 结果类型:all(返回所有结果)、results(仅返回results)、merge(仅返回merged_by_type),默认为merge |
|
||||
| src | string | 否 | 数据来源类型:all(默认,全部来源)、tg(仅Telegram)、plugin(仅插件) |
|
||||
| plugins | string[] | 否 | 指定搜索的插件列表,不指定则搜索全部插件 |
|
||||
| cloud_types | string[] | 否 | 指定返回的网盘类型列表,支持:baidu、aliyun、quark、tianyi、uc、mobile、115、pikpak、xunlei、123、magnet、ed2k,不指定则返回所有类型 |
|
||||
| ext | object | 否 | 扩展参数,用于传递给插件的自定义参数,如{"title_en":"English Title", "is_all":true} |
|
||||
|
||||
**GET请求参数**:
|
||||
@@ -73,6 +75,7 @@ PanSou是一个高性能的网盘资源搜索API服务,支持TG搜索和自定
|
||||
| res | string | 否 | 结果类型:all(返回所有结果)、results(仅返回results)、merge(仅返回merged_by_type),默认为merge |
|
||||
| src | string | 否 | 数据来源类型:all(默认,全部来源)、tg(仅Telegram)、plugin(仅插件) |
|
||||
| plugins | string | 否 | 指定搜索的插件列表,使用英文逗号分隔多个插件名,不指定则搜索全部插件 |
|
||||
| cloud_types | string | 否 | 指定返回的网盘类型列表,使用英文逗号分隔多个类型,支持:baidu、aliyun、quark、tianyi、uc、mobile、115、pikpak、xunlei、123、magnet、ed2k,不指定则返回所有类型 |
|
||||
| ext | string | 否 | JSON格式的扩展参数,用于传递给插件的自定义参数,如{"title_en":"English Title", "is_all":true} |
|
||||
|
||||
**POST请求示例**:
|
||||
@@ -86,6 +89,7 @@ PanSou是一个高性能的网盘资源搜索API服务,支持TG搜索和自定
|
||||
"res": "merge",
|
||||
"src": "all",
|
||||
"plugins": ["jikepan"],
|
||||
"cloud_types": ["baidu", "quark"],
|
||||
"ext": {
|
||||
"title_en": "Fast and Furious",
|
||||
"is_all": true
|
||||
@@ -96,7 +100,7 @@ PanSou是一个高性能的网盘资源搜索API服务,支持TG搜索和自定
|
||||
**GET请求示例**:
|
||||
|
||||
```
|
||||
GET /api/search?kw=速度与激情&channels=tgsearchers2,xxx&conc=2&refresh=true&res=merge&src=tg&ext={"title_en":"Fast and Furious","is_all":true}
|
||||
GET /api/search?kw=速度与激情&channels=tgsearchers2,xxx&conc=2&refresh=true&res=merge&src=tg&cloud_types=baidu,quark&ext={"title_en":"Fast and Furious","is_all":true}
|
||||
```
|
||||
|
||||
**成功响应**:
|
||||
|
||||
@@ -90,6 +90,26 @@ func SearchHandler(c *gin.Context) {
|
||||
plugins = nil
|
||||
}
|
||||
|
||||
// 处理cloud_types参数,支持逗号分隔
|
||||
var cloudTypes []string
|
||||
// 检查请求中是否存在cloud_types参数
|
||||
if c.Request.URL.Query().Has("cloud_types") {
|
||||
cloudTypesStr := c.Query("cloud_types")
|
||||
// 判断参数是否非空
|
||||
if cloudTypesStr != "" && cloudTypesStr != " " {
|
||||
parts := strings.Split(cloudTypesStr, ",")
|
||||
for _, part := range parts {
|
||||
trimmed := strings.TrimSpace(part)
|
||||
if trimmed != "" {
|
||||
cloudTypes = append(cloudTypes, trimmed)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 如果请求中不存在cloud_types参数,设置为nil
|
||||
cloudTypes = nil
|
||||
}
|
||||
|
||||
// 处理ext参数,JSON格式
|
||||
var ext map[string]interface{}
|
||||
extStr := c.Query("ext")
|
||||
@@ -117,6 +137,7 @@ func SearchHandler(c *gin.Context) {
|
||||
ResultType: resultType,
|
||||
SourceType: sourceType,
|
||||
Plugins: plugins,
|
||||
CloudTypes: cloudTypes, // 添加cloud_types到请求中
|
||||
Ext: ext,
|
||||
}
|
||||
} else {
|
||||
@@ -164,7 +185,7 @@ func SearchHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
// 执行搜索
|
||||
result, err := searchService.Search(req.Keyword, req.Channels, req.Concurrency, req.ForceRefresh, req.ResultType, req.SourceType, req.Plugins, req.Ext)
|
||||
result, err := searchService.Search(req.Keyword, req.Channels, req.Concurrency, req.ForceRefresh, req.ResultType, req.SourceType, req.Plugins, req.CloudTypes, req.Ext)
|
||||
|
||||
if err != nil {
|
||||
response := model.NewErrorResponse(500, "搜索失败: "+err.Error())
|
||||
|
||||
@@ -10,4 +10,5 @@ type SearchRequest struct {
|
||||
SourceType string `json:"src"` // 数据来源类型:all(默认,全部来源)、tg(仅Telegram)、plugin(仅插件)
|
||||
Plugins []string `json:"plugins"` // 指定搜索的插件列表,不指定则搜索全部插件
|
||||
Ext map[string]interface{} `json:"ext"` // 扩展参数,用于传递给插件的自定义参数
|
||||
CloudTypes []string `json:"cloud_types"` // 指定返回的网盘类型列表,不指定则返回所有类型
|
||||
}
|
||||
@@ -90,7 +90,7 @@ func injectMainCacheToAsyncPlugins(pluginManager *plugin.PluginManager, mainCach
|
||||
}
|
||||
|
||||
// Search 执行搜索
|
||||
func (s *SearchService) Search(keyword string, channels []string, concurrency int, forceRefresh bool, resultType string, sourceType string, plugins []string, ext map[string]interface{}) (model.SearchResponse, error) {
|
||||
func (s *SearchService) Search(keyword string, channels []string, concurrency int, forceRefresh bool, resultType string, sourceType string, plugins []string, cloudTypes []string, ext map[string]interface{}) (model.SearchResponse, error) {
|
||||
// 确保ext不为nil
|
||||
if ext == nil {
|
||||
ext = make(map[string]interface{})
|
||||
@@ -223,7 +223,7 @@ func (s *SearchService) Search(keyword string, channels []string, concurrency in
|
||||
}
|
||||
|
||||
// 合并链接按网盘类型分组(使用所有过滤后的结果)
|
||||
mergedLinks := mergeResultsByType(allResults, keyword)
|
||||
mergedLinks := mergeResultsByType(allResults, keyword, cloudTypes)
|
||||
|
||||
// 构建响应
|
||||
var total int
|
||||
@@ -656,7 +656,7 @@ func isEmpty(line string) bool {
|
||||
}
|
||||
|
||||
// 将搜索结果按网盘类型分组
|
||||
func mergeResultsByType(results []model.SearchResult, keyword string) model.MergedLinks {
|
||||
func mergeResultsByType(results []model.SearchResult, keyword string, cloudTypes []string) model.MergedLinks {
|
||||
// 创建合并结果的映射
|
||||
mergedLinks := make(model.MergedLinks, 10) // 预分配容量,假设有10种不同的网盘类型
|
||||
|
||||
@@ -787,6 +787,27 @@ func mergeResultsByType(results []model.SearchResult, keyword string) model.Merg
|
||||
mergedLinks[linkType] = links
|
||||
}
|
||||
|
||||
// 如果指定了cloudTypes,则过滤结果
|
||||
if len(cloudTypes) > 0 {
|
||||
// 创建过滤后的结果映射
|
||||
filteredLinks := make(model.MergedLinks)
|
||||
|
||||
// 将cloudTypes转换为map以提高查找性能
|
||||
allowedTypes := make(map[string]bool)
|
||||
for _, cloudType := range cloudTypes {
|
||||
allowedTypes[strings.ToLower(strings.TrimSpace(cloudType))] = true
|
||||
}
|
||||
|
||||
// 只保留指定类型的链接
|
||||
for linkType, links := range mergedLinks {
|
||||
if allowedTypes[strings.ToLower(linkType)] {
|
||||
filteredLinks[linkType] = links
|
||||
}
|
||||
}
|
||||
|
||||
return filteredLinks
|
||||
}
|
||||
|
||||
return mergedLinks
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user