mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-12-23 04:54:41 +00:00
Compare commits
5 Commits
v0.4.2-alp
...
v0.4.2-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7126cac63 | ||
|
|
151aa037bb | ||
|
|
08ed9933ee | ||
|
|
8425011e73 | ||
|
|
96ff550d61 |
33
.github/workflows/push_test_server.yml
vendored
33
.github/workflows/push_test_server.yml
vendored
@@ -18,41 +18,56 @@ jobs:
|
||||
run: sudo apt install --yes git
|
||||
- name: git global
|
||||
run: sudo git config --global --add safe.directory '*'
|
||||
-
|
||||
name: Fetch all tags
|
||||
- name: set version
|
||||
run: sudo git tag v99.99.99-alpha
|
||||
|
||||
- name: Fetch all tags
|
||||
run: sudo git fetch --force --tags
|
||||
|
||||
- name: Get version
|
||||
id: get_version
|
||||
# run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
|
||||
run: echo "VERSION=$(git describe --abbrev=0 --tags | awk -F- '{print $1}')" >> $GITHUB_ENV
|
||||
|
||||
- name: show version
|
||||
id: show_version
|
||||
# run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
|
||||
run: echo ${{env.VERSION}}
|
||||
-
|
||||
name: Set up Go
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.19
|
||||
-
|
||||
name: Run GoReleaser
|
||||
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
with:
|
||||
# either 'goreleaser' (default) or 'goreleaser-pro'
|
||||
distribution: goreleaser
|
||||
version: latest
|
||||
args: release --rm-dist
|
||||
args: release --rm-dist --snapshot
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
|
||||
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
|
||||
|
||||
- name: remove migration file
|
||||
run: sudo find . -type f \( -name '*migration*' \) -delete
|
||||
|
||||
- name: install sshpass
|
||||
run: sudo apt install sshpass --yes
|
||||
|
||||
- name: ZeroTier
|
||||
uses: zerotier/github-action@v1.0.1
|
||||
with:
|
||||
network_id: ${{ secrets.ZEROTIER_NETWORK_ID }}
|
||||
auth_token: ${{ secrets.ZEROTIER_CENTRAL_TOKEN }}
|
||||
|
||||
- name: copy tar to target host
|
||||
shell: bash
|
||||
run: |
|
||||
sshpass -p "${{ secrets.ssh_password }}" scp -r -o StrictHostKeyChecking=no -P ${{ secrets.ssh_port }} ./dist/*.gz root@${{ secrets.ssh_ip }}:/var/www/download
|
||||
sshpass -p "${{ secrets.ssh_password }}" scp -r -o StrictHostKeyChecking=no -P 22 ./dist/*.gz root@10.147.18.11:/var/www/download
|
||||
echo "ping success"
|
||||
- name: send message
|
||||
run: |
|
||||
curl -X POST -H "Content-Type: application/json" -d '{"msg_type":"text","content":{"text":"CasaOS updated"}}' https://open.feishu.cn/open-apis/bot/v2/hook/eb8f45c7-9636-4b64-84f2-a66d9aeb9d30
|
||||
curl -X POST -H "Content-Type: application/json" -d '{"msg_type":"text","content":{"text":"CasaOS updated"}}' ${{ secrets.SSH_ROBOT_URL }}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
Description=rclone
|
||||
|
||||
[Service]
|
||||
ExecStartPre=/usr/bin/rm -f /tmp/rclone.sock
|
||||
ExecStart=/usr/bin/rclone rcd --rc-addr unix:///tmp/rclone.sock --rc-no-auth --rc-allow-origin "*"
|
||||
ExecStartPre=/usr/bin/mkdir -p /var/run/rclone && /usr/bin/rm -f /var/run/rclone/rclone.sock
|
||||
ExecStart=/usr/bin/rclone rcd --rc-addr unix:///var/run/rclone/rclone.sock --rc-no-auth --rc-allow-origin "*"
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
|
||||
21
main.go
21
main.go
@@ -144,6 +144,7 @@ func main() {
|
||||
"/v1/driver",
|
||||
"/v1/cloud",
|
||||
"/v1/recover",
|
||||
"/v1/other",
|
||||
route.V2APIPath,
|
||||
route.V2DocPath,
|
||||
route.V3FilePath,
|
||||
@@ -164,14 +165,18 @@ func main() {
|
||||
events = append(events, message_bus.EventType{Name: "casaos:file:recover", SourceID: common.SERVICENAME, PropertyTypeList: []message_bus.PropertyType{}})
|
||||
events = append(events, message_bus.EventType{Name: "casaos:file:operate", SourceID: common.SERVICENAME, PropertyTypeList: []message_bus.PropertyType{}})
|
||||
// register at message bus
|
||||
|
||||
response, err := service.MyService.MessageBus().RegisterEventTypesWithResponse(context.Background(), events)
|
||||
if err != nil {
|
||||
logger.Error("error when trying to register one or more event types - some event type will not be discoverable", zap.Error(err))
|
||||
}
|
||||
|
||||
if response != nil && response.StatusCode() != http.StatusOK {
|
||||
logger.Error("error when trying to register one or more event types - some event type will not be discoverable", zap.String("status", response.Status()), zap.String("body", string(response.Body)))
|
||||
for i := 0; i < 10; i++ {
|
||||
response, err := service.MyService.MessageBus().RegisterEventTypesWithResponse(context.Background(), events)
|
||||
if err != nil {
|
||||
logger.Error("error when trying to register one or more event types - some event type will not be discoverable", zap.Error(err))
|
||||
}
|
||||
if response != nil && response.StatusCode() != http.StatusOK {
|
||||
logger.Error("error when trying to register one or more event types - some event type will not be discoverable", zap.String("status", response.Status()), zap.String("body", string(response.Body)))
|
||||
}
|
||||
if response.StatusCode() == http.StatusOK {
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
go func() {
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ var DefaultTimeout = time.Second * 30
|
||||
|
||||
func NewRestyClient() *resty.Client {
|
||||
|
||||
unixSocket := "/tmp/rclone.sock"
|
||||
unixSocket := "/var/run/rclone/rclone.sock"
|
||||
|
||||
transport := http.Transport{
|
||||
Dial: func(_, _ string) (net.Conn, error) {
|
||||
|
||||
@@ -156,6 +156,12 @@ func InitV1Router() *gin.Engine {
|
||||
// merge to system
|
||||
v1NotifyGroup.POST("/system_status", v1.PostSystemStatusNotify)
|
||||
}
|
||||
v1OtherGroup := v1Group.Group("/other")
|
||||
v1OtherGroup.Use()
|
||||
{
|
||||
v1OtherGroup.GET("/search", v1.GetSearchResult)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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})
|
||||
}
|
||||
@@ -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)})
|
||||
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 {
|
||||
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
|
||||
}
|
||||
baseHostPath := "/mnt/" + connection.Host
|
||||
for _, v := range mountPointList {
|
||||
err := service.MyService.Connections().UnmountSmaba(v.Path)
|
||||
err := service.MyService.Connections().UnmountSmaba(baseHostPath + "/" + v)
|
||||
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()})
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
FsService() FsService
|
||||
MessageBus() *message_bus.ClientWithResponses
|
||||
Other() OtherService
|
||||
}
|
||||
|
||||
func NewService(db *gorm.DB, RuntimePath string) Repository {
|
||||
@@ -69,6 +70,7 @@ func NewService(db *gorm.DB, RuntimePath string) Repository {
|
||||
fs_list: NewFsListService(),
|
||||
fs_link: NewFsLinkService(),
|
||||
fs: NewFsService(),
|
||||
other: NewOtherService(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +90,11 @@ type store struct {
|
||||
fs_link FsLinkService
|
||||
fs FsService
|
||||
health HealthService
|
||||
other OtherService
|
||||
}
|
||||
|
||||
func (c *store) Other() OtherService {
|
||||
return c.other
|
||||
}
|
||||
|
||||
func (c *store) FsLinkService() FsLinkService {
|
||||
|
||||
Reference in New Issue
Block a user