add media description submit (very woozy way, but it works as possible)

This commit is contained in:
localhost_frssoft 2023-11-11 01:20:20 +03:00
parent 58a2a1748e
commit cfddec036c
6 changed files with 26 additions and 7 deletions

1
README
View File

@ -12,6 +12,7 @@ Changes (localhost_custom fork):
- visible edited post time
- visible quoted post (status in status)
- visible profile banner in spoiler
- add media description submit (very woozy way, but it works as possible)
- add schedule status
- add language input form
- add expiry status

View File

@ -431,7 +431,7 @@ func (c *Client) Search(ctx context.Context, q string, qType string, limit int,
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()
if err != nil {
return nil, err
@ -441,7 +441,7 @@ func (c *Client) UploadMediaFromMultipartFileHeader(ctx context.Context, fh *mul
var buf bytes.Buffer
mw := multipart.NewWriter(&buf)
fname := filepath.Base(fh.Filename)
err = mw.WriteField("description", fname)
err = mw.WriteField("description", descr)
if err != nil {
return nil, err
}

View File

@ -76,6 +76,14 @@ func generatePollOptions() string {
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)(&gt;.*)(<br|$)")
func statusContentFilter(content string, emojis []mastodon.Emoji, mentions []mastodon.Mention) string {
@ -166,8 +174,9 @@ func NewRenderer(templateGlobPattern string) (r *renderer, err error) {
t := template.New("default")
t, err = t.Funcs(template.FuncMap{
"EmojiFilter": emojiFilter,
"Allowed_emoji_page": allowed_emoji_page,
"Allowed_emoji_page": allowed_emoji_page,
"GeneratePollOptions": generatePollOptions,
"GenerateMediaDescrForm": generateMediaDescrForm,
"StatusContentFilter": statusContentFilter,
"DisplayInteractionCount": displayInteractionCount,
"TimeSince": timeSince,

View File

@ -979,11 +979,12 @@ func (s *service) Signout(c *client) (err error) {
func (s *service) Post(c *client, content string, replyToID string,
format string, visibility string, isNSFW bool, spoilerText 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
for _, f := range files {
a, err := c.UploadMediaFromMultipartFileHeader(c.ctx, f)
for idx, f := range files {
a, err := c.UploadMediaFromMultipartFileHeader(c.ctx, f, mediaDescription[idx])
if err != nil {
return "", err
}

View File

@ -313,6 +313,11 @@ func NewHandler(s *service, verbose bool, staticDir string) http.Handler {
isNSFW := c.r.FormValue("is_nsfw") == "true"
quickReply := c.r.FormValue("quickreply") == "true"
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")
language := c.r.FormValue("lang-code")
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"
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 {
return err
}

View File

@ -43,6 +43,9 @@
<div>
<span class="post-form-field">
<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>
</div>
<button type="submit" accesskey="P" title="Post (P)"> Post </button>