Post Reddit drafts by hand: Open in Reddit, Copy text, Mark as posted

Reddit now approves API apps before they get keys, so Supermarket may not
be able to post there for a while. Each Reddit draft in the Inbox can be
posted by hand instead:

- Open in Reddit saves the edits and opens old.reddit.com's submit page
  for the subreddit in a new tab, with the title and text filled in, the
  source link added and own-site links UTM-tagged as publishing would.
  Links-only subreddits get a link post. Over ~7500 characters the text
  is left out of the address.
- Copy text copies the draft's current text.
- Mark as posted (with the post's link, optional) moves it to Published
  and into the Reddit history used for warnings.

Copy buttons now copy a field's current value, not its first text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-21 11:51:16 -07:00
co-authored by Claude Opus 5.5
parent 9c62680927
commit 013e30bf40
7 changed files with 171 additions and 10 deletions
+61
View File
@@ -316,3 +316,64 @@ func TestOwnContentPage(t *testing.T) {
t.Errorf("write: %s", rec.Body.String())
}
}
func TestPostRedditByHand(t *testing.T) {
s, h := newTestServer(t, nil)
_ = profile.Save(s.DB, &profile.Profile{Name: "Acme", Description: "Widgets.", Websites: []profile.Website{{URL: "https://acme.example"}}})
if _, err := content.CreateDrafts(s.DB, []content.Draft{
{InventoryName: "Acme", Kind: "product", Channel: content.ChannelReddit, Title: "Widget 2", Target: "selfhosted",
Content: "We made a widget.", SourceURL: "https://acme.example/widget"},
{InventoryName: "Acme", Kind: "product", Channel: content.ChannelReddit, Title: "Links", Target: "linksonly",
Content: "Body", SourceURL: "https://acme.example/w"},
}); err != nil {
t.Fatal(err)
}
_ = content.SaveSubreddit(s.DB, &reddit.Subreddit{Name: "linksonly", SubmissionType: "link", FetchedAt: time.Now()})
ids := map[string]string{}
ds, _ := content.ListDrafts(s.DB, 10, content.StatusDraft)
for _, d := range ds {
ids[d.Target] = strconv.FormatInt(d.ID, 10)
}
if body := do(h, http.MethodGet, "/inbox", nil, nil).Body.String(); !strings.Contains(body, "Open in Reddit") ||
!strings.Contains(body, "can't post to Reddit for you yet") || !strings.Contains(body, `action="/drafts/`+ids["selfhosted"]+`/posted"`) {
t.Error("inbox lacks the by-hand controls")
}
// Open saves the edits, then goes to Reddit's submit page, filled in and tagged.
rec := postForm(h, "/drafts/"+ids["selfhosted"]+"/open", url.Values{"title": {"Widget 2 is out"}, "content": {"Edited."}})
loc, _ := url.Parse(rec.Header().Get("Location"))
q := loc.Query()
if rec.Code != http.StatusSeeOther || loc.Host != "old.reddit.com" || loc.Path != "/r/selfhosted/submit" ||
q.Get("title") != "Widget 2 is out" || q.Get("selftext") != "true" ||
!strings.HasPrefix(q.Get("text"), "Edited.\n\nSource: https://acme.example/widget?") || !strings.Contains(q.Get("text"), "utm_source=reddit") {
t.Errorf("open: %d %s", rec.Code, loc)
}
if d, _ := content.GetDraft(s.DB, mustID(ids["selfhosted"])); d.Title != "Widget 2 is out" || d.Content != "Edited." || d.Status != content.StatusDraft {
t.Errorf("open should save the edits and leave it a draft: %+v", d)
}
// A links-only subreddit gets a link post.
loc, _ = url.Parse(postForm(h, "/drafts/"+ids["linksonly"]+"/open", nil).Header().Get("Location"))
if q := loc.Query(); q.Get("text") != "" || !strings.HasPrefix(q.Get("url"), "https://acme.example/w?") {
t.Errorf("link post: %s", loc)
}
// Mark as posted: a bad link is refused, a good one recorded.
if rec := postForm(h, "/drafts/"+ids["selfhosted"]+"/posted", url.Values{"post_url": {"not a link"}}); !strings.Contains(rec.Body.String(), "isn&#39;t a link to a post") {
t.Error("bad post link accepted")
}
post := "https://www.reddit.com/r/selfhosted/comments/abc/widget_2/"
if rec := postForm(h, "/drafts/"+ids["selfhosted"]+"/posted", url.Values{"post_url": {post}}); rec.Code != http.StatusSeeOther {
t.Fatalf("posted: %d %s", rec.Code, rec.Body.String())
}
if d, _ := content.GetDraft(s.DB, mustID(ids["selfhosted"])); d.Status != content.StatusPublished || d.PostURL != post || d.PublishedAt.IsZero() {
t.Errorf("posted: %+v", d)
}
if !strings.Contains(do(h, http.MethodGet, "/content/published", nil, nil).Body.String(), post) {
t.Error("the post isn't listed under Published")
}
// Without a link it still counts as posted.
if rec := postForm(h, "/drafts/"+ids["linksonly"]+"/posted", nil); rec.Code != http.StatusSeeOther {
t.Errorf("posted without a link: %d", rec.Code)
}
}