log new mastodon post url
This commit is contained in:
parent
3966020cfe
commit
9878f83c63
2 changed files with 103 additions and 1 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"bytes"
|
||||
"codeberg.org/lauralani/humble-bot/misc"
|
||||
"codeberg.org/lauralani/humble-bot/models"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
|
@ -24,6 +25,7 @@ func postQueueItemToMastodon(bundle models.QueueItem) error {
|
|||
urlstring := viper.GetString("mastodon.url") + "/api/v1/statuses"
|
||||
endpoint, _ := url.Parse(urlstring)
|
||||
visibility := viper.GetString("mastodon.visibility")
|
||||
var post models.MastodonPost
|
||||
|
||||
token := viper.GetString("mastodon.token")
|
||||
idemkey := uuid.New().String()
|
||||
|
@ -67,7 +69,25 @@ func postQueueItemToMastodon(bundle models.QueueItem) error {
|
|||
return errors.New("couldn't POST message to Mastodon")
|
||||
}
|
||||
|
||||
defer func(Body io.ReadCloser) {
|
||||
err := Body.Close()
|
||||
if err != nil {
|
||||
log.Error().Str("func", "postQueueItemToMastodon.body.Close()").Msg(err.Error())
|
||||
}
|
||||
}(res.Body)
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
log.Error().Str("func", "postQueueItemToMastodon.body.ReadAll()").Msg(err.Error())
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, &post)
|
||||
if err != nil {
|
||||
log.Error().Str("func", "postQueueItemToMastodon.body.Unmarshal()").
|
||||
Msgf("can't unmarshal body: %q", err)
|
||||
}
|
||||
|
||||
log.Info().
|
||||
Str("url", bundle.URL).Msg("posted new Bundle to Mastodon =)")
|
||||
Str("bundle-url", bundle.URL).Str("post-url", post.URL).Msg("posted new Bundle =)")
|
||||
return nil
|
||||
}
|
||||
|
|
82
models/mastodon.go
Normal file
82
models/mastodon.go
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* Copyright (c) 2023 Laura Kalb <dev@lauka.net>
|
||||
* The code of this project is available under the MIT license. See the LICENSE file for more info.
|
||||
*
|
||||
*/
|
||||
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type MastodonPost struct {
|
||||
ID string `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
InReplyToID string `json:"in_reply_to_id"`
|
||||
InReplyToAccountID string `json:"in_reply_to_account_id"`
|
||||
Sensitive bool `json:"sensitive"`
|
||||
SpoilerText string `json:"spoiler_text"`
|
||||
Visibility string `json:"visibility"`
|
||||
Language string `json:"language"`
|
||||
URI string `json:"uri"`
|
||||
URL string `json:"url"`
|
||||
RepliesCount int `json:"replies_count"`
|
||||
ReblogsCount int `json:"reblogs_count"`
|
||||
FavouritesCount int `json:"favourites_count"`
|
||||
Favourited bool `json:"favourited"`
|
||||
Reblogged bool `json:"reblogged"`
|
||||
Muted bool `json:"muted"`
|
||||
Bookmarked bool `json:"bookmarked"`
|
||||
Content string `json:"content"`
|
||||
Reblog any `json:"reblog,omitempty"`
|
||||
Application struct {
|
||||
Name string `json:"name"`
|
||||
Website string `json:"website,omitempty"`
|
||||
} `json:"application"`
|
||||
Account struct {
|
||||
ID string `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Acct string `json:"acct"`
|
||||
DisplayName string `json:"display_name"`
|
||||
Locked bool `json:"locked"`
|
||||
Bot bool `json:"bot"`
|
||||
Discoverable bool `json:"discoverable"`
|
||||
Group bool `json:"group"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Note string `json:"note"`
|
||||
URL string `json:"url"`
|
||||
Avatar string `json:"avatar"`
|
||||
AvatarStatic string `json:"avatar_static"`
|
||||
Header string `json:"header"`
|
||||
HeaderStatic string `json:"header_static"`
|
||||
FollowersCount int `json:"followers_count"`
|
||||
FollowingCount int `json:"following_count"`
|
||||
StatusesCount int `json:"statuses_count"`
|
||||
LastStatusAt time.Time `json:"last_status_at"`
|
||||
Emojis []any `json:"emojis,omitempty"`
|
||||
Fields []struct {
|
||||
Name string `json:"name"`
|
||||
Value string `json:"value"`
|
||||
VerifiedAt any `json:"verified_at,omitempty"`
|
||||
} `json:"fields"`
|
||||
} `json:"account"`
|
||||
MediaAttachments []any `json:"media_attachments,omitempty"`
|
||||
Mentions []any `json:"mentions,omitempty"`
|
||||
Tags []any `json:"tags,omitempty"`
|
||||
Emojis []any `json:"emojis,omitempty"`
|
||||
Card struct {
|
||||
URL string `json:"url"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Type string `json:"type"`
|
||||
AuthorName string `json:"author_name"`
|
||||
AuthorURL string `json:"author_url"`
|
||||
ProviderName string `json:"provider_name"`
|
||||
ProviderURL string `json:"provider_url"`
|
||||
HTML string `json:"html"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Image any `json:"image,omitempty"`
|
||||
EmbedURL string `json:"embed_url"`
|
||||
} `json:"card"`
|
||||
Poll any `json:"poll,omitempty"`
|
||||
}
|
Loading…
Reference in a new issue