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:
+57
-1
@@ -5,6 +5,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -228,7 +229,7 @@ func (s *Server) draftAction(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
action := r.PathValue("action")
|
||||
switch action {
|
||||
case "save", "publish", "schedule":
|
||||
case "save", "publish", "schedule", "open":
|
||||
if title, sent := r.PostForm["title"]; sent {
|
||||
if err := content.UpdateTitle(s.DB, id, title[0]); err != nil {
|
||||
fail(err)
|
||||
@@ -281,6 +282,30 @@ func (s *Server) draftAction(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
redirect(w, r, back, "scheduled")
|
||||
case "open":
|
||||
// Post by hand: the edits are saved above; now off to Reddit's
|
||||
// submit page, filled in, in the tab the form opened.
|
||||
d, err := content.GetDraft(s.DB, id)
|
||||
if err != nil {
|
||||
fail(err)
|
||||
return
|
||||
}
|
||||
info, _ := content.GetSubreddit(s.DB, d.Target)
|
||||
http.Redirect(w, r, redditSubmitURL(d, s.tagger(), info), http.StatusSeeOther)
|
||||
case "posted":
|
||||
postURL := strings.TrimSpace(r.PostForm.Get("post_url"))
|
||||
if postURL != "" {
|
||||
if u, err := url.Parse(postURL); err != nil || (u.Scheme != "https" && u.Scheme != "http") || u.Host == "" {
|
||||
fail(errors.New("that isn't a link to a post: copy the address from your browser, or leave it empty"))
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := content.MarkPosted(s.DB, id, postURL); err != nil {
|
||||
fail(err)
|
||||
return
|
||||
}
|
||||
s.forgetRedditHistory()
|
||||
redirect(w, r, back, "posted")
|
||||
case "unschedule":
|
||||
if err := content.Unschedule(s.DB, id); err != nil {
|
||||
fail(err)
|
||||
@@ -370,3 +395,34 @@ func (s *Server) publishDue(ctx context.Context, now time.Time) {
|
||||
s.Log.Info("scheduler: published", "draft", d.ID, "channel", d.Channel)
|
||||
}
|
||||
}
|
||||
|
||||
// maxSubmitURL is about as long as a link to Reddit's submit page can be
|
||||
// and still open; past it, the text is left for the user to paste.
|
||||
const maxSubmitURL = 7500
|
||||
|
||||
// redditSubmitURL is Reddit's submit page for the draft's subreddit, filled
|
||||
// in: a text post with the source link at the end, or a link post where the
|
||||
// subreddit only takes links. It uses old.reddit.com, whose submit page
|
||||
// reliably takes the title and text from the address.
|
||||
func redditSubmitURL(d *content.Draft, tags *utm.Tagger, info *reddit.Subreddit) string {
|
||||
text, src := content.Manual(d, tags)
|
||||
base := "https://old.reddit.com/submit"
|
||||
if sub := reddit.CleanName(d.Target); sub != "" {
|
||||
base = "https://old.reddit.com/r/" + url.PathEscape(sub) + "/submit"
|
||||
}
|
||||
q := url.Values{"title": {d.Title}}
|
||||
if info != nil && !info.AllowsText() && src != "" {
|
||||
q.Set("url", src)
|
||||
return base + "?" + q.Encode()
|
||||
}
|
||||
if src != "" && !strings.Contains(text, src) {
|
||||
text += "\n\nSource: " + src
|
||||
}
|
||||
q.Set("selftext", "true")
|
||||
q.Set("text", text)
|
||||
if u := base + "?" + q.Encode(); len(u) <= maxSubmitURL {
|
||||
return u
|
||||
}
|
||||
q.Del("text")
|
||||
return base + "?" + q.Encode()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user