Begin work on outline page and route
This commit is contained in:
@@ -518,3 +518,32 @@ func (chain *ProxyChain) Execute() error {
|
||||
|
||||
// return chain.Context.SendStream(body)
|
||||
}
|
||||
|
||||
func (chain *ProxyChain) ExecuteForAPI() (string, error) {
|
||||
defer chain._reset()
|
||||
body, err := chain._execute()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return "", err
|
||||
}
|
||||
if chain.Context == nil {
|
||||
return "", errors.New("no context set")
|
||||
}
|
||||
|
||||
// in case api user did not set or forward content-type, we do it for them
|
||||
/*
|
||||
if chain.Context.Get("content-type") == "" {
|
||||
chain.Context.Set("content-type", chain.Response.Header.Get("content-type"))
|
||||
}
|
||||
*/
|
||||
|
||||
// Capture the HTML content in a variable
|
||||
htmlContent, err := io.ReadAll(body)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Return the HTML content to the client
|
||||
return string(htmlContent), nil
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package responsemodifers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
//"github.com/go-shiori/dom"
|
||||
"github.com/go-shiori/dom"
|
||||
"github.com/markusmobius/go-trafilatura"
|
||||
|
||||
//"golang.org/x/net/html"
|
||||
|
||||
"ladder/proxychain"
|
||||
@@ -37,15 +38,9 @@ func APIOutline() proxychain.ResponseModification {
|
||||
return nil
|
||||
}
|
||||
|
||||
doc := api.ExtractResultToAPIResponse(result)
|
||||
jsonData, err := json.MarshalIndent(doc, "", "\t")
|
||||
if err != nil {
|
||||
chain.Response.Body = api.CreateAPIErrReader(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(jsonData)
|
||||
chain.Response.Body = io.NopCloser(buf)
|
||||
doc := trafilatura.CreateReadableDocument(result)
|
||||
reader := io.NopCloser(strings.NewReader(dom.OuterHTML(doc)))
|
||||
chain.Response.Body = reader
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user