mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-12-23 21:14:41 +00:00
Compare commits
5 Commits
v0.4.2-alp
...
v0.4.2-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6d7012d5f | ||
|
|
85a803d352 | ||
|
|
5def3e5856 | ||
|
|
c768260b1b | ||
|
|
46e146e633 |
128
CODE_OF_CONDUCT.md
Normal file
128
CODE_OF_CONDUCT.md
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
# Contributor Covenant Code of Conduct
|
||||||
|
|
||||||
|
## Our Pledge
|
||||||
|
|
||||||
|
We as members, contributors, and leaders pledge to make participation in our
|
||||||
|
community a harassment-free experience for everyone, regardless of age, body
|
||||||
|
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
||||||
|
identity and expression, level of experience, education, socio-economic status,
|
||||||
|
nationality, personal appearance, race, religion, or sexual identity
|
||||||
|
and orientation.
|
||||||
|
|
||||||
|
We pledge to act and interact in ways that contribute to an open, welcoming,
|
||||||
|
diverse, inclusive, and healthy community.
|
||||||
|
|
||||||
|
## Our Standards
|
||||||
|
|
||||||
|
Examples of behavior that contributes to a positive environment for our
|
||||||
|
community include:
|
||||||
|
|
||||||
|
* Demonstrating empathy and kindness toward other people
|
||||||
|
* Being respectful of differing opinions, viewpoints, and experiences
|
||||||
|
* Giving and gracefully accepting constructive feedback
|
||||||
|
* Accepting responsibility and apologizing to those affected by our mistakes,
|
||||||
|
and learning from the experience
|
||||||
|
* Focusing on what is best not just for us as individuals, but for the
|
||||||
|
overall community
|
||||||
|
|
||||||
|
Examples of unacceptable behavior include:
|
||||||
|
|
||||||
|
* The use of sexualized language or imagery, and sexual attention or
|
||||||
|
advances of any kind
|
||||||
|
* Trolling, insulting or derogatory comments, and personal or political attacks
|
||||||
|
* Public or private harassment
|
||||||
|
* Publishing others' private information, such as a physical or email
|
||||||
|
address, without their explicit permission
|
||||||
|
* Other conduct which could reasonably be considered inappropriate in a
|
||||||
|
professional setting
|
||||||
|
|
||||||
|
## Enforcement Responsibilities
|
||||||
|
|
||||||
|
Community leaders are responsible for clarifying and enforcing our standards of
|
||||||
|
acceptable behavior and will take appropriate and fair corrective action in
|
||||||
|
response to any behavior that they deem inappropriate, threatening, offensive,
|
||||||
|
or harmful.
|
||||||
|
|
||||||
|
Community leaders have the right and responsibility to remove, edit, or reject
|
||||||
|
comments, commits, code, wiki edits, issues, and other contributions that are
|
||||||
|
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
||||||
|
decisions when appropriate.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
This Code of Conduct applies within all community spaces, and also applies when
|
||||||
|
an individual is officially representing the community in public spaces.
|
||||||
|
Examples of representing our community include using an official e-mail address,
|
||||||
|
posting via an official social media account, or acting as an appointed
|
||||||
|
representative at an online or offline event.
|
||||||
|
|
||||||
|
## Enforcement
|
||||||
|
|
||||||
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||||
|
reported to the community leaders responsible for enforcement at
|
||||||
|
wiki@casaos.io.
|
||||||
|
All complaints will be reviewed and investigated promptly and fairly.
|
||||||
|
|
||||||
|
All community leaders are obligated to respect the privacy and security of the
|
||||||
|
reporter of any incident.
|
||||||
|
|
||||||
|
## Enforcement Guidelines
|
||||||
|
|
||||||
|
Community leaders will follow these Community Impact Guidelines in determining
|
||||||
|
the consequences for any action they deem in violation of this Code of Conduct:
|
||||||
|
|
||||||
|
### 1. Correction
|
||||||
|
|
||||||
|
**Community Impact**: Use of inappropriate language or other behavior deemed
|
||||||
|
unprofessional or unwelcome in the community.
|
||||||
|
|
||||||
|
**Consequence**: A private, written warning from community leaders, providing
|
||||||
|
clarity around the nature of the violation and an explanation of why the
|
||||||
|
behavior was inappropriate. A public apology may be requested.
|
||||||
|
|
||||||
|
### 2. Warning
|
||||||
|
|
||||||
|
**Community Impact**: A violation through a single incident or series
|
||||||
|
of actions.
|
||||||
|
|
||||||
|
**Consequence**: A warning with consequences for continued behavior. No
|
||||||
|
interaction with the people involved, including unsolicited interaction with
|
||||||
|
those enforcing the Code of Conduct, for a specified period of time. This
|
||||||
|
includes avoiding interactions in community spaces as well as external channels
|
||||||
|
like social media. Violating these terms may lead to a temporary or
|
||||||
|
permanent ban.
|
||||||
|
|
||||||
|
### 3. Temporary Ban
|
||||||
|
|
||||||
|
**Community Impact**: A serious violation of community standards, including
|
||||||
|
sustained inappropriate behavior.
|
||||||
|
|
||||||
|
**Consequence**: A temporary ban from any sort of interaction or public
|
||||||
|
communication with the community for a specified period of time. No public or
|
||||||
|
private interaction with the people involved, including unsolicited interaction
|
||||||
|
with those enforcing the Code of Conduct, is allowed during this period.
|
||||||
|
Violating these terms may lead to a permanent ban.
|
||||||
|
|
||||||
|
### 4. Permanent Ban
|
||||||
|
|
||||||
|
**Community Impact**: Demonstrating a pattern of violation of community
|
||||||
|
standards, including sustained inappropriate behavior, harassment of an
|
||||||
|
individual, or aggression toward or disparagement of classes of individuals.
|
||||||
|
|
||||||
|
**Consequence**: A permanent ban from any sort of public interaction within
|
||||||
|
the community.
|
||||||
|
|
||||||
|
## Attribution
|
||||||
|
|
||||||
|
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
||||||
|
version 2.0, available at
|
||||||
|
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
||||||
|
|
||||||
|
Community Impact Guidelines were inspired by [Mozilla's code of conduct
|
||||||
|
enforcement ladder](https://github.com/mozilla/diversity).
|
||||||
|
|
||||||
|
[homepage]: https://www.contributor-covenant.org
|
||||||
|
|
||||||
|
For answers to common questions about this code of conduct, see the FAQ at
|
||||||
|
https://www.contributor-covenant.org/faq. Translations are available at
|
||||||
|
https://www.contributor-covenant.org/translations.
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
Description=rclone
|
Description=rclone
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStartPre=/usr/bin/rm -f /tmp/rclone.sock
|
ExecStartPre=/usr/bin/rm -f /var/run/rclone/rclone.sock
|
||||||
ExecStart=/usr/bin/rclone rcd --rc-addr unix:///tmp/rclone.sock --rc-no-auth
|
ExecStart=/usr/bin/rclone rcd --rc-addr unix:///var/run/rclone/rclone.sock --rc-no-auth --rc-allow-origin "*"
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
|
|
||||||
|
|||||||
1
main.go
1
main.go
@@ -144,6 +144,7 @@ func main() {
|
|||||||
"/v1/driver",
|
"/v1/driver",
|
||||||
"/v1/cloud",
|
"/v1/cloud",
|
||||||
"/v1/recover",
|
"/v1/recover",
|
||||||
|
"/v1/other",
|
||||||
route.V2APIPath,
|
route.V2APIPath,
|
||||||
route.V2DocPath,
|
route.V2DocPath,
|
||||||
route.V3FilePath,
|
route.V3FilePath,
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
type SearchFileInfo struct {
|
type SearchEngine struct {
|
||||||
Path string `json:"path"`
|
Name string `json:"name"`
|
||||||
Name string `json:"name"`
|
Icon string `json:"icon"`
|
||||||
Type int `json:"type"`
|
SearchUrl string `json:"search_url"`
|
||||||
|
RecoUrl string `json:"reco_url"`
|
||||||
|
Data []string `json:"data"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ var DefaultTimeout = time.Second * 30
|
|||||||
|
|
||||||
func NewRestyClient() *resty.Client {
|
func NewRestyClient() *resty.Client {
|
||||||
|
|
||||||
unixSocket := "/tmp/rclone.sock"
|
unixSocket := "/var/run/rclone/rclone.sock"
|
||||||
|
|
||||||
transport := http.Transport{
|
transport := http.Transport{
|
||||||
Dial: func(_, _ string) (net.Conn, error) {
|
Dial: func(_, _ string) (net.Conn, error) {
|
||||||
|
|||||||
@@ -156,6 +156,12 @@ func InitV1Router() *gin.Engine {
|
|||||||
// merge to system
|
// merge to system
|
||||||
v1NotifyGroup.POST("/system_status", v1.PostSystemStatusNotify)
|
v1NotifyGroup.POST("/system_status", v1.PostSystemStatusNotify)
|
||||||
}
|
}
|
||||||
|
v1OtherGroup := v1Group.Group("/other")
|
||||||
|
v1OtherGroup.Use()
|
||||||
|
{
|
||||||
|
v1OtherGroup.GET("/search", v1.GetSearchResult)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|||||||
26
route/v1/other.go
Normal file
26
route/v1/other.go
Normal file
@@ -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})
|
||||||
|
}
|
||||||
@@ -26,6 +26,7 @@ func GetRecoverStorage(c *gin.Context) {
|
|||||||
c.String(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
|
c.String(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
|
||||||
notify["status"] = "fail"
|
notify["status"] = "fail"
|
||||||
notify["message"] = "Code cannot be empty"
|
notify["message"] = "Code cannot be empty"
|
||||||
|
logger.Error("Then code is empty: ", zap.String("code", add.Code), zap.Any("name", "google_drive"))
|
||||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -41,6 +42,7 @@ func GetRecoverStorage(c *gin.Context) {
|
|||||||
c.String(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
|
c.String(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
|
||||||
notify["status"] = "fail"
|
notify["status"] = "fail"
|
||||||
notify["message"] = "Initialization failure"
|
notify["message"] = "Initialization failure"
|
||||||
|
logger.Error("Then init error: ", zap.Error(err), zap.Any("name", "google_drive"))
|
||||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -50,6 +52,7 @@ func GetRecoverStorage(c *gin.Context) {
|
|||||||
c.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
|
c.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
|
||||||
notify["status"] = "fail"
|
notify["status"] = "fail"
|
||||||
notify["message"] = "Failed to get user information"
|
notify["message"] = "Failed to get user information"
|
||||||
|
logger.Error("Then get user info error: ", zap.Error(err), zap.Any("name", "google_drive"))
|
||||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -57,9 +60,10 @@ func GetRecoverStorage(c *gin.Context) {
|
|||||||
dmap["username"] = username
|
dmap["username"] = username
|
||||||
configs, err := service.MyService.Storage().GetConfig()
|
configs, err := service.MyService.Storage().GetConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
|
c.String(200, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
|
||||||
notify["status"] = "fail"
|
notify["status"] = "fail"
|
||||||
notify["message"] = "Failed to get user information"
|
notify["message"] = "Failed to get rclone config"
|
||||||
|
logger.Error("Then get config error: ", zap.Error(err), zap.Any("name", "google_drive"))
|
||||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -107,6 +111,7 @@ func GetRecoverStorage(c *gin.Context) {
|
|||||||
c.String(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
|
c.String(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
|
||||||
notify["status"] = "fail"
|
notify["status"] = "fail"
|
||||||
notify["message"] = "Code cannot be empty"
|
notify["message"] = "Code cannot be empty"
|
||||||
|
logger.Error("Then code is empty error: ", zap.String("code", add.Code), zap.Any("name", "dropbox"))
|
||||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -120,6 +125,7 @@ func GetRecoverStorage(c *gin.Context) {
|
|||||||
c.String(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
|
c.String(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
|
||||||
notify["status"] = "fail"
|
notify["status"] = "fail"
|
||||||
notify["message"] = "Initialization failure"
|
notify["message"] = "Initialization failure"
|
||||||
|
logger.Error("Then init error: ", zap.Error(err), zap.Any("name", "dropbox"))
|
||||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -128,6 +134,7 @@ func GetRecoverStorage(c *gin.Context) {
|
|||||||
c.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
|
c.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
|
||||||
notify["status"] = "fail"
|
notify["status"] = "fail"
|
||||||
notify["message"] = "Failed to get user information"
|
notify["message"] = "Failed to get user information"
|
||||||
|
logger.Error("Then get user information: ", zap.Error(err), zap.Any("name", "dropbox"))
|
||||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -136,9 +143,10 @@ func GetRecoverStorage(c *gin.Context) {
|
|||||||
|
|
||||||
configs, err := service.MyService.Storage().GetConfig()
|
configs, err := service.MyService.Storage().GetConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
|
c.String(200, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
|
||||||
notify["status"] = "fail"
|
notify["status"] = "fail"
|
||||||
notify["message"] = "Failed to get user information"
|
notify["message"] = "Failed to get rclone config"
|
||||||
|
logger.Error("Then get config error: ", zap.Error(err), zap.Any("name", "dropbox"))
|
||||||
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,15 +199,17 @@ func DeleteSambaConnections(c *gin.Context) {
|
|||||||
c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.Record_NOT_EXIST, Message: common_err.GetMsg(common_err.Record_NOT_EXIST)})
|
c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.Record_NOT_EXIST, Message: common_err.GetMsg(common_err.Record_NOT_EXIST)})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mountPointList, err := service.MyService.System().GetDirPath(connection.MountPoint)
|
mountPointList, err := samba.GetSambaSharesList(connection.Host, connection.Port, connection.Username, connection.Password)
|
||||||
|
//mountPointList, err := service.MyService.System().GetDirPath(connection.MountPoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
|
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
|
return
|
||||||
}
|
}
|
||||||
|
baseHostPath := "/mnt/" + connection.Host
|
||||||
for _, v := range mountPointList {
|
for _, v := range mountPointList {
|
||||||
err := service.MyService.Connections().UnmountSmaba(v.Path)
|
err := service.MyService.Connections().UnmountSmaba(baseHostPath + "/" + v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("unmount smaba error", zap.Error(err), zap.Any("path", v.Path))
|
logger.Error("unmount smaba error", zap.Error(err), zap.Any("path", baseHostPath+"/"+v))
|
||||||
c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR), Data: err.Error()})
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -138,8 +139,10 @@ func InitV2DocRouter(docHTML string, docYAML string) http.Handler {
|
|||||||
}
|
}
|
||||||
func InitFile() http.Handler {
|
func InitFile() http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
path := r.URL.Query().Get("path")
|
filePath := r.URL.Query().Get("path")
|
||||||
http.ServeFile(w, r, path)
|
fileName := path.Base(filePath)
|
||||||
|
w.Header().Add("Content-Disposition", "attachment; filename*=utf-8''"+url.PathEscape(fileName))
|
||||||
|
http.ServeFile(w, r, filePath)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
104
service/other.go
Normal file
104
service/other.go
Normal file
@@ -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{}
|
||||||
|
}
|
||||||
12
service/other_test.go
Normal file
12
service/other_test.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,6 +46,7 @@ type Repository interface {
|
|||||||
FsLinkService() FsLinkService
|
FsLinkService() FsLinkService
|
||||||
FsService() FsService
|
FsService() FsService
|
||||||
MessageBus() *message_bus.ClientWithResponses
|
MessageBus() *message_bus.ClientWithResponses
|
||||||
|
Other() OtherService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewService(db *gorm.DB, RuntimePath string) Repository {
|
func NewService(db *gorm.DB, RuntimePath string) Repository {
|
||||||
@@ -69,6 +70,7 @@ func NewService(db *gorm.DB, RuntimePath string) Repository {
|
|||||||
fs_list: NewFsListService(),
|
fs_list: NewFsListService(),
|
||||||
fs_link: NewFsLinkService(),
|
fs_link: NewFsLinkService(),
|
||||||
fs: NewFsService(),
|
fs: NewFsService(),
|
||||||
|
other: NewOtherService(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +90,11 @@ type store struct {
|
|||||||
fs_link FsLinkService
|
fs_link FsLinkService
|
||||||
fs FsService
|
fs FsService
|
||||||
health HealthService
|
health HealthService
|
||||||
|
other OtherService
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *store) Other() OtherService {
|
||||||
|
return c.other
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *store) FsLinkService() FsLinkService {
|
func (c *store) FsLinkService() FsLinkService {
|
||||||
|
|||||||
Reference in New Issue
Block a user