Skip to content

Commit 37afe13

Browse files
Add privacy policy notes (#699)
* Add privacy policy notes * Improve layout * Rename privacy url * Sets command for telegram bot * Privacy URL configurable for web * Optional privacy URL * CSS autoprefixer * Update changelog.md * Fix linter
1 parent 3af8341 commit 37afe13

File tree

16 files changed

+236
-68
lines changed

16 files changed

+236
-68
lines changed

config/config_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,3 +3273,39 @@ func TestProxy(t *testing.T) {
32733273
})
32743274
}
32753275
}
3276+
3277+
func TestPrivacyURL(t *testing.T) {
3278+
t.Parallel()
3279+
3280+
var tests = []struct {
3281+
url string
3282+
expected string
3283+
}{
3284+
{
3285+
url: "",
3286+
expected: defPrivacyURL,
3287+
},
3288+
{
3289+
url: "http://127.0.0.1",
3290+
expected: `http://127.0.0.1`,
3291+
},
3292+
}
3293+
3294+
for i, test := range tests {
3295+
t.Run(strconv.Itoa(i), func(t *testing.T) {
3296+
os.Clearenv()
3297+
os.Setenv("WAYBACK_PRIVACY_URL", test.url)
3298+
3299+
parser := NewParser()
3300+
opts, err := parser.ParseEnvironmentVariables()
3301+
if err != nil {
3302+
t.Fatalf(`Parsing environment variables failed: %v`, err)
3303+
}
3304+
3305+
got := opts.PrivacyURL()
3306+
if got != test.expected {
3307+
t.Fatalf(`Unexpected get privacy url, got %s instead of %s`, got, test.expected)
3308+
}
3309+
})
3310+
}
3311+
}

config/options.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ const (
105105

106106
defOmnivoreApikey = ""
107107

108+
defPrivacyURL = ""
109+
108110
maxAttachSizeTelegram = 50000000 // 50MB
109111
maxAttachSizeDiscord = 8000000 // 8MB
110112
maxAttachSizeSlack = 5000000000 // 5GB
@@ -138,14 +140,15 @@ type Options struct {
138140
matrix *matrix
139141
slack *slack
140142
services sync.Map
141-
maxMediaSize string
143+
privacyURL string
142144
storageDir string
143145
waybackUserAgent string
144146
proxy string
145147
logLevel string
146148
listenAddr string
147149
chromeRemoteAddr string
148150
boltPathname string
151+
maxMediaSize string
149152
poolingSize int
150153
waybackTimeout int
151154
waybackMaxRetries int
@@ -272,6 +275,7 @@ func NewOptions() *Options {
272275
poolingSize: defPoolingSize,
273276
storageDir: defStorageDir,
274277
maxMediaSize: defMaxMediaSize,
278+
privacyURL: defPrivacyURL,
275279
waybackTimeout: defWaybackTimeout,
276280
waybackMaxRetries: defWaybackMaxRetries,
277281
waybackUserAgent: defWaybackUserAgent,
@@ -979,3 +983,8 @@ func (o *Options) HTTPdEnabled() bool {
979983
func (o *Options) Proxy() string {
980984
return o.proxy
981985
}
986+
987+
// PrivacyURL returns the privacy policy URL.
988+
func (o *Options) PrivacyURL() string {
989+
return o.privacyURL
990+
}

config/parser.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ func (p *Parser) parseLines(lines []string) (err error) {
229229
p.opts.meili.apikey = parseString(val, defMeiliApikey)
230230
case "WAYBACK_OMNIVORE_APIKEY":
231231
p.opts.omnivore.apikey = parseString(val, defOmnivoreApikey)
232+
case "WAYBACK_PRIVACY_URL":
233+
p.opts.privacyURL = parseString(val, defPrivacyURL)
232234
default:
233235
if os.Getenv(key) == "" && val != "" {
234236
os.Setenv(key, val)

docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111
- Add support for placing ipfs variables
1212
- Add support publish to Omnivore
13+
- Add privacy notes ([#669](https://github.com/wabarc/wayback/pull/669))
1314

1415
### Changed
1516
- Do not upload files to anonfiles

docs/environment.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,4 @@ Use the `-c` / `--config` option to specify the build definition file to use.
100100
| - | `WAYBACK_SLOT` | - | Pinning service for IPFS mode of pinner, see [ipfs-pinner](https://github.com/wabarc/ipfs-pinner#supported-pinning-services) |
101101
| - | `WAYBACK_APIKEY` | - | API key for pinning service |
102102
| - | `WAYBACK_SECRET` | - | API secret for pinning service |
103+
| - | `WAYBACK_PRIVACY_URL` | - | Privacy policy URL |

service/discord/discord.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package discord // import "github.com/wabarc/wayback/service/discord"
77
import (
88
"context"
99
"encoding/base64"
10+
"fmt"
1011
"net/url"
1112
"strconv"
1213
"strings"
@@ -166,7 +167,7 @@ func (d *Discord) Shutdown() error {
166167

167168
func (d *Discord) commandHandlers() map[string]func(*discord.Session, *discord.InteractionCreate) {
168169
return map[string]func(s *discord.Session, i *discord.InteractionCreate){
169-
"help": func(s *discord.Session, i *discord.InteractionCreate) {
170+
service.CommandHelp: func(s *discord.Session, i *discord.InteractionCreate) {
170171
// nolint:errcheck
171172
s.InteractionRespond(i.Interaction, &discord.InteractionResponse{
172173
Type: discord.InteractionResponseChannelMessageWithSource,
@@ -175,10 +176,10 @@ func (d *Discord) commandHandlers() map[string]func(*discord.Session, *discord.I
175176
},
176177
})
177178
},
178-
"playback": func(s *discord.Session, i *discord.InteractionCreate) {
179+
service.CommandPlayback: func(s *discord.Session, i *discord.InteractionCreate) {
179180
d.playback(s, i) // nolint:errcheck
180181
},
181-
"metrics": func(s *discord.Session, i *discord.InteractionCreate) {
182+
service.CommandMetrics: func(s *discord.Session, i *discord.InteractionCreate) {
182183
stats := metrics.Gather.Export("wayback")
183184
if !d.opts.EnabledMetrics() || stats == "" {
184185
return
@@ -191,12 +192,21 @@ func (d *Discord) commandHandlers() map[string]func(*discord.Session, *discord.I
191192
},
192193
})
193194
},
195+
service.CommandPrivacy: func(s *discord.Session, i *discord.InteractionCreate) {
196+
// nolint:errcheck
197+
s.InteractionRespond(i.Interaction, &discord.InteractionResponse{
198+
Type: discord.InteractionResponseChannelMessageWithSource,
199+
Data: &discord.InteractionResponseData{
200+
Content: fmt.Sprintf("To read our privacy policy, please visit %s.", d.opts.PrivacyURL()),
201+
},
202+
})
203+
},
194204
}
195205
}
196206

197207
func (d *Discord) buttonHandlers() map[string]func(*discord.Session, *discord.InteractionCreate) {
198208
return map[string]func(s *discord.Session, i *discord.InteractionCreate){
199-
"playback": func(s *discord.Session, i *discord.InteractionCreate) {
209+
service.CommandPlayback: func(s *discord.Session, i *discord.InteractionCreate) {
200210
id, err := strconv.Atoi(i.MessageComponentData().CustomID)
201211
if err != nil {
202212
logger.Warn("invalid playback id: %s", i.MessageComponentData().CustomID)
@@ -439,18 +449,24 @@ func (d *Discord) setCommands(guild string) (err error) {
439449
func (d *Discord) requires() (commands []*discord.ApplicationCommand) {
440450
if d.opts.DiscordHelptext() != "" {
441451
commands = append(commands, &discord.ApplicationCommand{
442-
Name: "help",
452+
Name: service.CommandHelp,
443453
Description: "Show help information",
444454
})
445455
}
446456
if d.opts.EnabledMetrics() {
447457
commands = append(commands, &discord.ApplicationCommand{
448-
Name: "metrics",
458+
Name: service.CommandMetrics,
449459
Description: "Show service metrics",
450460
})
451461
}
462+
if d.opts.PrivacyURL() != "" {
463+
commands = append(commands, &discord.ApplicationCommand{
464+
Name: service.CommandPrivacy,
465+
Description: "Read our privacy policy",
466+
})
467+
}
452468
commands = append(commands, &discord.ApplicationCommand{
453-
Name: "playback",
469+
Name: service.CommandPlayback,
454470
Description: "Playback archived url",
455471
Options: []*discord.ApplicationCommandOption{
456472
{

service/httpd/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func newWeb(ctx context.Context, opts *config.Options, pool *pooling.Pool, pub *
4646
opts: opts,
4747
pool: pool,
4848
router: router,
49-
template: template.New(router),
49+
template: template.New(router, opts),
5050
}
5151
if err := web.template.ParseTemplates(); err != nil {
5252
logger.Fatal("unable to parse templates: %v", err)

service/relaychat/relaychat.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package relaychat // import "github.com/wabarc/wayback/service/relaychat"
77
import (
88
"context"
99
"crypto/tls"
10+
"fmt"
1011
"net/url"
1112
"strings"
1213
"sync"
@@ -174,6 +175,9 @@ func (i *IRC) process(m *irc.Message) error {
174175
case strings.HasPrefix(text, service.CommandPlayback):
175176
return i.playback(m, urls)
176177

178+
case strings.HasPrefix(text, service.CommandPrivacy):
179+
return i.reply(m.Name, i.privacy()...)
180+
177181
default:
178182
metrics.IncrementWayback(metrics.ServiceIRC, metrics.StatusRequest)
179183
i.reply(m.Name, "I'll help you archive the URL and return the results promptly.") // nolint:errcheck
@@ -264,3 +268,9 @@ func (i *IRC) helper() []string {
264268
"***** End of Help *****",
265269
}
266270
}
271+
272+
func (i *IRC) privacy() []string {
273+
return []string{
274+
fmt.Sprintf("To read our privacy policy, please visit %s.", i.opts.PrivacyURL()),
275+
}
276+
}

service/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
CommandHelp = "help"
2222
CommandMetrics = "metrics"
2323
CommandPlayback = "playback"
24+
CommandPrivacy = "privacy"
2425

2526
MsgWaybackRetrying = "wayback timeout, retrying."
2627
MsgWaybackTimeout = "wayback timeout, please try later."

service/slack/slack.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ package slack // import "github.com/wabarc/wayback/service/slack"
66

77
import (
88
"context"
9+
"fmt"
910
"net/url"
11+
"strings"
1012

1113
"github.com/gookit/color"
1214
"github.com/slack-go/slack"
@@ -225,8 +227,8 @@ func (s *Slack) handleCommand(evt socketmode.Event) {
225227
logger.Debug("slash command received: %+v", cmd)
226228

227229
var payload interface{}
228-
switch cmd.Command {
229-
case "/help":
230+
switch strings.TrimPrefix(cmd.Command, "/") {
231+
case service.CommandHelp:
230232
payload = map[string]interface{}{
231233
"blocks": []slack.Block{
232234
slack.NewSectionBlock(
@@ -237,7 +239,7 @@ func (s *Slack) handleCommand(evt socketmode.Event) {
237239
nil, nil,
238240
),
239241
}}
240-
case "/metrics":
242+
case service.CommandMetrics:
241243
stats := metrics.Gather.Export("wayback")
242244
if s.opts.EnabledMetrics() && stats != "" {
243245
payload = map[string]interface{}{
@@ -251,9 +253,20 @@ func (s *Slack) handleCommand(evt socketmode.Event) {
251253
),
252254
}}
253255
}
254-
case "/playback":
256+
case service.CommandPlayback:
255257
// nolint:errcheck
256258
s.playback(cmd.ChannelID, cmd.Text, cmd.TriggerID)
259+
case service.CommandPrivacy:
260+
payload = map[string]interface{}{
261+
"blocks": []slack.Block{
262+
slack.NewSectionBlock(
263+
&slack.TextBlockObject{
264+
Type: slack.PlainTextType,
265+
Text: fmt.Sprintf("To read our privacy policy, please visit %s.", s.opts.PrivacyURL()),
266+
},
267+
nil, nil,
268+
),
269+
}}
257270
default:
258271
}
259272
s.client.Ack(*evt.Request, payload)

0 commit comments

Comments
 (0)