Skip to content
Merged
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
7 changes: 5 additions & 2 deletions authHandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func LoginWithProvider(w http.ResponseWriter, r *http.Request) error {
http.NotFound(w, r)
return nil
}
http.Redirect(w, r, cfg.AuthCodeURL(""), http.StatusTemporaryRedirect)
http.Redirect(w, r, cfg.AuthCodeURL(providerName), http.StatusTemporaryRedirect)
return nil
}

Expand All @@ -99,7 +99,10 @@ func Oauth2CallbackPage(w http.ResponseWriter, r *http.Request) error {
return fmt.Errorf("session error: %w", err)
}

providerName, _ := session.Values["Provider"].(string)
providerName := r.URL.Query().Get("state")
if providerName == "" {
providerName, _ = session.Values["Provider"].(string)
}
p := GetProvider(providerName)
if p == nil {
return fmt.Errorf("unknown provider")
Expand Down
5 changes: 4 additions & 1 deletion provider_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,16 @@ func (p GitHubProvider) CreateBookmarks(ctx context.Context, user string, token
return err
}
}
_, _, err := client.Repositories.CreateFile(ctx, user, RepoName, "bookmarks.txt", &github.RepositoryContentFileOptions{
_, resp, err := client.Repositories.CreateFile(ctx, user, RepoName, "bookmarks.txt", &github.RepositoryContentFileOptions{
Message: SP("Auto create from web"),
Content: []byte(text),
Branch: &branch,
Author: commitAuthor,
Committer: commitAuthor,
})
if resp != nil && resp.StatusCode == http.StatusNotFound {
return ErrRepoNotFound
}
if err != nil {
log.Printf("github CreateBookmarks: %v", err)
return fmt.Errorf("CreateBookmarks: %w", err)
Expand Down
16 changes: 11 additions & 5 deletions repo.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package gobookmarks

import "strings"

var RepoName = GetBookmarksRepoName()

// GetBookmarksRepoName returns the repository name based on the current
// configuration and build mode. When running a development build the name is
// suffixed with "-dev". The Namespace value is appended if supplied.
func GetBookmarksRepoName() string {
name := "MyBookmarks"
if version == "dev" {
name += "-dev"
ns := Namespace
if strings.EqualFold(version, "dev") {
if ns == "" {
ns = version
}
}
if Namespace != "" {
name += "-" + Namespace

name := "MyBookmarks"
if ns != "" {
name += "-" + ns
}
return name
}
Loading