From f9ec3a4b25a3d177e992cb612e398ab69fa4962d Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Fri, 24 Sep 2021 20:32:37 +0930 Subject: [PATCH 1/7] Create dependabot.yml --- .github/dependabot.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..eb4bfe6 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "gomod" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "daily" From a99f65918fdc62c0ec8b48d31deb391a1fe3e206 Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Sun, 26 Sep 2021 12:33:03 +0930 Subject: [PATCH 2/7] Fix regexp for the "merge" log line --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 8468dca..71dea07 100644 --- a/main.go +++ b/main.go @@ -309,7 +309,7 @@ func updateMetadata(dl *download, s string) { // This means a file has been "created" by merging others // [ffmpeg] Merging formats into "Toto - Africa (Official HD Video)-FTQbiNvZqaY.mp4" - mergedFilename := regexp.MustCompile(`Merging formats into "(.+)$`) + mergedFilename := regexp.MustCompile(`Merging formats into "(.+)"$`) matches = mergedFilename.FindStringSubmatch(s) if len(matches) == 2 { dl.Files = append(dl.Files, matches[1]) From 2c57a77b987da9ea05bc8676fd45a9813f223389 Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Sun, 26 Sep 2021 12:33:31 +0930 Subject: [PATCH 3/7] Make the index page dynamic --- main.go | 10 ++++++++-- web/index.html | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 71dea07..0507d7a 100644 --- a/main.go +++ b/main.go @@ -81,7 +81,8 @@ func main() { r := mux.NewRouter() r.HandleFunc("/", HomeHandler) r.HandleFunc("/fetch", FetchHandler) - r.HandleFunc("/fetch/info/{id}", FetchInfoHandler) + r.HandleFunc("/fetch/info", FetchInfoHandler) + r.HandleFunc("/fetch/info/{id}", FetchInfoOneHandler) http.Handle("/", r) @@ -126,7 +127,7 @@ func HomeHandler(w http.ResponseWriter, r *http.Request) { } -func FetchInfoHandler(w http.ResponseWriter, r *http.Request) { +func FetchInfoOneHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) idString := vars["id"] if idString != "" { @@ -148,6 +149,11 @@ func FetchInfoHandler(w http.ResponseWriter, r *http.Request) { } } +func FetchInfoHandler(w http.ResponseWriter, r *http.Request) { + b, _ := json.Marshal(downloads) + w.Write(b) +} + func FetchHandler(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() diff --git a/web/index.html b/web/index.html index 2b88232..d8047ab 100644 --- a/web/index.html +++ b/web/index.html @@ -6,7 +6,7 @@

-
+
@@ -14,16 +14,21 @@ + + + {{ range $k, $v := .Downloads }} - - - - - - - - - {{ end }}
{{ $v.Id }}{{ range $_, $f := $v.Files }}{{ $f }}
{{ end }}
link{{ $v.State }}{{ $v.Percent }}{{ $v.Eta }}{{ $v.Finished }}
@@ -31,4 +36,19 @@ {{ end }} {{ define "js" }} + {{ end }} \ No newline at end of file From 7c1d11298f9be43926938dcfce38f3eee4869bf9 Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Sun, 26 Sep 2021 12:48:42 +0930 Subject: [PATCH 4/7] Clean up and better error checking --- main.go | 16 ++++++++++++---- web/index.html | 7 +++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 0507d7a..eb188ae 100644 --- a/main.go +++ b/main.go @@ -157,12 +157,21 @@ func FetchInfoHandler(w http.ResponseWriter, r *http.Request) { func FetchHandler(w http.ResponseWriter, r *http.Request) { query := r.URL.Query() - url, present := query["url"] //filters=["color", "price", "brand"] + url, present := query["url"] if !present { - fmt.Fprint(w, "something") + w.WriteHeader(400) + fmt.Fprint(w, "No url supplied") + return } else { + // check the URL for a sudden but inevitable betrayal + if strings.Contains(url[0], address) { + w.WriteHeader(400) + fmt.Fprint(w, "you musn't gropple your gropple :-)") + return + } + // create the record // XXX should be atomic! downloadId++ @@ -183,6 +192,7 @@ func FetchHandler(w http.ResponseWriter, r *http.Request) { go func() { queue(&newDownload) }() + t, err := template.ParseFS(webFS, "web/layout.tmpl", "web/popup.html") if err != nil { panic(err) @@ -191,8 +201,6 @@ func FetchHandler(w http.ResponseWriter, r *http.Request) { if err != nil { panic(err) } - - // fmt.Fprintf(w, "Started DL %d!", downloadId) } } diff --git a/web/index.html b/web/index.html index d8047ab..33c6a15 100644 --- a/web/index.html +++ b/web/index.html @@ -18,7 +18,7 @@ - + link @@ -44,7 +44,10 @@ fetch('/fetch/info') .then(response => response.json()) .then(info => { - this.items = info; + // will be null if no downloads yet + if (info) { + this.items = info; + } setTimeout(() => { this.fetch_data() }, 1000); }) }, From 648b9ad8862586fce96fc94a72727570db7be830 Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Sun, 26 Sep 2021 12:49:08 +0930 Subject: [PATCH 5/7] Bump version --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index eb188ae..471e368 100644 --- a/main.go +++ b/main.go @@ -50,7 +50,7 @@ var defaultArgs = args{ "--newline", } -const currentVersion = "v0.03" +const currentVersion = "v0.04" //go:embed web var webFS embed.FS From 7b9620631e356a33a0ef3e5bc8c989a08f95a1ef Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Sun, 26 Sep 2021 21:13:33 +0930 Subject: [PATCH 6/7] Version check and upgrade prompt. --- build_release.pl | 3 ++- go.mod | 5 ++++- go.sum | 13 +++++++++++++ main.go | 22 ++++++++++++++++++++-- web/index.html | 40 ++++++++++++++++++++++++++++++++-------- web/layout.tmpl | 7 +++++++ 6 files changed, 78 insertions(+), 12 deletions(-) diff --git a/build_release.pl b/build_release.pl index 6812b6b..d93f764 100755 --- a/build_release.pl +++ b/build_release.pl @@ -7,7 +7,8 @@ open my $fh, "<", "main.go" || die $!; my $version; while (<$fh>) { - $version = $1 if /^const\s+currentVersion.*?"(v[\d\.]+)"/; + # CurrentVersion: "v0.04" + $version = $1 if /CurrentVersion:\s*"(v[\d\.]+)"/; } close $fh; diff --git a/go.mod b/go.mod index 21cef81..61627a6 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,7 @@ module github.com/tardisx/gropple go 1.16 -require github.com/gorilla/mux v1.8.0 +require ( + github.com/gorilla/mux v1.8.0 + golang.org/x/mod v0.5.1 +) diff --git a/go.sum b/go.sum index 5350288..78fad6d 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,15 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38= +golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/main.go b/main.go index 471e368..c538e31 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ import ( "strconv" "github.com/gorilla/mux" + "github.com/tardisx/gropple/version" ) type download struct { @@ -50,7 +51,7 @@ var defaultArgs = args{ "--newline", } -const currentVersion = "v0.04" +var versionInfo = version.Info{CurrentVersion: "v0.4.0"} //go:embed web var webFS embed.FS @@ -83,6 +84,7 @@ func main() { r.HandleFunc("/fetch", FetchHandler) r.HandleFunc("/fetch/info", FetchInfoHandler) r.HandleFunc("/fetch/info/{id}", FetchInfoOneHandler) + r.HandleFunc("/version", VersionHandler) http.Handle("/", r) @@ -94,10 +96,26 @@ func main() { ReadTimeout: 5 * time.Second, } - log.Printf("starting gropple %s - https://github.com/tardisx/gropple", currentVersion) + // check for a new version every 4 hours + go func() { + for { + versionInfo.UpdateGitHubVersion() + time.Sleep(time.Hour * 4) + } + }() + + log.Printf("starting gropple %s - https://github.com/tardisx/gropple", versionInfo.CurrentVersion) log.Printf("go to %s for details on installing the bookmarklet and to check status", address) log.Fatal(srv.ListenAndServe()) +} +func VersionHandler(w http.ResponseWriter, r *http.Request) { + if versionInfo.GithubVersionFetched { + b, _ := json.Marshal(versionInfo) + w.Write(b) + } else { + w.WriteHeader(400) + } } func HomeHandler(w http.ResponseWriter, r *http.Request) { diff --git a/web/index.html b/web/index.html index 33c6a15..2aa693f 100644 --- a/web/index.html +++ b/web/index.html @@ -1,12 +1,24 @@ {{ define "content" }} -
-

- Drag this bookmarklet: Gropple to your bookmark bar, and click it - on any page you want to grab the video from. -

-
-
+ +
+ +

gropple

+ +

+ Upgrade is available - + you have + and + + is available.

+ +
+

+ Drag this bookmarklet: Gropple to your bookmark bar, and click it + on any page you want to grab the video from. +

+
+ @@ -39,7 +51,19 @@