Skip to content

Commit

Permalink
Support wayback to IPFS
Browse files Browse the repository at this point in the history
  • Loading branch information
WaybackBot committed Jul 4, 2020
1 parent 8381a62 commit ee09b0b
Show file tree
Hide file tree
Showing 9 changed files with 1,140 additions and 100 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ FROM alpine:3.12

LABEL maintainer "WaybackBot <[email protected]>"
COPY --from=builder /wayback /usr/local/bin
RUN apk update && apk add ca-certificates
RUN apk update && apk add ca-certificates tor
RUN mv /etc/tor/torrc.sample /etc/tor/torrc

USER nobody
WORKDIR /usr/local/bin
USER tor
WORKDIR /tmp

ENTRYPOINT ["/usr/local/bin/wayback"]

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ NAME = wayback
BINDIR ?= ./bin
PACKDIR ?= ./build/package
VERSION := $(shell cat VERSION)
GOBUILD := CGO_ENABLED=0 go build --ldflags="-s -w"
GOBUILD := CGO_ENABLED=0 go build --ldflags="-s -w" -v
GOFILES := $(wildcard ./cmd/*.go)
PROJECT := github.com/wabarc/wayback
PACKAGES := $(shell go list ./...)
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ Available Commands:
telegram A CLI tool for wayback webpages on Telegram bot.

Flags:
-h, --help help for wayback
-h, --help help for wayback
--host string IPFS daemon host. (default "127.0.0.1")
--port uint IPFS daemon port. (default 5001)
--tor Saving webpage use tor proxy.

Use "wayback [command] --help" for more information about a command.

Expand Down Expand Up @@ -77,8 +80,8 @@ $ docker run -d wabarc/wayback telegram -t YOUR-BOT-TOKEN -c YOUR-CHANNEL-USERNA

[Archive.org](https://web.archive.org/) and [Archive.today](https://archive.today/) are currently supported, the next step mind support the followings platform:

- [IPFS](https://ipfs.io/)
- [ZeroNet](https://zeronet.io/)
- [x] [IPFS](https://ipfs.io/)
- [ ] [ZeroNet](https://zeronet.io/)

## Telegram bot

Expand Down
7 changes: 7 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (
)

var (
host string
port uint
tor bool

rootCmd = &cobra.Command{
Use: "wayback",
Short: "A CLI tool for wayback webpages.",
Expand All @@ -19,5 +23,8 @@ func main() {
}

func init() {
rootCmd.PersistentFlags().StringVarP(&host, "host", "", "127.0.0.1", "IPFS daemon host.")
rootCmd.PersistentFlags().UintVarP(&port, "port", "", 5001, "IPFS daemon port.")
rootCmd.PersistentFlags().BoolVarP(&tor, "tor", "", false, "Saving webpage use tor proxy.")
rootCmd.AddCommand(telegramCmd)
}
3 changes: 2 additions & 1 deletion cmd/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ var (
os.Exit(0)
}

wbrc := wayback.NewConfig(token, debug, chatid)
ipfs := &wayback.IPFS{Host: host, Port: port, UseTor: tor}
wbrc := wayback.NewConfig(token, debug, chatid, ipfs)

wbrc.Telegram()
},
Expand Down
10 changes: 9 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
package wayback

type IPFS struct {
Host string
Port uint
UseTor bool
}

type Config struct {
Token string
ChatID string
Debug bool
IPFS *IPFS
}

func NewConfig(token string, debug bool, chatid string) *Config {
func NewConfig(token string, debug bool, chatid string, ipfs *IPFS) *Config {
conf := &Config{
Token: token,
ChatID: chatid,
Debug: debug,
IPFS: ipfs,
}

return conf
Expand Down
21 changes: 8 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,17 @@ go 1.14

require (
github.com/andybalholm/cascadia v1.2.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.3.2 // indirect
github.com/pelletier/go-toml v1.8.0 // indirect
github.com/spf13/afero v1.3.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.7.0
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
github.com/wabarc/archive.is v1.0.0
github.com/wabarc/archive.org v1.0.0
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect
github.com/wabarc/archive.is v0.1.0
github.com/wabarc/archive.org v0.1.0
github.com/wabarc/wbipfs v0.0.0-20200704155612-6ac39276732b
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1 // indirect
golang.org/x/text v0.3.3 // indirect
gopkg.in/ini.v1 v1.57.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)

replace github.com/go-shiori/obelisk => github.com/wabarc/obelisk v0.0.0-20200703142927-b75ec5557781
1,159 changes: 1,089 additions & 70 deletions go.sum

Large diffs are not rendered by default.

22 changes: 14 additions & 8 deletions telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package wayback

import (
"bytes"
"github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/wabarc/archive.is/pkg"
"github.com/wabarc/archive.org/pkg"
"log"
"regexp"
"text/template"

"github.com/go-telegram-bot-api/telegram-bot-api"
"github.com/wabarc/archive.is/pkg"
"github.com/wabarc/archive.org/pkg"
"github.com/wabarc/wbipfs"
)

type Message struct {
Archiver []string
URL [][]string
URL []map[string]string
}

const tmpl = `{{range $i, $name := .Archiver}}<b>{{ $name }}</b>:
Expand All @@ -39,6 +41,9 @@ func (cfg *Config) Telegram() {
log.Panic(err)
}

iaWbrc := &ia.Archiver{}
isWbrc := &is.Archiver{}
ipfsWbrc := &wbipfs.Archiver{IPFSHost: cfg.IPFS.Host, IPFSPort: cfg.IPFS.Port, UseTor: cfg.IPFS.UseTor}
for update := range updates {
if update.Message == nil { // ignore any non-Message Updates
continue
Expand All @@ -51,13 +56,14 @@ func (cfg *Config) Telegram() {
for _, el := range match {
url = append(url, el)
}
iaURL := ia.Wayback(url)
isURL := is.Wayback(url)
iaURL, _ := iaWbrc.Wayback(url)
isURL, _ := isWbrc.Wayback(url)
ipfsURL, _ := ipfsWbrc.Wayback(url)

if len(iaURL) > 0 || len(isURL) > 0 {
vars := &Message{
Archiver: []string{"Internet Archive", "archive.today"},
URL: [][]string{iaURL, isURL},
Archiver: []string{"Internet Archive", "archive.today", "IPFS(alpha)"},
URL: []map[string]string{iaURL, isURL, ipfsURL},
}
replyText := message(vars)
msg := tgbotapi.NewMessage(update.Message.Chat.ID, replyText)
Expand Down

0 comments on commit ee09b0b

Please sign in to comment.