Phase 3 part 1: Search Console and what already ranks
PLAN: Phase 3 rewritten around a weekly seven-job SEO loop (what ranks, next keywords, brief, page, approval, morning check, Monday report), with chatseo.app's ideas borrowed and rankings from Search Console only. Google OAuth (PKCE, offline, read-only webmasters scope) from Settings → Search engines, with each website's property. Search Console is synced into SQLite by day (site, page, and page+query; 16 months, then twice a day). SEO → What ranks shows the last 90 days: totals, the share of clicks from hidden queries, best pages, queries shown but not clicked, and the pages to protect and to push, each with its numbers. Schema 12. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -358,6 +358,13 @@ func (s *Server) oauthStart(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
authURL, p, err = oauth.RedditStart(id, s.callbackURL("reddit"))
|
||||
case "google":
|
||||
id := s.Secrets.Get(secrets.GoogleClientID)
|
||||
if id == "" || !s.Secrets.Has(secrets.GoogleClientSecret) {
|
||||
http.Error(w, "Save Google's client ID and secret first.", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
authURL, p, err = oauth.GoogleStart(id, s.callbackURL("google"))
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
@@ -386,15 +393,19 @@ func (s *Server) oauthCallback(w http.ResponseWriter, r *http.Request) {
|
||||
p := s.pending[q.Get("state")]
|
||||
delete(s.pending, q.Get("state")) // a state is good for one callback
|
||||
s.mu.Unlock()
|
||||
back, nav := "/settings/accounts", "settings/accounts"
|
||||
if provider == "google" {
|
||||
back, nav = "/settings/search", "settings/search"
|
||||
}
|
||||
if p == nil || p.Provider != provider || time.Since(p.Started) > oauthTTL {
|
||||
s.Log.Warn("oauth: callback with an unknown or expired state", "provider", provider)
|
||||
redirect(w, r, "/settings/accounts", "oauth-expired")
|
||||
redirect(w, r, back, "oauth-expired")
|
||||
return
|
||||
}
|
||||
fail := func(msg string) {
|
||||
s.Log.Warn("oauth: sign-in failed", "provider", provider, "reason", msg)
|
||||
s.render(w, r, "message", page{Title: "Sign-in failed", Nav: "settings/accounts", Error: msg,
|
||||
Data: map[string]string{"Back": "/settings/accounts"}})
|
||||
s.render(w, r, "message", page{Title: "Sign-in failed", Nav: nav, Error: msg,
|
||||
Data: map[string]string{"Back": back}})
|
||||
}
|
||||
if e := q.Get("error"); e != "" {
|
||||
// Some providers (LinkedIn) send the description HTML-escaped;
|
||||
@@ -411,6 +422,29 @@ func (s *Server) oauthCallback(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
|
||||
defer cancel()
|
||||
switch provider {
|
||||
case "google":
|
||||
res, err := oauth.GoogleExchange(ctx, s.Secrets.Get(secrets.GoogleClientID), s.Secrets.Get(secrets.GoogleClientSecret), code, p)
|
||||
if err != nil {
|
||||
fail(err.Error())
|
||||
return
|
||||
}
|
||||
if res.RefreshToken == "" {
|
||||
fail("Google sent no refresh token, so Supermarket couldn't read Search Console on its own. Remove Supermarket's access in your Google account's security settings, then connect again.")
|
||||
return
|
||||
}
|
||||
email, err := oauth.GoogleEmail(ctx, res.AccessToken)
|
||||
if err != nil {
|
||||
s.Log.Warn("google: couldn't read the account's email", "err", err)
|
||||
}
|
||||
if err := s.Secrets.Set(map[string]string{secrets.GoogleRefreshToken: res.RefreshToken}); err != nil {
|
||||
fail("Signed in, but couldn't save the token: " + err.Error())
|
||||
return
|
||||
}
|
||||
s.setGoogleToken(res)
|
||||
if err := s.saveConnection("google", Connection{Account: email, At: time.Now()}); err != nil {
|
||||
s.Log.Error("saving connection", "err", err)
|
||||
}
|
||||
redirect(w, r, "/settings/search", "google-connected")
|
||||
case "x":
|
||||
res, err := oauth.XExchange(ctx, s.Secrets.Get(secrets.XClientID), s.Secrets.Get(secrets.XClientSecret), code, p)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user