Skip to content

Commit 515e065

Browse files
committed
Added --anyways/-a flag for forcing archival even when there is a recent snapshot.
1 parent 4a89ba9 commit 515e065

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

capture.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var (
2727

2828
// Config settings for page capture client behavior.
2929
type Config struct {
30+
Anyway bool // Force archival even if there is already a recent snapshot of the page.
3031
Wait bool // Wait until the crawl has been completed.
3132
WaitTimeout time.Duration // Max time to wait for crawl completion. Default is unlimited.
3233
PollInterval time.Duration // Interval between crawl completion checks. Defaults to 5s.
@@ -43,6 +44,7 @@ func Capture(u string, cfg ...Config) (string, error) {
4344

4445
var (
4546
submitID string
47+
anyway string
4648
body []byte
4749
resp *http.Response
4850
final string
@@ -56,7 +58,11 @@ func Capture(u string, cfg ...Config) (string, error) {
5658
return "", err
5759
}
5860

59-
content := fmt.Sprintf("submitid=%v&url=%v", url.QueryEscape(submitID), url.QueryEscape(u))
61+
if len(cfg) > 0 && cfg[0].Anyway {
62+
anyway = "&anyway=1"
63+
}
64+
65+
content := fmt.Sprintf("submitid=%v&url=%v%v", url.QueryEscape(submitID), url.QueryEscape(u), anyway)
6066

6167
resp, body, err = doRequest("POST", BaseURL+"/submit/", ioutil.NopCloser(bytes.NewBufferString(content)), timeout)
6268
if err != nil {

cmd/archive.is/main.go

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var (
1717
RequestTimeout time.Duration = archiveis.DefaultRequestTimeout
1818
PollInterval time.Duration = archiveis.DefaultPollInterval
1919
WaitTimeout time.Duration = time.Duration(0)
20+
Anyway bool
2021
submitID string
2122
)
2223

@@ -27,6 +28,7 @@ func init() {
2728
rootCmd.PersistentFlags().DurationVarP(&RequestTimeout, "request-timeout", "r", RequestTimeout, "Timeout duration for HTTP requests")
2829
rootCmd.PersistentFlags().DurationVarP(&PollInterval, "poll-interval", "p", PollInterval, "Poll interval, only applies when -w/--wait is active")
2930
rootCmd.PersistentFlags().DurationVarP(&WaitTimeout, "wait-timeout", "", WaitTimeout, "Maximum wait duration, only applies when -w/--wait is active (default: infinite)")
31+
rootCmd.PersistentFlags().BoolVarP(&Anyway, "anyway", "a", false, "Force archival even if there is already a recent snapshot of the page")
3032
rootCmd.PersistentFlags().StringVarP(&archiveis.BaseURL, "base-url", "b", archiveis.BaseURL, "Archive.is server base URL address")
3133
rootCmd.PersistentFlags().StringVarP(&archiveis.HTTPHost, "http-host", "", archiveis.HTTPHost, "'Host' header to use")
3234
rootCmd.PersistentFlags().StringVarP(&archiveis.UserAgent, "user-agent", "u", archiveis.UserAgent, "'User-Agent' header to use")
@@ -49,6 +51,7 @@ var rootCmd = &cobra.Command{
4951
},
5052
Run: func(cmd *cobra.Command, args []string) {
5153
cfg := archiveis.Config{
54+
Anyway: Anyway,
5255
Wait: Wait,
5356
SubmitID: submitID,
5457
}

0 commit comments

Comments
 (0)