Minor improvements to archiver

This commit is contained in:
Cadence Ember 2023-12-13 23:09:00 +13:00
parent a57445abcb
commit 9c3125d6be
Signed by untrusted user: cadence
GPG key ID: BC1C2C61CF521B17
4 changed files with 27 additions and 27 deletions

View file

@ -90,27 +90,21 @@
(define/obs @input "")
(splicing-let ([frame-count 30])
(splicing-let ([frame-count 20])
(define stickman-frames
(for/vector ([s (in-range 0 1 (/ 1 frame-count))])
(running-stickman-icon
s
#:height status-icon-size
#:material (default-icon-material))))
#:material (default-icon-material)))))
(define/obs @stick-frame-no 0)
(define stick-timer
(new timer%
[notify-callback (λ () (@stick-frame-no . <~ . add1))]
[interval (truncate (/ 1000 frame-count))]))
(define/obs @stick
(@stick-frame-no . ~> . (λ (n) (vector-ref stickman-frames
(modulo n (vector-length stickman-frames)))))))
(define (stick n)
(vector-ref stickman-frames (modulo n (vector-length stickman-frames))))
(define status-icons
(hasheq 'queued (stop-icon #:color syntax-icon-color #:height status-icon-size)
'paused (continue-forward-icon #:color syntax-icon-color #:height status-icon-size)
'running @stick
'running (stick 0)
'error (x-icon #:height status-icon-size)
'complete (check-icon #:color color-green #:height status-icon-size)))
@ -155,7 +149,7 @@
#:mixin (λ (%) (class % (super-new)
(obs-observe! @visible? (λ (visible?) (send this show visible?)))))
(vpanel #:margin '(15 15)
(text "Encountered this error while downloading:")
(text (format "Encountered this error while downloading ~a:" (qi^-wikiname (obs-peek @qi))))
(input #:style '(multiple hscroll)
#:min-size '(#f 200)
(exn->string e))
@ -259,15 +253,16 @@
(update-qi @qi [th #f] [st 'paused]))
(define (do-reset-qi @qi)
(define reset-progress-to 0)
(define th (qi^-th (obs-peek @qi)))
(when th (kill-thread th))
(update-qi @qi [th #f] [st 'queued] [stage 0] [progress 0] [max-progress 0])
(query-exec* "update wiki set progress = 0 where wikiname = ?" (qi^-wikiname (obs-peek @qi))))
(update-qi @qi [th #f] [st 'queued] [stage reset-progress-to] [progress 0] [max-progress 0])
(query-exec* "update wiki set progress = ? where wikiname = ?" reset-progress-to (qi^-wikiname (obs-peek @qi))))
(define (do-try-unpause-next-entry)
(define queue (obs-peek @queue))
(define next-qi (for/first ([qi queue]
#:when (memq (qi^-st qi) '(paused queued error)))
(define next-qi (for/last ([qi queue]
#:when (memq (qi^-st qi) '(paused queued)))
qi))
(when next-qi
(define @qi (@queue . ~> . (λ (queue) (findf (λ (qi) (equal? (qi^-wikiname qi) (qi^-wikiname next-qi))) queue))))
@ -281,7 +276,6 @@
#:mixin (λ (%) (class %
(super-new)
(define/augment (on-close)
(send stick-timer stop)
(for ([qi (obs-peek @queue)])
(when (qi^-th qi)
(kill-thread (qi^-th qi))))
@ -307,7 +301,7 @@
(λ (k @qi)
(define @status-icons
(@> (case (qi^-st @qi)
[(running) @stick]
[(running) (stick (qi^-progress @qi))]
[else (hash-ref status-icons (qi^-st @qi))])))
(define @is-running?
(@> (memq (qi^-st @qi) '(running))))
@ -325,10 +319,8 @@
(spacer)
(hpanel
#:stretch '(#f #f)
(if-view @is-complete?
(button (hash-ref action-icons 'reset)
(λ () (do-reset-qi @qi)))
(spacer))
(if-view @is-running?
(button (hash-ref action-icons 'pause)
(λ () (do-stop-qi @qi)))

View file

@ -86,14 +86,17 @@
(string-contains? url "/drm_fonts/")
(string-contains? url "//db.onlinewebfonts.com/")
(string-contains? url "//bits.wikimedia.org/")
(string-contains? url "mygamercard.net/")
(string-contains? url "dropbox")
(string-contains? url "only=styles")
(string-contains? url "https://https://")
(regexp-match? #rx"^%20" url)
(regexp-match? #rx"^data:" url))))
(regexp-match? #rx"^data:" url)
(regexp-match? #rx"^file:" url))))
(cond
[(string-prefix? url "https://") url]
[(string-prefix? url "http://") (regexp-replace #rx"http:" url "https:")]
[(string-prefix? url "httpshttps://") (regexp-replace #rx"httpshttps://" url "https://")]
[(string-prefix? url "//") (string-append "https:" url)]
[(string-prefix? url "/") (format "https://~a.fandom.com~a" wikiname url)]
[else (raise-user-error "While calling check-style-for-images, this URL had an unknown format and couldn't be saved:" url path)])))
@ -244,7 +247,7 @@
;; save redirects as well
(save-redirects wikiname callback (+ already-done-count (length basenames)) total-count)
;; saved all pages, register that fact in the database
(query-exec* "update wiki set progress = 2 where wikiname = ?" wikiname))
(query-exec* "update wiki set progress = 2 where wikiname = ? and progress <= 2" wikiname))
;; 2.5. Download each redirect-target via API and save mapping in database
@ -334,8 +337,8 @@
(define url (vector-ref row 0))
(define hash (vector-ref row 1))
;; check
#; (printf "~a -> ~a~n" url hash)
(define r (get url))
#;(printf "~a -> ~a~n" url hash)
(define r (get url #:timeouts (make-timeout-config #:connect 15)))
(define declared-type (response-headers-ref r 'content-type))
(define final-type (if (equal? declared-type #"application/octet-stream")
(let ([sniff-entity (message-entity (mime-analyze (response-body r)))])

View file

@ -22,6 +22,7 @@ image/x-jng jng
image/x-ms-bmp bmp
image/svg+xml svg
image/webp webp
image/avif avif
application/font-woff2 woff2
application/acad woff2
@ -31,6 +32,7 @@ font/woff woff
application/x-font-ttf ttf
application/x-font-truetype ttf
application/x-truetype-font ttf
font/ttf ttf
application/font-sfnt ttf
font/sfnt ttf
application/vnd.oasis.opendocument.formula-template otf

View file

@ -30,16 +30,19 @@
(string-contains? url "/drm_fonts/")
(string-contains? url "//db.onlinewebfonts.com/")
(string-contains? url "//bits.wikimedia.org/")
(string-contains? url "mygamercard.net/")
(string-contains? url "dropbox")
(string-contains? url "only=styles")
(string-contains? url "https://https://")
(regexp-match? #rx"^%20|^'" url)
(regexp-match? #rx"^\"?data:" url))
(regexp-match? #rx"^\"?data:" url)
(regexp-match? #rx"^file:" url))
url
(let* ([norm-url
(cond
[(string-prefix? url "https://") url]
[(string-prefix? url "http://") (regexp-replace #rx"http:" url "https:")]
[(string-prefix? url "httpshttps://") (regexp-replace #rx"httpshttps://" url "https://")]
[(string-prefix? url "//") (string-append "https:" url)]
[(string-prefix? url "/") (format "https://~a.fandom.com~a" wikiname url)]
[else (error 'replace-style-for-images "unknown URL format: ~a" url)])])