mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 09:35:00 +09:00
replace infrastructure-experiments to any-sync
This commit is contained in:
parent
33fdf3eb4c
commit
67614f7cb3
84 changed files with 209 additions and 218 deletions
|
@ -2,10 +2,10 @@ package linkpreview
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/golang/groupcache/lru"
|
||||
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
|
||||
"github.com/anytypeio/any-sync/app"
|
||||
"github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/model"
|
||||
"github.com/hashicorp/golang-lru"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -23,7 +23,7 @@ type cache struct {
|
|||
|
||||
func (c *cache) Init(_ *app.App) (err error) {
|
||||
c.lp = New()
|
||||
c.cache, _ = lru.New(maxCacheEntries)
|
||||
c.cache = lru.New(maxCacheEntries)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
package linkpreview
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"github.com/anytypeio/go-anytype-middleware/util/text"
|
||||
"github.com/go-shiori/go-readability"
|
||||
"github.com/mauidude/go-readability"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/app"
|
||||
"github.com/anytypeio/any-sync/app"
|
||||
"github.com/anytypeio/go-anytype-middleware/util/uri"
|
||||
|
||||
"github.com/anytypeio/go-anytype-middleware/pkg/lib/pb/model"
|
||||
|
@ -87,7 +87,7 @@ func (l *linkPreview) convertOGToInfo(fetchUrl string, og *opengraph.OpenGraph)
|
|||
}
|
||||
|
||||
if len(og.Image) != 0 {
|
||||
url, err := uri.NormalizeURI(og.Image[0].URL)
|
||||
url, err := uri.ProcessURI(og.Image[0].URL)
|
||||
if err == nil {
|
||||
i.ImageUrl = url
|
||||
}
|
||||
|
@ -102,12 +102,11 @@ func (l *linkPreview) findContent(data []byte) (content string) {
|
|||
// ignore possible panic while html parsing
|
||||
}
|
||||
}()
|
||||
|
||||
article, err := readability.FromReader(bytes.NewReader(data), nil)
|
||||
doc, err := readability.NewDocument(string(data))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
content = article.TextContent
|
||||
content = doc.Content()
|
||||
content = strings.TrimSpace(l.bmPolicy.Sanitize(content))
|
||||
content = strings.Join(strings.Fields(content), " ") // removes repetitive whitespaces
|
||||
if text.UTF16RuneCountString(content) > maxDescriptionSize {
|
||||
|
@ -128,11 +127,11 @@ func (l *linkPreview) makeNonHtml(fetchUrl string, resp *http.Response) (i model
|
|||
} else {
|
||||
i.Type = model.LinkPreview_Unknown
|
||||
}
|
||||
pURL, e := uri.ParseURI(fetchUrl)
|
||||
pUrl, e := url.Parse(fetchUrl)
|
||||
if e == nil {
|
||||
pURL.Path = "favicon.ico"
|
||||
pURL.RawQuery = ""
|
||||
i.FaviconUrl = pURL.String()
|
||||
pUrl.Path = "favicon.ico"
|
||||
pUrl.RawQuery = ""
|
||||
i.FaviconUrl = pUrl.String()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue