List attachments api

This commit is contained in:
2024-07-25 22:12:00 +08:00
parent 9ceb9925dd
commit 01e395b2bf
3 changed files with 49 additions and 2 deletions

View File

@ -3,12 +3,14 @@ package grpc
import (
"context"
"fmt"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
"git.solsynth.dev/hydrogen/paperclip/pkg/proto"
"google.golang.org/protobuf/types/known/emptypb"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
jsoniter "github.com/json-iterator/go"
"github.com/samber/lo"
)
func (v *Server) GetAttachment(ctx context.Context, request *proto.AttachmentLookupRequest) (*proto.Attachment, error) {
@ -31,6 +33,10 @@ func (v *Server) GetAttachment(ctx context.Context, request *proto.AttachmentLoo
rawMetadata, _ := jsoniter.Marshal(attachment.Metadata)
if attachment.AccountID == nil {
attachment.AccountID = lo.ToPtr[uint](0)
}
return &proto.Attachment{
Id: uint64(attachment.ID),
Uuid: attachment.Uuid,
@ -43,7 +49,7 @@ func (v *Server) GetAttachment(ctx context.Context, request *proto.AttachmentLoo
Destination: attachment.Destination,
Metadata: rawMetadata,
IsMature: attachment.IsMature,
AccountId: uint64(attachment.AccountID),
AccountId: uint64(*attachment.AccountID),
}, nil
}