From 9c3125d6bec1de1b012d083c56e97607b5796072 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Wed, 13 Dec 2023 23:09:00 +1300 Subject: [PATCH] Minor improvements to archiver --- archiver/archiver-gui.rkt | 36 ++++++++++++++---------------------- archiver/archiver.rkt | 11 +++++++---- lib/mime.types | 2 ++ src/page-static-archive.rkt | 5 ++++- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/archiver/archiver-gui.rkt b/archiver/archiver-gui.rkt index 6f09cb8..a5facae 100644 --- a/archiver/archiver-gui.rkt +++ b/archiver/archiver-gui.rkt @@ -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)) + (button (hash-ref action-icons 'reset) + (λ () (do-reset-qi @qi))) (if-view @is-running? (button (hash-ref action-icons 'pause) (λ () (do-stop-qi @qi))) diff --git a/archiver/archiver.rkt b/archiver/archiver.rkt index 84fd16f..01f03ad 100644 --- a/archiver/archiver.rkt +++ b/archiver/archiver.rkt @@ -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)))]) diff --git a/lib/mime.types b/lib/mime.types index c06a1e9..4ae48d8 100644 --- a/lib/mime.types +++ b/lib/mime.types @@ -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 diff --git a/src/page-static-archive.rkt b/src/page-static-archive.rkt index c0c2e09..501bda7 100644 --- a/src/page-static-archive.rkt +++ b/src/page-static-archive.rkt @@ -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)])])