Add preview card storing to the database

This commit is contained in:
kaimanhub 2025-03-30 20:24:15 +03:00
commit 6169351d22
12 changed files with 228 additions and 55 deletions

View file

@ -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())
}