add templater

This commit is contained in:
idk
2022-01-22 00:32:39 -05:00
parent f3905a3e35
commit 239aef0bba
4 changed files with 56 additions and 0 deletions

1
go.mod
View File

@ -12,6 +12,7 @@ require (
require (
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.17.0 // indirect
github.com/russross/blackfriday v1.6.0
github.com/ulikunitz/xz v0.5.10 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect

2
go.sum
View File

@ -37,6 +37,8 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
github.com/onsi/gomega v1.17.0 h1:9Luw4uT5HTjHTN8+aNcSThgH1vdXnmdJ8xIfZ4wyTRE=
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww=
github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=

View File

@ -5,6 +5,7 @@ import (
"fmt"
"io/ioutil"
"log"
"net/http"
"path/filepath"
"strings"
@ -37,6 +38,23 @@ func NewClient(hostname string, lang string, os string, arch string) (*Client, e
return m, nil
}
func (m *Client) ServeHTTP(rw http.ResponseWriter, rq http.Request) {
path := rq.URL.Path
switch path {
case "/start-tor-browser":
case "/start-i2p-browser":
case "/start-tor":
case "/stop-tor":
default:
b, e := m.Page()
if e != nil {
fmt.Fprintf(rw, "Error: %s", e)
}
rw.Write([]byte(b))
}
rw.Write([]byte("Hello, world!"))
}
func (m *Client) generateMirrorJSON() (map[string]interface{}, error) {
if !strings.HasSuffix(m.hostname, "/") {
m.hostname += "/"

35
serve/template.go Normal file
View File

@ -0,0 +1,35 @@
package tbserve
import (
"io/ioutil"
"path/filepath"
"github.com/russross/blackfriday"
)
var defaultmd []byte = []byte(`
# Tor Binary Manager
This plugin manages the Tor Browser Bundle and a Tor binary
for you. Combined with a SOCKS5 plugin for I2P, it acts as
an alternative to a fixed outproxy by using Tor, and also
provides a way to run I2P in the Tor Browser without any other
configuration.
- [Launch I2P in Tor Browser](/launch-i2p-browser)
- [Launch Tor Browser](/launch-tor-browser)
- [Start Tor](/start-tor)
- [Stop Tor](/stop-tor)
`)
func (m *Client) Page() (string, error) {
dir := filepath.Dir(m.TBD.DownloadPath)
mdpath := filepath.Join(dir, m.TBD.Lang, "index.md")
mdbytes, err := ioutil.ReadFile(mdpath)
if err != nil {
return string(blackfriday.MarkdownCommon(defaultmd)), err
}
htmlbytes := blackfriday.MarkdownCommon(mdbytes)
return string(htmlbytes), nil
}