mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-11 10:18:28 +09:00
linkPreview: favicon + url
This commit is contained in:
parent
ee3568e9b1
commit
41e57a1d20
4 changed files with 154 additions and 41 deletions
183
pb/misc.pb.go
183
pb/misc.pb.go
|
@ -529,7 +529,9 @@ type LinkPreviewResponse struct {
|
|||
Title string `protobuf:"bytes,2,opt,name=title,proto3" json:"title,omitempty"`
|
||||
Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
|
||||
ImageUrl string `protobuf:"bytes,4,opt,name=imageUrl,proto3" json:"imageUrl,omitempty"`
|
||||
Type LinkPreviewResponse_Type `protobuf:"varint,5,opt,name=type,proto3,enum=anytype.LinkPreviewResponse_Type" json:"type,omitempty"`
|
||||
Url string `protobuf:"bytes,5,opt,name=url,proto3" json:"url,omitempty"`
|
||||
FaviconUrl string `protobuf:"bytes,6,opt,name=faviconUrl,proto3" json:"faviconUrl,omitempty"`
|
||||
Type LinkPreviewResponse_Type `protobuf:"varint,7,opt,name=type,proto3,enum=anytype.LinkPreviewResponse_Type" json:"type,omitempty"`
|
||||
}
|
||||
|
||||
func (m *LinkPreviewResponse) Reset() { *m = LinkPreviewResponse{} }
|
||||
|
@ -593,6 +595,20 @@ func (m *LinkPreviewResponse) GetImageUrl() string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (m *LinkPreviewResponse) GetUrl() string {
|
||||
if m != nil {
|
||||
return m.Url
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *LinkPreviewResponse) GetFaviconUrl() string {
|
||||
if m != nil {
|
||||
return m.FaviconUrl
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *LinkPreviewResponse) GetType() LinkPreviewResponse_Type {
|
||||
if m != nil {
|
||||
return m.Type
|
||||
|
@ -672,45 +688,46 @@ func init() {
|
|||
func init() { proto.RegisterFile("misc.proto", fileDescriptor_2d3ba2f07ad357c5) }
|
||||
|
||||
var fileDescriptor_2d3ba2f07ad357c5 = []byte{
|
||||
// 600 bytes of a gzipped FileDescriptorProto
|
||||
// 619 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0xc1, 0x4e, 0xdb, 0x4c,
|
||||
0x10, 0xc7, 0xe3, 0xd8, 0xfe, 0x20, 0x83, 0xc8, 0xb7, 0x2c, 0x1c, 0xa2, 0xa8, 0xb5, 0xc0, 0x95,
|
||||
0x28, 0x27, 0x1f, 0xa0, 0x88, 0xaa, 0x3d, 0x54, 0x86, 0x98, 0xc8, 0xad, 0x59, 0x5b, 0x8b, 0x0d,
|
||||
0xb4, 0x97, 0x08, 0xc8, 0x16, 0x59, 0x4d, 0x62, 0xd7, 0x36, 0xa9, 0xf2, 0x16, 0x7d, 0x8b, 0x1e,
|
||||
0x7a, 0xab, 0xd4, 0x53, 0x5f, 0xa0, 0x52, 0x2f, 0x1c, 0x7b, 0xac, 0x92, 0xd7, 0xe8, 0xa1, 0x5a,
|
||||
0xdb, 0x09, 0xb8, 0xa9, 0x82, 0xe0, 0xb6, 0x33, 0xfe, 0xef, 0xcc, 0xfc, 0xe7, 0x67, 0x1b, 0xa0,
|
||||
0xeb, 0xc7, 0xe7, 0x5a, 0x18, 0x05, 0x49, 0x80, 0xe7, 0x4e, 0x7b, 0x83, 0x64, 0x10, 0x32, 0x75,
|
||||
0x19, 0x96, 0x8e, 0x58, 0x14, 0xfb, 0x41, 0xaf, 0xc9, 0x12, 0xca, 0xde, 0x5f, 0xb2, 0x38, 0x51,
|
||||
0xbf, 0x96, 0x01, 0xdf, 0xcc, 0xc6, 0x61, 0xd0, 0x8b, 0x19, 0xde, 0x01, 0x99, 0x45, 0x51, 0x10,
|
||||
0xd5, 0x84, 0x55, 0x61, 0x63, 0x61, 0x73, 0x4d, 0xcb, 0x8b, 0x68, 0xd3, 0x5a, 0xcd, 0xe0, 0x42,
|
||||
0x9a, 0xe9, 0x71, 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,
|
||||
0xdc, 0x8d, 0xde, 0x8b, 0x7b, 0xd0, 0x2b, 0xe0, 0xda, 0x06, 0x89, 0xcf, 0xcd, 0x0b, 0x38, 0x7a,
|
||||
0xd3, 0xc8, 0xde, 0x7b, 0xf3, 0x80, 0x1f, 0x05, 0x9e, 0x74, 0x8d, 0x13, 0x7e, 0xa7, 0x0a, 0xe0,
|
||||
0x11, 0xe3, 0xc4, 0x31, 0xf6, 0x5c, 0xa3, 0x81, 0xc4, 0xdd, 0x07, 0xdf, 0x87, 0x8a, 0x70, 0x35,
|
||||
0x54, 0x84, 0x5f, 0x43, 0x45, 0xf8, 0x38, 0x52, 0x4a, 0x57, 0x23, 0xa5, 0xf4, 0x73, 0xa4, 0x94,
|
||||
0xde, 0x94, 0xc3, 0xb3, 0xb3, 0xff, 0xd2, 0xbf, 0xe1, 0xd6, 0x9f, 0x00, 0x00, 0x00, 0xff, 0xff,
|
||||
0x56, 0x36, 0x32, 0xd1, 0x1b, 0x05, 0x00, 0x00,
|
||||
0x14, 0x85, 0xe3, 0xc4, 0x26, 0xe4, 0x22, 0xf2, 0x0f, 0x03, 0x8b, 0x28, 0xfa, 0x6b, 0x81, 0x2b,
|
||||
0x51, 0x56, 0x59, 0x40, 0x11, 0x55, 0xbb, 0xa8, 0x0c, 0x31, 0x91, 0x5b, 0x33, 0xb6, 0x06, 0x1b,
|
||||
0x68, 0x37, 0x51, 0x48, 0x06, 0x64, 0x35, 0xd8, 0xae, 0x6d, 0x52, 0xf1, 0x16, 0x7d, 0x8b, 0x2e,
|
||||
0xba, 0xab, 0xd4, 0x77, 0xa8, 0xd4, 0x0d, 0xcb, 0x2e, 0x2b, 0x58, 0xf7, 0x0d, 0xba, 0xa8, 0xc6,
|
||||
0x76, 0x0c, 0x6e, 0xaa, 0x20, 0xd8, 0xcd, 0xbd, 0x3e, 0x73, 0x7d, 0xce, 0xfd, 0x64, 0x03, 0x9c,
|
||||
0xb9, 0x51, 0xbf, 0x15, 0x84, 0x7e, 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74, 0x48, 0x1b, 0x31, 0x3c, 0x07, 0x55, 0x5b, 0xdf, 0xd3, 0x4c, 0xc7, 0x46,
|
||||
0x27, 0xca, 0x67, 0x01, 0xea, 0x86, 0x7f, 0xba, 0xcf, 0xbc, 0x41, 0xb6, 0x4a, 0x1e, 0xfd, 0x8c,
|
||||
0x45, 0x51, 0xef, 0x34, 0x4d, 0x56, 0xa3, 0xe3, 0x12, 0x6f, 0x80, 0x34, 0x64, 0x23, 0x36, 0x4c,
|
||||
0xec, 0xd6, 0xd7, 0x1f, 0xe5, 0x89, 0x8b, 0x13, 0x5a, 0x06, 0x17, 0xd1, 0x54, 0xab, 0xbc, 0x02,
|
||||
0x29, 0xa9, 0x71, 0x0d, 0xa4, 0xb6, 0xb6, 0xed, 0x74, 0x50, 0x89, 0x1f, 0xc7, 0x09, 0x6a, 0x20,
|
||||
0xed, 0xaa, 0xb6, 0x6a, 0xa0, 0x32, 0x4f, 0xaa, 0x93, 0x5d, 0x13, 0x55, 0x78, 0xd3, 0x52, 0x89,
|
||||
0xbe, 0x83, 0x44, 0xee, 0xf6, 0x50, 0xa5, 0x44, 0x27, 0x1d, 0x24, 0x29, 0xbf, 0x05, 0xf8, 0x2f,
|
||||
0x7f, 0x57, 0x86, 0xf8, 0x69, 0x11, 0xb1, 0x3c, 0x69, 0xea, 0x1f, 0x7c, 0x9b, 0x5f, 0x72, 0x8a,
|
||||
0x5b, 0x05, 0x8a, 0x8f, 0xa7, 0x5f, 0xbf, 0x1f, 0x42, 0xf2, 0x00, 0x84, 0xd3, 0x60, 0xad, 0x02,
|
||||
0x36, 0x5c, 0xef, 0x9d, 0x15, 0xb2, 0x91, 0xcb, 0x3e, 0x8c, 0x79, 0x21, 0xa8, 0x9c, 0x87, 0xc3,
|
||||
0x8c, 0x15, 0x3f, 0x2a, 0xbf, 0x2a, 0xb0, 0x58, 0x10, 0x66, 0xab, 0x7a, 0x56, 0x5c, 0x95, 0x72,
|
||||
0x93, 0x75, 0x52, 0x5c, 0xfc, 0x1c, 0x96, 0x40, 0x8a, 0xdd, 0x78, 0xc8, 0xb2, 0x94, 0x69, 0xf1,
|
||||
0xf7, 0x06, 0x2a, 0x13, 0x1b, 0xc0, 0x4d, 0x98, 0x75, 0xcf, 0x7a, 0xa7, 0xcc, 0x09, 0x87, 0x0d,
|
||||
0x31, 0x79, 0x9c, 0xd7, 0x63, 0xdf, 0x52, 0xee, 0x1b, 0xcb, 0x00, 0x27, 0xbd, 0x91, 0xdb, 0xf7,
|
||||
0x3d, 0xae, 0x9f, 0x49, 0x1e, 0xdc, 0xea, 0xe0, 0x4d, 0x10, 0xb9, 0xdd, 0x46, 0x35, 0x41, 0xb5,
|
||||
0x32, 0xd5, 0xbe, 0x7d, 0x11, 0x30, 0x9a, 0xc8, 0x9b, 0x9f, 0x72, 0xd6, 0x2f, 0x0a, 0xac, 0x9f,
|
||||
0xdc, 0x9d, 0xff, 0x7e, 0xbc, 0x5f, 0x3e, 0x80, 0x77, 0x01, 0xf0, 0x26, 0x88, 0xdc, 0x37, 0x1f,
|
||||
0x60, 0xa9, 0x1d, 0x2d, 0xfd, 0x52, 0xf4, 0x3d, 0x7e, 0x14, 0x78, 0xd3, 0xd6, 0x8e, 0xf8, 0x9d,
|
||||
0x3a, 0x80, 0x43, 0xb4, 0x23, 0x4b, 0xdb, 0xb1, 0xb5, 0x36, 0xaa, 0x6c, 0xff, 0xff, 0xed, 0x4a,
|
||||
0x16, 0x2e, 0xaf, 0x64, 0xe1, 0xe7, 0x95, 0x2c, 0x7c, 0xbc, 0x96, 0x4b, 0x97, 0xd7, 0x72, 0xe9,
|
||||
0xc7, 0xb5, 0x5c, 0x7a, 0x5b, 0x0e, 0x8e, 0x8f, 0x67, 0x92, 0xff, 0xe7, 0xc6, 0x9f, 0x00, 0x00,
|
||||
0x00, 0xff, 0xff, 0x13, 0x97, 0xe7, 0x57, 0x4d, 0x05, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *VersionGetRequest) Marshal() (dAtA []byte, err error) {
|
||||
|
@ -971,7 +988,21 @@ func (m *LinkPreviewResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
|||
if m.Type != 0 {
|
||||
i = encodeVarintMisc(dAtA, i, uint64(m.Type))
|
||||
i--
|
||||
dAtA[i] = 0x28
|
||||
dAtA[i] = 0x38
|
||||
}
|
||||
if len(m.FaviconUrl) > 0 {
|
||||
i -= len(m.FaviconUrl)
|
||||
copy(dAtA[i:], m.FaviconUrl)
|
||||
i = encodeVarintMisc(dAtA, i, uint64(len(m.FaviconUrl)))
|
||||
i--
|
||||
dAtA[i] = 0x32
|
||||
}
|
||||
if len(m.Url) > 0 {
|
||||
i -= len(m.Url)
|
||||
copy(dAtA[i:], m.Url)
|
||||
i = encodeVarintMisc(dAtA, i, uint64(len(m.Url)))
|
||||
i--
|
||||
dAtA[i] = 0x2a
|
||||
}
|
||||
if len(m.ImageUrl) > 0 {
|
||||
i -= len(m.ImageUrl)
|
||||
|
@ -1177,6 +1208,14 @@ func (m *LinkPreviewResponse) Size() (n int) {
|
|||
if l > 0 {
|
||||
n += 1 + l + sovMisc(uint64(l))
|
||||
}
|
||||
l = len(m.Url)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovMisc(uint64(l))
|
||||
}
|
||||
l = len(m.FaviconUrl)
|
||||
if l > 0 {
|
||||
n += 1 + l + sovMisc(uint64(l))
|
||||
}
|
||||
if m.Type != 0 {
|
||||
n += 1 + sovMisc(uint64(m.Type))
|
||||
}
|
||||
|
@ -2027,6 +2066,70 @@ func (m *LinkPreviewResponse) Unmarshal(dAtA []byte) error {
|
|||
m.ImageUrl = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 5:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Url", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowMisc
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthMisc
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthMisc
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.Url = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 6:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field FaviconUrl", wireType)
|
||||
}
|
||||
var stringLen uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowMisc
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
stringLen |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
intStringLen := int(stringLen)
|
||||
if intStringLen < 0 {
|
||||
return ErrInvalidLengthMisc
|
||||
}
|
||||
postIndex := iNdEx + intStringLen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthMisc
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.FaviconUrl = string(dAtA[iNdEx:postIndex])
|
||||
iNdEx = postIndex
|
||||
case 7:
|
||||
if wireType != 0 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType)
|
||||
}
|
||||
|
|
|
@ -65,7 +65,9 @@ message LinkPreviewResponse {
|
|||
string title = 2;
|
||||
string description = 3;
|
||||
string imageUrl = 4;
|
||||
Type type = 5;
|
||||
string url = 5;
|
||||
string faviconUrl = 6;
|
||||
Type type = 7;
|
||||
|
||||
message Error {
|
||||
Code code = 1;
|
||||
|
|
|
@ -41,10 +41,13 @@ func (l *linkPreview) Fetch(ctx context.Context, url string) (pb.LinkPreviewResp
|
|||
}
|
||||
|
||||
func (l *linkPreview) convertOGToInfo(og *opengraph.OpenGraph) (i pb.LinkPreviewResponse) {
|
||||
og.ToAbsURL()
|
||||
i = pb.LinkPreviewResponse{
|
||||
Url: og.URL.String(),
|
||||
Title: og.Title,
|
||||
Description: og.Description,
|
||||
Type: pb.LinkPreviewResponse_PAGE,
|
||||
FaviconUrl: og.Favicon,
|
||||
}
|
||||
if len(og.Image) != 0 {
|
||||
i.ImageUrl = og.Image[0].URL
|
||||
|
@ -54,6 +57,7 @@ func (l *linkPreview) convertOGToInfo(og *opengraph.OpenGraph) (i pb.LinkPreview
|
|||
|
||||
func (l *linkPreview) makeNonHtml(url string, resp *http.Response) (i pb.LinkPreviewResponse, err error) {
|
||||
ct := resp.Header.Get("Content-Type")
|
||||
i.Url = url
|
||||
i.Title = filepath.Base(url)
|
||||
if strings.HasPrefix(ct, "image/") {
|
||||
i.Type = pb.LinkPreviewResponse_IMAGE
|
||||
|
|
|
@ -24,6 +24,8 @@ func TestLinkPreview_Fetch(t *testing.T) {
|
|||
info, err := lp.Fetch(ctx, ts.URL)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, pb.LinkPreviewResponse{
|
||||
Url: ts.URL,
|
||||
FaviconUrl: ts.URL + "/favicon.ico",
|
||||
Title: "Title",
|
||||
Description: "Description",
|
||||
ImageUrl: "http://site.com/images/example.jpg",
|
||||
|
@ -40,6 +42,7 @@ func TestLinkPreview_Fetch(t *testing.T) {
|
|||
info, err := lp.Fetch(ctx, url)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, pb.LinkPreviewResponse{
|
||||
Url: url,
|
||||
Title: "filename.jpg",
|
||||
ImageUrl: url,
|
||||
Type: pb.LinkPreviewResponse_IMAGE,
|
||||
|
@ -56,6 +59,7 @@ func TestLinkPreview_Fetch(t *testing.T) {
|
|||
info, err := lp.Fetch(ctx, url)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, pb.LinkPreviewResponse{
|
||||
Url: url,
|
||||
Title: "filename.jpg",
|
||||
Type: pb.LinkPreviewResponse_UNEXPECTED,
|
||||
}, info)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue