Unverified Commit 0abe20df authored by Mehad Nadeem's avatar Mehad Nadeem Committed by GitHub

feat: implemented link previews (server files) (#3073)

* feat: implmented link previews (server files)

* chore: updated variable name

* chore: renamed service file from `metadata_service.go` to `link_service.go`

* fix: passing errors

* fix: fixed linter warnong about `ctx`
parent 4d41b68d
This diff is collapsed.
package v2
import (
"context"
getter "github.com/usememos/memos/plugin/http-getter"
apiv2pb "github.com/usememos/memos/proto/gen/api/v2"
)
func (*APIV2Service) GetMetadata(_ context.Context, request *apiv2pb.GetLinkMetadataRequest) (*apiv2pb.GetLinkMetadataResponse, error) {
urlStr := request.Url
htmlMeta, err := getter.GetHTMLMeta(urlStr)
if err != nil {
return nil, err
}
return &apiv2pb.GetLinkMetadataResponse{
Metadata: &apiv2pb.Metadata{
Title: htmlMeta.Title,
Description: htmlMeta.Description,
Image: htmlMeta.Image,
},
}, nil
}
...@@ -30,6 +30,7 @@ type APIV2Service struct { ...@@ -30,6 +30,7 @@ type APIV2Service struct {
apiv2pb.UnimplementedInboxServiceServer apiv2pb.UnimplementedInboxServiceServer
apiv2pb.UnimplementedActivityServiceServer apiv2pb.UnimplementedActivityServiceServer
apiv2pb.UnimplementedWebhookServiceServer apiv2pb.UnimplementedWebhookServiceServer
apiv2pb.UnimplementedLinkServiceServer
Secret string Secret string
Profile *profile.Profile Profile *profile.Profile
...@@ -66,6 +67,7 @@ func NewAPIV2Service(secret string, profile *profile.Profile, store *store.Store ...@@ -66,6 +67,7 @@ func NewAPIV2Service(secret string, profile *profile.Profile, store *store.Store
apiv2pb.RegisterInboxServiceServer(grpcServer, apiv2Service) apiv2pb.RegisterInboxServiceServer(grpcServer, apiv2Service)
apiv2pb.RegisterActivityServiceServer(grpcServer, apiv2Service) apiv2pb.RegisterActivityServiceServer(grpcServer, apiv2Service)
apiv2pb.RegisterWebhookServiceServer(grpcServer, apiv2Service) apiv2pb.RegisterWebhookServiceServer(grpcServer, apiv2Service)
apiv2pb.RegisterLinkServiceServer(grpcServer, apiv2Service)
reflection.Register(grpcServer) reflection.Register(grpcServer)
return apiv2Service return apiv2Service
...@@ -119,6 +121,9 @@ func (s *APIV2Service) RegisterGateway(ctx context.Context, e *echo.Echo) error ...@@ -119,6 +121,9 @@ func (s *APIV2Service) RegisterGateway(ctx context.Context, e *echo.Echo) error
if err := apiv2pb.RegisterWebhookServiceHandler(context.Background(), gwMux, conn); err != nil { if err := apiv2pb.RegisterWebhookServiceHandler(context.Background(), gwMux, conn); err != nil {
return err return err
} }
if err := apiv2pb.RegisterLinkServiceHandler(context.Background(), gwMux, conn); err != nil {
return err
}
e.Any("/api/v2/*", echo.WrapHandler(gwMux)) e.Any("/api/v2/*", echo.WrapHandler(gwMux))
// GRPC web proxy. // GRPC web proxy.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment