diff --git a/src/page-file.rkt b/src/page-file.rkt index 962144e..dfd3024 100644 --- a/src/page-file.rkt +++ b/src/page-file.rkt @@ -28,6 +28,30 @@ ; (define category-json-data ; '#hasheq((batchcomplete . #t) (continue . #hasheq((cmcontinue . "page|4150504c45|41473") (continue . "-||"))) (query . #hasheq((categorymembers . (#hasheq((ns . 0) (pageid . 25049) (title . "Item (entity)")) #hasheq((ns . 0) (pageid . 128911) (title . "3D")) #hasheq((ns . 0) (pageid . 124018) (title . "A Very Fine Item")) #hasheq((ns . 0) (pageid . 142208) (title . "Amethyst Shard")) #hasheq((ns . 0) (pageid . 121612) (title . "Ankle Monitor"))))))))) +(define (html-from-url image-url) + ([media-detail (define dest-url + (format "~a/wikia.php?~a" + origin + (params->query `(("format" . "json") + ("controller" . "Lightbox") + ("method" . "getMediaDetail") + ("fileTitle" . ,prefixed-title))))) + (log-outgoing dest-url) + (define dest-res (easy:get dest-url #:timeouts timeouts)) + (easy:response-json dest-res)] + (log-outgoing image-url) + (define dest-res (easy:head image-url #:timeouts timeouts)) + (define content-type (response-headers-ref dest-res "Content-Type")) + (cond + [(eq? content-type #f) ""] + [(regexp-match? #rx"^image/" content-type) + (img (@ (src ,(u-proxy-url image-url))))] + [(regexp-match? #rx"^audio/" content-type) + (audio (@ (src ,(u-proxy-url image-url)) (controls)))] + [(regexp-match? #rx"^video/" content-type) + (video (@ (src ,(u-proxy-url image-url)) (controls)))] + [else ""])) + (define (generate-results-page #:source-url source-url #:wikiname wikiname @@ -42,16 +66,22 @@ (define smaller-article-list (jp "/smallerArticleList" media-detail)) (define article-list-is-smaller (jp "/articleListIsSmaller" media-detail)) (define image-description (jp "/imageDescription" media-detail #f)) + (define maybe-proxied-raw-image-url (if (config-true? 'strict_proxy) + (u-proxy-url raw-image-url) + raw-image-url)) (generate-wiki-page #:source-url source-url #:wikiname wikiname #:title title #:license license `(div + ,(if (non-empty-string? video-embed-code) + (update-tree-wiki (html->xexp (preprocess-html-wiki video-embed-code)) wikiname) + `(html-from-url image-url)) (p ,(if (non-empty-string? video-embed-code) `"" - `(span (a (@ (href ,(u-proxy-url raw-image-url))) "View original file") ". ")) + `(span (a (@ (href ,maybe-proxied-raw-image-url)) "View original file") ". ")) "Added by " (a (@ (href ,(format "/~a/wiki/User:~a" wikiname username))) ,username) "."