Reddit: posted by hand, with the rules pasted

Reddit's API isn't open to apps like this one, so Supermarket no longer
signs in to Reddit, publishes or schedules there, or reads subreddits and
the account's posts. The internal/api/reddit client, Reddit's OAuth, its
keys and its Social accounts card are gone.

Supermarket still writes the post. Each Reddit draft in Posts has a box
for its subreddit's rules, with a link to them on Reddit: pasted once,
they're kept (subreddits.data, as pasted_rules) and given to the model
for later drafts. Open in Reddit saves the edits and opens the submit
page filled in; Copy title and Copy text (with the tagged source link)
cover a box that comes up empty; Mark as posted records it. Warnings come
from the pasted rules and the posts marked as posted. Fill's subreddit
suggestions are kept unchecked, and say so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 11:48:54 -07:00
co-authored by Claude Opus 5.5
parent bae468e01c
commit 5451fe6d63
33 changed files with 382 additions and 1107 deletions
+2 -37
View File
@@ -11,7 +11,6 @@ import (
"supermarket/internal/ai"
linkedinapi "supermarket/internal/api/linkedin"
"supermarket/internal/api/reddit"
"supermarket/internal/api/twitter"
"supermarket/internal/oauth"
"supermarket/internal/posting"
@@ -158,7 +157,6 @@ type secretField struct {
const (
xConsole = "https://console.x.com"
linkedInApps = "https://www.linkedin.com/developers/apps"
redditApps = "https://www.reddit.com/prefs/apps"
googleCreds = "https://console.cloud.google.com/apis/credentials"
anthropicKeys = "https://platform.claude.com/settings/keys"
)
@@ -187,10 +185,6 @@ var accountFields = []secretField{
"A second LinkedIn app, linked to the company page, with the Community Management API approved by LinkedIn (it must be the app's only product). Its Auth tab has the ID.", linkedInApps},
{"LinkedIn page", secrets.LinkedInPageClientSecret, "Client secret",
"On the same Auth tab, under the client ID.", linkedInApps},
{"Reddit", secrets.RedditClientID, "Client ID",
"Create app → choose \"web app\" and enter the redirect URI above. The client ID is the string under the app's name.", redditApps},
{"Reddit", secrets.RedditClientSecret, "Client secret",
"On the same app, next to \"secret\".", redditApps},
{"YouTube", secrets.YouTubeAPIKey, "API key",
"Free. In Google Cloud, enable the YouTube Data API v3 for a project, then Credentials → Create credentials → API key. For reading channels' videos.", googleCreds},
}
@@ -254,7 +248,7 @@ func (s *Server) networks() []network {
}
set := s.secretState(names...)
accts := s.postingAccounts()
netOf := map[string]string{"x": posting.X, "linkedin": posting.LinkedIn, liPageProvider: posting.LinkedInPage, "reddit": posting.Reddit}
netOf := map[string]string{"x": posting.X, "linkedin": posting.LinkedIn, liPageProvider: posting.LinkedInPage}
connect := func(provider, token, setup, note string, ready bool, account func(string) string) *connectInfo {
c := &connectInfo{Provider: provider, Redirect: s.callbackURL(provider), Setup: setup, Note: note, Ready: ready}
for _, a := range accts {
@@ -276,7 +270,7 @@ func (s *Server) networks() []network {
}
}
var nets []network
for _, name := range []string{"X", "LinkedIn", liPageNetwork, "Reddit", "YouTube"} {
for _, name := range []string{"X", "LinkedIn", liPageNetwork, "YouTube"} {
n := network{Name: name, Set: set}
for _, f := range accountFields {
if f.Group == name {
@@ -297,10 +291,6 @@ func (s *Server) networks() []network {
set[secrets.LinkedInPageClientID] && set[secrets.LinkedInPageClientSecret], func(a string) string { return a })
n.Connect.Expiry = s.linkedInPageExpiry()
n.Connect.Page = s.pageSetup()
case "Reddit":
n.Connect = connect("reddit", secrets.RedditAccessToken, "At reddit.com/prefs/apps, create a web app with this redirect URI:",
"Reddit's API terms need approval for commercial use: Supermarket is meant for a few hand-approved posts, not volume.",
set[secrets.RedditClientID] && set[secrets.RedditClientSecret], at("u/"))
}
nets = append(nets, n)
}
@@ -395,13 +385,6 @@ func (s *Server) oauthStart(w http.ResponseWriter, r *http.Request) {
return
}
authURL, p, err = oauth.LinkedInStartScopes(liPageProvider, id, s.callbackURL(liPageProvider), s.liPageScopes())
case "reddit":
id := s.Secrets.Get(secrets.RedditClientID)
if id == "" || !s.Secrets.Has(secrets.RedditClientSecret) {
http.Error(w, "Save Reddit's client ID and secret first.", http.StatusBadRequest)
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) {
@@ -632,24 +615,6 @@ func (s *Server) oauthCallback(w http.ResponseWriter, r *http.Request) {
return
}
redirect(w, r, "/settings/accounts", "li-page-connected")
case "reddit":
res, err := oauth.RedditExchange(ctx, s.Secrets.Get(secrets.RedditClientID), s.Secrets.Get(secrets.RedditClientSecret),
s.redditUserAgent(), code, p)
if err != nil {
fail(err.Error())
return
}
name, err := reddit.New(res.AccessToken, s.redditUserAgent(), nil).Me(ctx)
if err != nil {
fail("Signed in, but couldn't read the Reddit account's name: " + err.Error())
return
}
if err := saveAccount(posting.Reddit, "u/"+name, name, res.AccessToken, res.RefreshToken, time.Time{}); err != nil {
fail("Signed in, but couldn't save the token: " + err.Error())
return
}
s.forgetRedditHistory()
redirect(w, r, back, ownMsg("reddit-connected"))
default:
http.NotFound(w, r)
}