mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-16 12:03:02 +00:00
add media description submit (very woozy way, but it works as possible)
This commit is contained in:
parent
58a2a1748e
commit
cfddec036c
1
README
1
README
@ -12,6 +12,7 @@ Changes (localhost_custom fork):
|
|||||||
- visible edited post time
|
- visible edited post time
|
||||||
- visible quoted post (status in status)
|
- visible quoted post (status in status)
|
||||||
- visible profile banner in spoiler
|
- visible profile banner in spoiler
|
||||||
|
- add media description submit (very woozy way, but it works as possible)
|
||||||
- add schedule status
|
- add schedule status
|
||||||
- add language input form
|
- add language input form
|
||||||
- add expiry status
|
- add expiry status
|
||||||
|
@ -431,7 +431,7 @@ func (c *Client) Search(ctx context.Context, q string, qType string, limit int,
|
|||||||
return &results, nil
|
return &results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) UploadMediaFromMultipartFileHeader(ctx context.Context, fh *multipart.FileHeader) (*Attachment, error) {
|
func (c *Client) UploadMediaFromMultipartFileHeader(ctx context.Context, fh *multipart.FileHeader, descr string) (*Attachment, error) {
|
||||||
f, err := fh.Open()
|
f, err := fh.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -441,7 +441,7 @@ func (c *Client) UploadMediaFromMultipartFileHeader(ctx context.Context, fh *mul
|
|||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
mw := multipart.NewWriter(&buf)
|
mw := multipart.NewWriter(&buf)
|
||||||
fname := filepath.Base(fh.Filename)
|
fname := filepath.Base(fh.Filename)
|
||||||
err = mw.WriteField("description", fname)
|
err = mw.WriteField("description", descr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -76,6 +76,14 @@ func generatePollOptions() string {
|
|||||||
return pollbuilder
|
return pollbuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateMediaDescrForm() string {
|
||||||
|
var mediadescrbuilder string
|
||||||
|
for i := 0; i < 20; i++ {
|
||||||
|
mediadescrbuilder = mediadescrbuilder + `<div><textarea rows="2" id="` + fmt.Sprintf("media-descr-%d", i) + `" name="` + fmt.Sprintf("media-descr-%d", i) + `"></textarea></div>`
|
||||||
|
}
|
||||||
|
return mediadescrbuilder
|
||||||
|
}
|
||||||
|
|
||||||
var quoteRE = regexp.MustCompile("(?mU)(^|> *|\n)(>.*)(<br|$)")
|
var quoteRE = regexp.MustCompile("(?mU)(^|> *|\n)(>.*)(<br|$)")
|
||||||
|
|
||||||
func statusContentFilter(content string, emojis []mastodon.Emoji, mentions []mastodon.Mention) string {
|
func statusContentFilter(content string, emojis []mastodon.Emoji, mentions []mastodon.Mention) string {
|
||||||
@ -168,6 +176,7 @@ func NewRenderer(templateGlobPattern string) (r *renderer, err error) {
|
|||||||
"EmojiFilter": emojiFilter,
|
"EmojiFilter": emojiFilter,
|
||||||
"Allowed_emoji_page": allowed_emoji_page,
|
"Allowed_emoji_page": allowed_emoji_page,
|
||||||
"GeneratePollOptions": generatePollOptions,
|
"GeneratePollOptions": generatePollOptions,
|
||||||
|
"GenerateMediaDescrForm": generateMediaDescrForm,
|
||||||
"StatusContentFilter": statusContentFilter,
|
"StatusContentFilter": statusContentFilter,
|
||||||
"DisplayInteractionCount": displayInteractionCount,
|
"DisplayInteractionCount": displayInteractionCount,
|
||||||
"TimeSince": timeSince,
|
"TimeSince": timeSince,
|
||||||
|
@ -979,11 +979,12 @@ func (s *service) Signout(c *client) (err error) {
|
|||||||
func (s *service) Post(c *client, content string, replyToID string,
|
func (s *service) Post(c *client, content string, replyToID string,
|
||||||
format string, visibility string, isNSFW bool, spoilerText string,
|
format string, visibility string, isNSFW bool, spoilerText string,
|
||||||
files []*multipart.FileHeader, edit string, language string, expiresIn int, scheduledAt string,
|
files []*multipart.FileHeader, edit string, language string, expiresIn int, scheduledAt string,
|
||||||
pollOptions []string, pollExpiresIn int, pollHideTotals bool, pollMultiple bool) (id string, err error) {
|
pollOptions []string, pollExpiresIn int, pollHideTotals bool, pollMultiple bool,
|
||||||
|
mediaDescription []string) (id string, err error) {
|
||||||
|
|
||||||
var mediaIDs []string
|
var mediaIDs []string
|
||||||
for _, f := range files {
|
for idx, f := range files {
|
||||||
a, err := c.UploadMediaFromMultipartFileHeader(c.ctx, f)
|
a, err := c.UploadMediaFromMultipartFileHeader(c.ctx, f, mediaDescription[idx])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -313,6 +313,11 @@ func NewHandler(s *service, verbose bool, staticDir string) http.Handler {
|
|||||||
isNSFW := c.r.FormValue("is_nsfw") == "true"
|
isNSFW := c.r.FormValue("is_nsfw") == "true"
|
||||||
quickReply := c.r.FormValue("quickreply") == "true"
|
quickReply := c.r.FormValue("quickreply") == "true"
|
||||||
files := c.r.MultipartForm.File["attachments"]
|
files := c.r.MultipartForm.File["attachments"]
|
||||||
|
var mediaDescription []string
|
||||||
|
for i := 0; i < len(files); i++ {
|
||||||
|
v := c.r.FormValue(fmt.Sprintf("media-descr-%d", i))
|
||||||
|
mediaDescription = append(mediaDescription, v)
|
||||||
|
}
|
||||||
edit := c.r.FormValue("edit-status-id")
|
edit := c.r.FormValue("edit-status-id")
|
||||||
language := c.r.FormValue("lang-code")
|
language := c.r.FormValue("lang-code")
|
||||||
expiresIn, err := strconv.Atoi(c.r.FormValue("expires-in"))
|
expiresIn, err := strconv.Atoi(c.r.FormValue("expires-in"))
|
||||||
@ -342,7 +347,7 @@ func NewHandler(s *service, verbose bool, staticDir string) http.Handler {
|
|||||||
pollHideTotals := c.r.FormValue("poll-hide-totals") == "true"
|
pollHideTotals := c.r.FormValue("poll-hide-totals") == "true"
|
||||||
pollMultiple := c.r.FormValue("poll-is-multiple") == "true"
|
pollMultiple := c.r.FormValue("poll-is-multiple") == "true"
|
||||||
|
|
||||||
id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, spoilerText, files, edit, language, expiresIn, scheduledAt, pollOptions, pollExpiresIn, pollHideTotals, pollMultiple)
|
id, err := s.Post(c, content, replyToID, format, visibility, isNSFW, spoilerText, files, edit, language, expiresIn, scheduledAt, pollOptions, pollExpiresIn, pollHideTotals, pollMultiple, mediaDescription)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,9 @@
|
|||||||
<div>
|
<div>
|
||||||
<span class="post-form-field">
|
<span class="post-form-field">
|
||||||
<input id="post-file-picker" type="file" name="attachments" multiple accesskey="A" title="Attachments (A)">
|
<input id="post-file-picker" type="file" name="attachments" multiple accesskey="A" title="Attachments (A)">
|
||||||
|
<details><summary> Descriptions for media attachments </summary>
|
||||||
|
{{GenerateMediaDescrForm | Raw}}
|
||||||
|
</details>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" accesskey="P" title="Post (P)"> Post </button>
|
<button type="submit" accesskey="P" title="Post (P)"> Post </button>
|
||||||
|
Loading…
Reference in New Issue
Block a user