|
|
|
@ -24,20 +24,28 @@ func (service *ItemSearchService) Search(c *gin.Context) serializer.Response {
|
|
|
|
|
|
|
|
|
|
switch service.Type {
|
|
|
|
|
case "keywords":
|
|
|
|
|
return service.SearchKeywords(c, "%"+service.Keywords+"%", fs)
|
|
|
|
|
return service.SearchKeywords(c, fs, "%"+service.Keywords+"%")
|
|
|
|
|
case "image":
|
|
|
|
|
return service.SearchKeywords(c, fs, "%.bmp", "%.flac", "%.iff", "%.png", "%.gif", "%.jpg", "%.jpge", "%.psd", "%.svg", "%.webp")
|
|
|
|
|
case "video":
|
|
|
|
|
return service.SearchKeywords(c, fs, "%.mp4", "%.flv", "%.avi", "%.wmv", "%.mkv", "%.rm", "%.rmvb", "%.mov", "%.ogv")
|
|
|
|
|
case "audio":
|
|
|
|
|
return service.SearchKeywords(c, fs, "%.mp3", "%.flac", "%.ape", "%.wav", "%.acc", "%.ogg", "%.midi", "%.mid")
|
|
|
|
|
case "doc":
|
|
|
|
|
return service.SearchKeywords(c, fs, "%.txt", "%.md", "%.pdf", "%.doc", "%.docx", "%.ppt", "%.pptx", "%.xls", "%.xlsx", "%.pub")
|
|
|
|
|
default:
|
|
|
|
|
return serializer.ParamErr("未知搜索类型", nil)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SearchKeywords 根据关键字搜索文件
|
|
|
|
|
func (service *ItemSearchService) SearchKeywords(c *gin.Context, keywords string, fs *filesystem.FileSystem) serializer.Response {
|
|
|
|
|
func (service *ItemSearchService) SearchKeywords(c *gin.Context, fs *filesystem.FileSystem, keywords ...interface{}) serializer.Response {
|
|
|
|
|
// 上下文
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
|
|
// 获取子项目
|
|
|
|
|
objects, err := fs.Search(ctx, keywords)
|
|
|
|
|
objects, err := fs.Search(ctx, keywords...)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return serializer.Err(serializer.CodeNotSet, err.Error(), err)
|
|
|
|
|
}
|
|
|
|
|