mirror of https://github.com/usememos/memos
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
580 B
Go
26 lines
580 B
Go
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
|
|
}
|