mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-27 06:03:51 +03:00
make route more compact
This commit is contained in:
parent
afcc7f0def
commit
7c86f13728
1 changed files with 14 additions and 13 deletions
|
@ -232,10 +232,11 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
|
|
||||||
var user *user_model.User
|
var user *user_model.User
|
||||||
|
|
||||||
log.Info("RepositoryInbox: repo %v, %v", ctx.Repo.Repository.OwnerName, ctx.Repo.Repository.Name)
|
repository := ctx.Repo.Repository
|
||||||
|
log.Info("RepositoryInbox: repo: %v, owned by: %v", repository.Name, repository.OwnerName)
|
||||||
|
|
||||||
activity := web.GetForm(ctx).(*forgefed.Star)
|
activity := web.GetForm(ctx).(*forgefed.Star)
|
||||||
log.Info("RepositoryInbox: Activity.Source %v", activity.Source)
|
log.Info("RepositoryInbox: Activity.Source: %v, Activity.Actor %v, Activity.Actor.Id %v", activity.Source, activity.Actor, activity.Actor.GetID().String())
|
||||||
log.Info("RepositoryInbox: Activity.Actor %v", activity.Actor)
|
|
||||||
|
|
||||||
// assume actor is: "actor": "https://codeberg.org/api/v1/activitypub/user-id/12345" - NB: This might be actually the ID? Maybe check vocabulary.
|
// assume actor is: "actor": "https://codeberg.org/api/v1/activitypub/user-id/12345" - NB: This might be actually the ID? Maybe check vocabulary.
|
||||||
// "https://Codeberg.org/api/v1/activitypub/user-id/12345"
|
// "https://Codeberg.org/api/v1/activitypub/user-id/12345"
|
||||||
|
@ -246,18 +247,18 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
|
|
||||||
// parse senderActorId
|
// parse senderActorId
|
||||||
// senderActorId holds the data to construct the sender of the star
|
// senderActorId holds the data to construct the sender of the star
|
||||||
log.Info("activity.Actor.GetID().String(): %v", activity.Actor.GetID().String())
|
validatedActorId, err := activitypub.ValidateAndParseIRI(activity.Actor.GetID().String())
|
||||||
validatedURL, err := activitypub.ValidateAndParseIRI(activity.Actor.GetID().String())
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
ctx.ServerError("Set Name", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
senderActorId := activitypub.ParseActorID(validatedURL, string(activity.Source))
|
actorId := activitypub.ParseActorID(validatedActorId, string(activity.Source))
|
||||||
|
|
||||||
// Is the ActorID Struct valid?
|
// Is the ActorID Struct valid?
|
||||||
senderActorId.PanicIfInvalid()
|
actorId.PanicIfInvalid()
|
||||||
log.Info("RepositoryInbox: Actor parsed. %v", senderActorId)
|
log.Info("RepositoryInbox: Actor parsed. %v", actorId)
|
||||||
|
|
||||||
remoteStargazer := senderActorId.GetNormalizedUri() // used as LoginName in newly created user
|
remoteStargazer := actorId.GetNormalizedUri() // used as LoginName in newly created user
|
||||||
log.Info("remotStargazer: %v", remoteStargazer)
|
log.Info("remotStargazer: %v", remoteStargazer)
|
||||||
|
|
||||||
// Check if user already exists
|
// Check if user already exists
|
||||||
|
@ -310,11 +311,11 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if already starred by this user
|
// check if already starred by this user
|
||||||
alreadyStared := repo_model.IsStaring(ctx, remoteUser.ID, ctx.Repo.Repository.ID)
|
alreadyStared := repo_model.IsStaring(ctx, remoteUser.ID, repository.ID)
|
||||||
switch alreadyStared {
|
switch alreadyStared {
|
||||||
case true: // execute unstar action
|
case true: // execute unstar action
|
||||||
{
|
{
|
||||||
err = repo_model.StarRepo(ctx, remoteUser.ID, ctx.Repo.Repository.ID, false)
|
err = repo_model.StarRepo(ctx, remoteUser.ID, repository.ID, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
||||||
return
|
return
|
||||||
|
@ -322,7 +323,7 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
}
|
}
|
||||||
case false: // execute star action
|
case false: // execute star action
|
||||||
{
|
{
|
||||||
err = repo_model.StarRepo(ctx, remoteUser.ID, ctx.Repo.Repository.ID, true)
|
err = repo_model.StarRepo(ctx, remoteUser.ID, repository.ID, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
ctx.Error(http.StatusInternalServerError, "StarRepo", err)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue