Compare commits
4 commits
b363b87013
...
2c0a4c88d5
Author | SHA1 | Date | |
---|---|---|---|
2c0a4c88d5 | |||
e7632c6ad4 | |||
06841782df | |||
4f64f0b847 |
4 changed files with 60 additions and 18 deletions
|
@ -2,13 +2,15 @@ FROM docker.io/node:22 AS build-ember
|
||||||
# TODO: Implement ember frontend build
|
# TODO: Implement ember frontend build
|
||||||
COPY . /app
|
COPY . /app
|
||||||
WORKDIR /app/frontend-reactive
|
WORKDIR /app/frontend-reactive
|
||||||
RUN npm install && npm run build
|
RUN npm install
|
||||||
|
RUN npm run build
|
||||||
|
|
||||||
FROM docker.io/golang:1.24 AS build-go
|
FROM docker.io/golang:1.24 AS build-go
|
||||||
# TODO: Implement golang build
|
# TODO: Implement golang build
|
||||||
|
|
||||||
COPY --from=build-ember /app /app
|
COPY --from=build-ember /app /app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
RUN GOTOOLCHAIN=auto GOSUMDB=sum.golang.org go get
|
||||||
RUN CGO_ENABLED=0 GOTOOLCHAIN=auto GOSUMDB=sum.golang.org go build -o /app/linstrom .
|
RUN CGO_ENABLED=0 GOTOOLCHAIN=auto GOSUMDB=sum.golang.org go build -o /app/linstrom .
|
||||||
|
|
||||||
# FROM fedora:latest AS release
|
# FROM fedora:latest AS release
|
||||||
|
|
|
@ -74,16 +74,30 @@ func insertDefaultDuck() (*models.MediaMetadata, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func insertServer(duck *models.MediaMetadata) (*models.RemoteServer, error) {
|
func insertServer(duck *models.MediaMetadata) (*models.RemoteServer, error) {
|
||||||
// dbServer, err := dbgen.RemoteServer.Where(dbgen.RemoteServer.ID.Eq(1)).First()
|
rs := dbgen.RemoteServer
|
||||||
// if err == nil {
|
dbServer, err := rs.Where(rs.IsSelf.Is(true)).First()
|
||||||
// return dbServer, nil
|
if err == nil {
|
||||||
// } else if err != gorm.ErrRecordNotFound {
|
// Exists, ensure up to date info
|
||||||
// return nil, err
|
tx := dbgen.Q.Begin()
|
||||||
// }
|
if _, err = tx.RemoteServer.Where(rs.IsSelf.Is(true)).UpdateColumn(rs.Version, shared.Version); err != nil {
|
||||||
|
_ = tx.Rollback()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if _, err = tx.RemoteServer.Where(rs.IsSelf.Is(true)).
|
||||||
|
UpdateColumn(rs.Name, config.GlobalConfig.Self.ServerDisplayName); err != nil {
|
||||||
|
_ = tx.Rollback()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err = tx.Commit(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return dbServer, nil
|
||||||
|
} else if err != gorm.ErrRecordNotFound {
|
||||||
|
// Db fail
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// Doesn't exist, create
|
||||||
server := models.RemoteServer{
|
server := models.RemoteServer{
|
||||||
Model: gorm.Model{
|
|
||||||
ID: 1,
|
|
||||||
},
|
|
||||||
ServerType: models.ServerSoftwareLinstrom,
|
ServerType: models.ServerSoftwareLinstrom,
|
||||||
SpecificType: "linstrom",
|
SpecificType: "linstrom",
|
||||||
Version: shared.Version,
|
Version: shared.Version,
|
||||||
|
@ -93,7 +107,7 @@ func insertServer(duck *models.MediaMetadata) (*models.RemoteServer, error) {
|
||||||
IconId: sql.NullString{String: duck.ID, Valid: true},
|
IconId: sql.NullString{String: duck.ID, Valid: true},
|
||||||
IsSelf: true,
|
IsSelf: true,
|
||||||
}
|
}
|
||||||
err := dbgen.RemoteServer.Save(&server)
|
err = rs.Create(&server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
|
||||||
log := hlog.FromRequest(r)
|
log := hlog.FromRequest(r)
|
||||||
userId := r.PathValue("id")
|
userId := r.PathValue("id")
|
||||||
body, err := io.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
log.Info().
|
log.Trace().
|
||||||
Err(err).
|
Err(err).
|
||||||
Str("userId", userId).
|
Str("userId", userId).
|
||||||
Bytes("body", body).
|
Bytes("body", body).
|
||||||
|
@ -268,6 +268,11 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
follower, err := activitypub.ImportRemoteAccountByAPUrl(actorApId)
|
follower, err := activitypub.ImportRemoteAccountByAPUrl(actorApId)
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("Failed to import following account")
|
||||||
|
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
u2u := dbgen.UserToUserRelation
|
u2u := dbgen.UserToUserRelation
|
||||||
followRelations, err := u2u.Where(
|
followRelations, err := u2u.Where(
|
||||||
u2u.UserId.Eq(follower.ID),
|
u2u.UserId.Eq(follower.ID),
|
||||||
|
@ -297,7 +302,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
||||||
}
|
}
|
||||||
err = tx.UserToUserRelation.Create(&req)
|
err = tx.UserToUserRelation.Create(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
_ = tx.Rollback()
|
||||||
log.Error().Err(err).Any("follow-request", req).Msg("Failed to store follow request")
|
log.Error().Err(err).Any("follow-request", req).Msg("Failed to store follow request")
|
||||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
@ -310,7 +315,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
||||||
}
|
}
|
||||||
err = tx.Activity.Create(&activity)
|
err = tx.Activity.Create(&activity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
_ = tx.Rollback()
|
||||||
log.Error().Err(err).Any("activity", activity).Msg("Failed to store follow activity")
|
log.Error().Err(err).Any("activity", activity).Msg("Failed to store follow activity")
|
||||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
@ -318,11 +323,18 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
||||||
err = tx.Commit()
|
err = tx.Commit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("Failed to commit follow activity transaction")
|
log.Error().Err(err).Msg("Failed to commit follow activity transaction")
|
||||||
|
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if !followed.RestrictedFollow {
|
if !followed.RestrictedFollow {
|
||||||
// FIXME: Handle errors
|
|
||||||
tx = dbgen.Q.Begin()
|
tx = dbgen.Q.Begin()
|
||||||
_, err = u2u.Where(u2u.ID.Eq(req.ID)).UpdateColumn(u2u.Relation, models.RelationFollow)
|
_, err = u2u.Where(u2u.ID.Eq(req.ID)).UpdateColumn(u2u.Relation, models.RelationFollow)
|
||||||
|
if err != nil {
|
||||||
|
_ = tx.Rollback()
|
||||||
|
log.Error().Err(err).Msg("Failed to update follow to confirmed")
|
||||||
|
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
acceptActivity := models.Activity{
|
acceptActivity := models.Activity{
|
||||||
Id: shared.NewId(),
|
Id: shared.NewId(),
|
||||||
Type: string(models.ActivityAccept),
|
Type: string(models.ActivityAccept),
|
||||||
|
@ -330,9 +342,20 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
||||||
ObjectType: uint32(models.ActivitystreamsActivityTargetActivity),
|
ObjectType: uint32(models.ActivitystreamsActivityTargetActivity),
|
||||||
}
|
}
|
||||||
err = tx.Activity.Create(&acceptActivity)
|
err = tx.Activity.Create(&acceptActivity)
|
||||||
tx.Commit()
|
if err != nil {
|
||||||
|
_ = tx.Rollback()
|
||||||
|
log.Error().Err(err).Msg("Failed to store accept activity in db")
|
||||||
|
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = tx.Commit()
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("Failed to commit follow accept to db")
|
||||||
|
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
go func() {
|
go func() {
|
||||||
// FIXME: Clean this entire mess up
|
// TODO: Maybe move this part to a separate function
|
||||||
time.Sleep(time.Millisecond * 20)
|
time.Sleep(time.Millisecond * 20)
|
||||||
webAccept, err := AcceptFromStorage(r.Context(), acceptActivity.Id)
|
webAccept, err := AcceptFromStorage(r.Context(), acceptActivity.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -345,6 +368,10 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
||||||
log.Error().Err(err).Msg("Failed to marshal accept")
|
log.Error().Err(err).Msg("Failed to marshal accept")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Debug().
|
||||||
|
Bytes("body", body).
|
||||||
|
Str("target", follower.RemoteInfo.InboxLink).
|
||||||
|
Msg("Sending follow accept out")
|
||||||
res, err := webshared.RequestSignedCavage(
|
res, err := webshared.RequestSignedCavage(
|
||||||
"POST",
|
"POST",
|
||||||
follower.RemoteInfo.InboxLink,
|
follower.RemoteInfo.InboxLink,
|
||||||
|
|
|
@ -89,7 +89,6 @@ func GenerateStringToSign(
|
||||||
// usedHeaders = append(usedHeaders, k)
|
// usedHeaders = append(usedHeaders, k)
|
||||||
}
|
}
|
||||||
tmp := strings.TrimSuffix(dataBuilder.String(), "\n")
|
tmp := strings.TrimSuffix(dataBuilder.String(), "\n")
|
||||||
log.Debug().Str("Raw signature string", tmp).Send()
|
|
||||||
return tmp
|
return tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue