Skip to content

Commit

Permalink
feat: 移除token
Browse files Browse the repository at this point in the history
  • Loading branch information
xbpk3t committed Jun 1, 2024
1 parent 2386621 commit 54298da
Show file tree
Hide file tree
Showing 41 changed files with 3,236 additions and 50 deletions.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
575 changes: 575 additions & 0 deletions .workflow/info.plist

Large diffs are not rendered by default.

File renamed without changes
2 changes: 1 addition & 1 deletion workflow/Makefile → Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ENABLED_AUTO_UPDATE ?= "false"
LDFLAGS ?= -X github.com/hxhac/docs-alfred/workflow/cmd.EnabledAutoUpdate=$(ENABLED_AUTO_UPDATE)
LDFLAGS ?= -X github.com/hxhac/docs-alfred/cmd.EnabledAutoUpdate=$(ENABLED_AUTO_UPDATE)

HAVE_GO_BINDATA := $(shell command -v go-bindata 2> /dev/null)
generate: ## go generate
Expand Down
File renamed without changes.
File renamed without changes.
13 changes: 9 additions & 4 deletions workflow/cmd/f.go → cmd/f.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ import (
"slices"
"strings"

"github.com/hxhac/docs-alfred/workflow/pkg/ws"
"github.com/hxhac/docs-alfred/pkg/ws"

"github.com/hxhac/docs-alfred/workflow/pkg/qs"
"github.com/hxhac/docs-alfred/pkg/qs"

aw "github.com/deanishe/awgo"
"github.com/hxhac/docs-alfred/workflow/pkg/gh"
"github.com/hxhac/docs-alfred/pkg/gh"

"github.com/spf13/cobra"
)

const (
ConfigGithub = "gh.yml"
RepoDB = "/repo.db"
)

// fCmd represents the f command
var fCmd = &cobra.Command{
Use: "f",
Expand Down Expand Up @@ -85,7 +90,7 @@ var ghCmd = &cobra.Command{
Short: "Searching from starred repositories and my repositories",
Run: func(cmd *cobra.Command, args []string) {
repos := gh.NewRepos()
err := repos.ListRepositories(wf.CacheDir() + "/repo.db")
err := repos.ListRepositories(wf.CacheDir() + RepoDB)
if err != nil {
wf.FatalError(err)
}
Expand Down
File renamed without changes.
11 changes: 6 additions & 5 deletions workflow/cmd/sync.go → cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"time"

"github.com/hxhac/docs-alfred/workflow/pkg/gh"
"github.com/hxhac/docs-alfred/pkg/gh"

"github.com/spf13/cobra"
)
Expand All @@ -26,7 +26,7 @@ var syncCmd = &cobra.Command{
_, err := wf.Cache.LoadOrStore(cfgFile, time.Duration(expire)*time.Minute, func() ([]byte, error) {
resp, err := http.Get(url)
if err != nil {
slog.Error("request error", slog.Any("err", err))
slog.Error("request error", slog.Any("Error", err))
return nil, err
}
defer resp.Body.Close()
Expand All @@ -37,10 +37,11 @@ var syncCmd = &cobra.Command{
}

switch cfgFile {
case "gh.yml":
case ConfigGithub:
token := wf.Config.GetString("gh_token")
gh := gh.NewRepos()
if _, err := gh.UpdateRepositories(token, wf.CacheDir()+"/repo.db"); err != nil {
if _, err := gh.UpdateRepositories(token, wf.CacheDir()+RepoDB); err != nil {
slog.Error("failed to update repo by token", slog.Any("Error", err))
ErrorHandle(err)
}
default:
Expand All @@ -54,7 +55,7 @@ var syncCmd = &cobra.Command{
}
slog.Info("Sync Repos Successfully.")
} else {
slog.Info("URL is Empty", slog.Any("url", url))
slog.Info("URL is Empty", slog.Any("URL", url))
}
},
}
Expand Down
8 changes: 8 additions & 0 deletions workflow/exec.sh → exec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

go run main.go f qs --config=qs.yml

go run main.go f gh --config=gh.yml

# f gh --config=gh.yml
# sync --config=gh.yml

go run main.go md qs --config qs.yml --target qs.md

alfred_workflow_bundleid=com.hapihacking.pwgen alfred_workflow_cache=./testenv/cache alfred_workflow_data=./testenv/cache alfred_workflow_name=docs-alfred alfred_workflow_version=2.0.0 go run main.go md qs --config qs.yml --target qs.md



7 changes: 4 additions & 3 deletions feeds-merge/cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package cmd

import (
"github.com/hxhac/docs-alfred/feeds-merge/pkg"
"github.com/samber/lo"
"github.com/spf13/cobra"
"log/slog"
"os"
"sync"

"github.com/hxhac/docs-alfred/feeds-merge/pkg"
"github.com/samber/lo"
"github.com/spf13/cobra"
)

var wg sync.WaitGroup
Expand Down
36 changes: 18 additions & 18 deletions feeds-merge/pkg/merge.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package pkg

import (
"github.com/avast/retry-go"
"gopkg.in/yaml.v3"
"log/slog"
"net/http"
"os"
"strconv"
"sync"
"time"

"github.com/avast/retry-go"
"gopkg.in/yaml.v3"

"github.com/gorilla/feeds"
"github.com/mmcdole/gofeed"
)
Expand Down Expand Up @@ -83,21 +84,21 @@ func EnvStrToInt(envKey string, def int) int {
return ti
}

// 直接获取
func (e Config) fetchURL(url string, ch chan<- *gofeed.Feed) {
// core.Infof("Fetching URL: %v\n", url)
fp := gofeed.NewParser()
fp.Client = &http.Client{
Timeout: time.Duration(e.Timeout) * time.Second,
}
feed, err := fp.ParseURL(url)
if err == nil {
ch <- feed
} else {
slog.Info("fetchURL Error:", slog.String("URL", url), slog.Any("Error", err))
ch <- nil
}
}
// // fetchURL 直接获取
// func (e Config) fetchURL(url string, ch chan<- *gofeed.Feed) {
// // core.Infof("Fetching URL: %v\n", url)
// fp := gofeed.NewParser()
// fp.Client = &http.Client{
// Timeout: time.Duration(e.Timeout) * time.Second,
// }
// feed, err := fp.ParseURL(url)
// if err == nil {
// ch <- feed
// } else {
// slog.Info("fetchURL Error:", slog.String("URL", url), slog.Any("Error", err))
// ch <- nil
// }
// }

// 尝试retry获取
func (e Config) FetchURLWithRetry(url string, ch chan<- *gofeed.Feed) {
Expand Down Expand Up @@ -127,7 +128,6 @@ func (e Config) FetchURLWithRetry(url string, ch chan<- *gofeed.Feed) {
slog.Info("Retry Parse Feed:", slog.String("URL", url), slog.Int("Tries", int(attempts)))
}),
)

if err != nil {
slog.Info("Parse Feed Error:", slog.String("URL", url), slog.Any("Error", err))
ch <- nil // 发送 nil 表示获取失败
Expand Down
Loading

0 comments on commit 54298da

Please sign in to comment.