From e845cc460b644d40ea1a69e89912de8a2a13fc21 Mon Sep 17 00:00:00 2001 From: blankie Date: Sat, 8 Oct 2022 23:14:02 +0700 Subject: [PATCH] content-type --- src/page-file.rkt | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/page-file.rkt b/src/page-file.rkt index 4348740..7db138d 100644 --- a/src/page-file.rkt +++ b/src/page-file.rkt @@ -28,18 +28,20 @@ ; (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) +(define (url-content-type url) (log-outgoing image-url) (define dest-res (easy:head image-url #:timeouts timeouts)) - (define content-type (easy:response-headers-ref dest-res 'Content-Type)) + (easy:response-headers-ref dest-res 'Content-Type)) + +(define (get-media-html url content-type) (cond [(eq? content-type #f) `""] [(regexp-match? #rx"^image/" content-type) - `(img (@ (src ,(u-proxy-url image-url))))] + `(img (@ (src ,(u-proxy-url url))))] [(regexp-match? #rx"^audio/|^application/ogg$" content-type) - `(audio (@ (src ,(u-proxy-url image-url)) (controls)))] + `(audio (@ (src ,(u-proxy-url url)) (controls)))] [(regexp-match? #rx"^video/" content-type) - `(video (@ (src ,(u-proxy-url image-url)) (controls)))] + `(video (@ (src ,(u-proxy-url url)) (controls)))] [else `""])) (define (generate-results-page @@ -47,6 +49,7 @@ #:wikiname wikiname #:title title #:media-detail media-detail + #:image-content-type image-content-type #:license [license #f]) (define video-embed-code (jp "/videoEmbedCode" media-detail "")) (define raw-image-url (jp "/rawImageUrl" media-detail)) @@ -67,7 +70,7 @@ `(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)) + (get-media-html image-url image-content-type)) (p ,(if (non-empty-string? video-embed-code) `"" @@ -122,11 +125,15 @@ (define title (if (non-empty-string? file-title) (format "File:~a" file-title) prefixed-title)) + (define image-content-type (if (non-empty-string? (jp "/videoEmbedCode" media-detail "")) + #f + (url-content-type (jp "/imageUrl" media-detail)))) (define body (generate-results-page #:source-url source-url #:wikiname wikiname #:title title #:media-detail media-detail + #:image-content-type image-content-type #:license license)) (when (config-true? 'debug)