From 0148c1c3f922e7a76e4e4d237405cb3d0f956700 Mon Sep 17 00:00:00 2001 From: blankie Date: Sat, 8 Oct 2022 15:42:00 +0700 Subject: [PATCH] idfk --- src/page-file.rkt | 66 ++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/src/page-file.rkt b/src/page-file.rkt index 24dd5ae..608e9c8 100644 --- a/src/page-file.rkt +++ b/src/page-file.rkt @@ -72,41 +72,43 @@ )) (define (page-file req) - (response-handler - (define wikiname (path/param-path (first (url-path (request-uri req))))) - (define prefixed-title (path/param-path (caddr (url-path (request-uri req))))) - (define origin (format "https://~a.fandom.com" wikiname)) - (define source-url (format "~a/wiki/~a" origin prefixed-title)) + (define wikiname (path/param-path (first (url-path (request-uri req))))) + (define prefixed-title (path/param-path (caddr (url-path (request-uri req))))) + (define origin (format "https://~a.fandom.com" wikiname)) + (define source-url (format "~a/wiki/~a" origin prefixed-title)) - (thread-let - ([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)] - [license (license-auto wikiname)]) + (thread-let + ([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)] + [license (license-auto wikiname)]) - (define title (jp "/fileTitle" page-data media-detail))) - (define body (generate-results-page - #:source-url source-url - #:wikiname wikiname - #:title title - #:media-detail media-detail - #:license license)) + (if (not (jp "/exists" media-detail #f)) + (next-dispatcher) + (response-handler + (define title (jp "/fileTitle" media-detail))) + (define body (generate-results-page + #:source-url source-url + #:wikiname wikiname + #:title title + #:media-detail media-detail + #:license license)) - (when (config-true? 'debug) - ; used for its side effects - ; convert to string with error checking, error will be raised if xexp is invalid - (xexp->html body)) - (response/output - #:code 200 - (λ (out) - (write-html body out)))))) + (when (config-true? 'debug) + ; used for its side effects + ; convert to string with error checking, error will be raised if xexp is invalid + (xexp->html body)) + (response/output + #:code 200 + (λ (out) + (write-html body out)))))) ;(module+ test ; (check-not-false ((query-selector (attribute-selector 'href "/test/wiki/Ankle_Monitor") ; (generate-results-page