mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-24 08:57:03 -05:00
Limit number of characters on body log
This commit is contained in:
parent
3363b3bf0c
commit
afc9acd925
1 changed files with 21 additions and 7 deletions
|
@ -193,29 +193,27 @@ func createUserFromAP(ctx *context.APIContext, personId forgefed.PersonId) (*use
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &user_model.User{}, err
|
return &user_model.User{}, err
|
||||||
}
|
}
|
||||||
|
log.Info("RepositoryInbox: got status: %v", response.Status)
|
||||||
|
|
||||||
// validate response; ToDo: Should we widen the restrictions here?
|
// validate response; ToDo: Should we widen the restrictions here?
|
||||||
if response.StatusCode != 200 {
|
if response.StatusCode != 200 {
|
||||||
err = fmt.Errorf("got non 200 status code for id: %v", personId.Id)
|
err = fmt.Errorf("got non 200 status code for id: %v", personId.Id)
|
||||||
return &user_model.User{}, err
|
return &user_model.User{}, err
|
||||||
}
|
}
|
||||||
log.Info("RepositoryInbox: got status: %v", response.Status)
|
|
||||||
|
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
body, err := io.ReadAll(response.Body)
|
body, err := io.ReadAll(response.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &user_model.User{}, err
|
return &user_model.User{}, err
|
||||||
}
|
}
|
||||||
log.Info("RepositoryInbox: got body: %v", string(body))
|
log.Info("RepositoryInbox: got body: %v", char_limiter(string(body), 120))
|
||||||
|
|
||||||
person := ap.Person{}
|
person := ap.Person{}
|
||||||
if strings.Contains(string(body), "user does not exist") {
|
err = person.UnmarshalJSON(body)
|
||||||
err = fmt.Errorf("the requested user id did not exist on the remote server: %v", personId.Id)
|
|
||||||
} else {
|
|
||||||
err = person.UnmarshalJSON(body)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &user_model.User{}, err
|
return &user_model.User{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("RepositoryInbox: got person by ap: %v", person)
|
log.Info("RepositoryInbox: got person by ap: %v", person)
|
||||||
email := fmt.Sprintf("%v@%v", uuid.New().String(), personId.Host)
|
email := fmt.Sprintf("%v@%v", uuid.New().String(), personId.Host)
|
||||||
loginName := personId.AsLoginName()
|
loginName := personId.AsLoginName()
|
||||||
|
@ -251,3 +249,19 @@ func createUserFromAP(ctx *context.APIContext, personId forgefed.PersonId) (*use
|
||||||
|
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Thanks to https://www.socketloop.com/tutorials/golang-characters-limiter-example
|
||||||
|
func char_limiter(s string, limit int) string {
|
||||||
|
|
||||||
|
reader := strings.NewReader(s)
|
||||||
|
|
||||||
|
buff := make([]byte, limit)
|
||||||
|
|
||||||
|
n, _ := io.ReadAtLeast(reader, buff, limit)
|
||||||
|
|
||||||
|
if n != 0 {
|
||||||
|
return fmt.Sprint(string(buff), "...")
|
||||||
|
} else {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue