mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-03 17:18:06 -06:00
Add preview card storing to the database
This commit is contained in:
parent
85c32526f2
commit
6169351d22
12 changed files with 228 additions and 55 deletions
|
|
@ -197,7 +197,14 @@ func (p *Processor) Create(
|
|||
|
||||
if card != nil {
|
||||
status.CardID = id.NewULIDFromTime(now)
|
||||
card.ID = status.CardID
|
||||
status.Card = card
|
||||
|
||||
// Insert this newly prepared preview card into the database.
|
||||
if err := p.state.DB.PutCard(ctx, card); err != nil {
|
||||
err := gtserror.Newf("error inserting preview card in db: %w", err)
|
||||
return nil, gtserror.NewErrorInternalError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// Only store ContentWarningText if the parsed
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ func FetchPreview(text string) (*gtsmodel.Card, gtserror.WithCode) {
|
|||
return nil, gtserror.NewErrorInternalError(fmt.Errorf("unsupported scheme: %s", parsed.Scheme))
|
||||
}
|
||||
|
||||
resp, err := http.Get(link)
|
||||
resp, err := safeGet(parsed)
|
||||
if err != nil {
|
||||
return nil, gtserror.NewErrorInternalError(err, "request failed")
|
||||
}
|
||||
|
|
@ -109,3 +109,8 @@ func FetchPreview(text string) (*gtsmodel.Card, gtserror.WithCode) {
|
|||
|
||||
return card, nil
|
||||
}
|
||||
|
||||
func safeGet(u *url.URL) (*http.Response, error) {
|
||||
// #nosec G107 -- URL was already validated
|
||||
return http.Get(u.String())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue