-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix permission change cannot be unmount (#902)
- Loading branch information
Showing
10 changed files
with
170 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package model | ||
|
||
type SearchFileInfo struct { | ||
Path string `json:"path"` | ||
Name string `json:"name"` | ||
Type int `json:"type"` | ||
type SearchEngine struct { | ||
Name string `json:"name"` | ||
Icon string `json:"icon"` | ||
SearchUrl string `json:"search_url"` | ||
RecoUrl string `json:"reco_url"` | ||
Data []string `json:"data"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package v1 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/IceWhaleTech/CasaOS/model" | ||
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err" | ||
"github.com/IceWhaleTech/CasaOS/service" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func GetSearchResult(c *gin.Context) { | ||
key := c.Query("key") | ||
if key == "" { | ||
c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS), Data: "key is empty"}) | ||
return | ||
} | ||
data, err := service.MyService.Other().Search(key) | ||
if err != nil { | ||
fmt.Println(err) | ||
c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()}) | ||
return | ||
} | ||
|
||
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package service | ||
|
||
import ( | ||
"net/url" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
||
"github.com/IceWhaleTech/CasaOS-Common/utils/logger" | ||
"github.com/IceWhaleTech/CasaOS/model" | ||
"github.com/go-resty/resty/v2" | ||
"github.com/tidwall/gjson" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type OtherService interface { | ||
Search(key string) ([]model.SearchEngine, error) | ||
} | ||
|
||
type otherService struct{} | ||
|
||
func (s *otherService) Search(key string) ([]model.SearchEngine, error) { | ||
|
||
engines := []model.SearchEngine{} | ||
engines = append(engines, model.SearchEngine{ | ||
Name: "bing", | ||
Icon: "https://files.codelife.cc/itab/search/bing.svg", | ||
SearchUrl: "https://www.bing.com/search?q=", | ||
RecoUrl: "https://www.bing.com/osjson.aspx?query=", // + keyword | ||
}, model.SearchEngine{ | ||
Name: "google", | ||
Icon: "https://files.codelife.cc/itab/search/google.svg", | ||
SearchUrl: "https://www.google.com/search?q=", | ||
RecoUrl: "https://www.google.com/complete/search?client=gws-wiz&xssi=t&hl=en-US&authuser=0&dpr=1&q=", // + keyword | ||
}, model.SearchEngine{ | ||
Name: "baidu", | ||
Icon: "https://files.codelife.cc/itab/search/baidu.svg", | ||
SearchUrl: "https://www.baidu.com/s?wd=", | ||
RecoUrl: "https://www.baidu.com/sugrec?json=1&prod=pc&wd=", // + keyword | ||
}, model.SearchEngine{ | ||
Name: "duckduckgo", | ||
Icon: "https://files.codelife.cc/itab/search/duckduckgo.svg", | ||
SearchUrl: "https://duckduckgo.com/?q=", | ||
RecoUrl: "https://duckduckgo.com/ac/?type=list&q=", // + keyword | ||
}, model.SearchEngine{ | ||
Name: "startpage", | ||
Icon: "https://www.startpage.com/sp/cdn/favicons/apple-touch-icon-60x60--default.png", | ||
SearchUrl: "https://www.startpage.com/do/search?q=", | ||
RecoUrl: "https://www.startpage.com/suggestions?segment=startpage.udog&lui=english&q=", // + keyword | ||
}) | ||
|
||
client := resty.New() | ||
client.SetTimeout(3 * time.Second) // 设置全局超时时间 | ||
var wg sync.WaitGroup | ||
for i := 0; i < len(engines); i++ { | ||
wg.Add(1) | ||
go func(i int, k string) { | ||
name := engines[i].Name | ||
url := engines[i].RecoUrl + url.QueryEscape(k) | ||
defer wg.Done() | ||
resp, err := client.R().Get(url) | ||
if err != nil { | ||
logger.Error("Then get search result error: %v", zap.Error(err), zap.String("name", name), zap.String("url", url)) | ||
return | ||
} | ||
res := []string{} | ||
if name == "bing" { | ||
r := gjson.Get(resp.String(), "1") | ||
for _, v := range r.Array() { | ||
res = append(res, v.String()) | ||
} | ||
} else if name == "google" { | ||
r := gjson.Get(strings.Replace(resp.String(), ")]}'", "", 1), "0.#.0") | ||
for _, v := range r.Array() { | ||
res = append(res, strings.ReplaceAll(strings.ReplaceAll(v.String(), "<b>", " "), "</b>", "")) | ||
} | ||
} else if name == "baidu" { | ||
r := gjson.Get(resp.String(), "g.#.q") | ||
for _, v := range r.Array() { | ||
res = append(res, v.String()) | ||
} | ||
} else if name == "duckduckgo" { | ||
r := gjson.Get(resp.String(), "1") | ||
for _, v := range r.Array() { | ||
res = append(res, v.String()) | ||
} | ||
} else if name == "startpage" { | ||
r := gjson.Get(resp.String(), "suggestions.#.text") | ||
for _, v := range r.Array() { | ||
res = append(res, v.String()) | ||
} | ||
} | ||
engines[i].Data = res | ||
}(i, key) | ||
} | ||
wg.Wait() | ||
|
||
return engines, nil | ||
|
||
} | ||
|
||
func NewOtherService() OtherService { | ||
return &otherService{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package service | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSearch(t *testing.T) { | ||
if d, e := NewOtherService().Search("test"); e != nil || d == nil { | ||
|
||
t.Error("then test search error", e) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters