Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add default hosts #108

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cmd/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
)

type DownloadOpts struct {
allowHost string
outputDir string
dump bool
}
Expand All @@ -24,7 +23,7 @@ var downloadOpts = DownloadOpts{}

func handleDownloadCommand(url string, opts *DownloadOpts) error {
// Validate the url to download
domain, docType, docToken, err := utils.ValidateDownloadURL(url, opts.allowHost)
domain, docType, docToken, err := utils.ValidateDownloadURL(url)
utils.CheckErr(err)
fmt.Println("Captured document token:", docToken)

Expand Down
6 changes: 0 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ func main() {
Usage: "Specify the output directory for the markdown files",
Destination: &downloadOpts.outputDir,
},
&cli.StringFlag{
Name: "allowHost",
Value: "",
Usage: "Additional allow host for the OPEN API",
Destination: &downloadOpts.allowHost,
},
&cli.BoolFlag{
Name: "dump",
Value: false,
Expand Down
10 changes: 4 additions & 6 deletions utils/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ func UnescapeURL(rawURL string) string {
return rawURL
}

func ValidateDownloadURL(url, allowHost string) (string, string, string, error) {
hosts := []string{"feishu.cn", "larksuite.com"}
if allowHost != "" {
hosts = append(hosts, allowHost)
}
func ValidateDownloadURL(url string) (string, string, string, error) {
hosts := []string{"feishu.cn", "larksuite.com", "larkoffice.com"}

reg := regexp.MustCompile("^https://([\\w-]+.)?(" + strings.Join(hosts, "|") + ")/(docs|docx|wiki)/([a-zA-Z0-9]+)")
matchResult := reg.FindStringSubmatch(url)
if matchResult == nil || len(matchResult) != 5 {
return "", "", "", errors.Errorf("Invalid feishu/larksuite/allowHost URL format")
return "", "", "", errors.Errorf("Invalid document URL format")
}

return matchResult[2], matchResult[3], matchResult[4], nil
}
Loading