lint
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
|||||||
|
|
||||||
func NewOutlineHandler(path string, opts *ProxyOptions) fiber.Handler {
|
func NewOutlineHandler(path string, opts *ProxyOptions) fiber.Handler {
|
||||||
return func(c *fiber.Ctx) error {
|
return func(c *fiber.Ctx) error {
|
||||||
|
|
||||||
return proxychain.
|
return proxychain.
|
||||||
NewProxyChain().
|
NewProxyChain().
|
||||||
WithAPIPath(path).
|
WithAPIPath(path).
|
||||||
@@ -27,6 +26,5 @@ func NewOutlineHandler(path string, opts *ProxyOptions) fiber.Handler {
|
|||||||
).
|
).
|
||||||
SetFiberCtx(c).
|
SetFiberCtx(c).
|
||||||
Execute()
|
Execute()
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/term"
|
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
var art string = `
|
var art string = `
|
||||||
|
|||||||
@@ -3,15 +3,16 @@ package responsemodifers
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/markusmobius/go-trafilatura"
|
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/markusmobius/go-trafilatura"
|
||||||
|
|
||||||
"ladder/proxychain"
|
"ladder/proxychain"
|
||||||
"ladder/proxychain/responsemodifers/api"
|
"ladder/proxychain/responsemodifers/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// APIContent creates an JSON representation of the article and returns it as an API response.
|
// APIContent creates an JSON representation of the article and returns it as an API response.
|
||||||
func APIContent() proxychain.ResponseModification {
|
func APIContent() proxychain.ResponseModification {
|
||||||
|
|
||||||
return func(chain *proxychain.ProxyChain) error {
|
return func(chain *proxychain.ProxyChain) error {
|
||||||
// we set content-type twice here, in case another response modifier
|
// we set content-type twice here, in case another response modifier
|
||||||
// tries to forward over the original headers
|
// tries to forward over the original headers
|
||||||
@@ -43,5 +44,4 @@ func APIContent() proxychain.ResponseModification {
|
|||||||
chain.Response.Body = io.NopCloser(bytes.NewReader(jsonData))
|
chain.Response.Body = io.NopCloser(bytes.NewReader(jsonData))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"ladder/proxychain"
|
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"ladder/proxychain"
|
||||||
|
|
||||||
"golang.org/x/net/html"
|
"golang.org/x/net/html"
|
||||||
"golang.org/x/net/html/atom"
|
"golang.org/x/net/html/atom"
|
||||||
|
|
||||||
@@ -24,7 +25,6 @@ var templateFS embed.FS
|
|||||||
// GenerateReadableOutline creates an reader-friendly distilled representation of the article.
|
// GenerateReadableOutline creates an reader-friendly distilled representation of the article.
|
||||||
// This is a reliable way of bypassing soft-paywalled articles, where the content is hidden, but still present in the DOM.
|
// This is a reliable way of bypassing soft-paywalled articles, where the content is hidden, but still present in the DOM.
|
||||||
func GenerateReadableOutline() proxychain.ResponseModification {
|
func GenerateReadableOutline() proxychain.ResponseModification {
|
||||||
|
|
||||||
// get template only once, and resuse for subsequent calls
|
// get template only once, and resuse for subsequent calls
|
||||||
f := "generate_readable_outline.html"
|
f := "generate_readable_outline.html"
|
||||||
tmpl, err := template.ParseFS(templateFS, f)
|
tmpl, err := template.ParseFS(templateFS, f)
|
||||||
@@ -33,7 +33,6 @@ func GenerateReadableOutline() proxychain.ResponseModification {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return func(chain *proxychain.ProxyChain) error {
|
return func(chain *proxychain.ProxyChain) error {
|
||||||
|
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
// 1. extract dom contents using reading mode algo
|
// 1. extract dom contents using reading mode algo
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
@@ -90,14 +89,13 @@ func GenerateReadableOutline() proxychain.ResponseModification {
|
|||||||
defer pw.Close()
|
defer pw.Close()
|
||||||
|
|
||||||
err := tmpl.Execute(pw, data) // <- render template
|
err := tmpl.Execute(pw, data) // <- render template
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("WARN: GenerateReadableOutline template rendering error: %s\n", err)
|
log.Printf("WARN: GenerateReadableOutline template rendering error: %s\n", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
chain.Context.Set("content-type", "text/html")
|
chain.Context.Set("content-type", "text/html")
|
||||||
chain.Response.Body = pr // <- replace reponse body reader with our new reader from pipe
|
chain.Response.Body = pr // <- replace response body reader with our new reader from pipe
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,7 +132,6 @@ func rewriteHrefLinks(n *html.Node, baseURL string, apiPath string) {
|
|||||||
|
|
||||||
var recurse func(*html.Node) bool
|
var recurse func(*html.Node) bool
|
||||||
recurse = func(n *html.Node) bool {
|
recurse = func(n *html.Node) bool {
|
||||||
|
|
||||||
if n.Type == html.ElementNode && n.DataAtom == atom.A {
|
if n.Type == html.ElementNode && n.DataAtom == atom.A {
|
||||||
for i := range n.Attr {
|
for i := range n.Attr {
|
||||||
attr := n.Attr[i]
|
attr := n.Attr[i]
|
||||||
|
|||||||
Reference in New Issue
Block a user