forked from cadence/breezewiki
raco fmt
This commit is contained in:
parent
1a996e7c89
commit
51bf087b30
1 changed files with 66 additions and 84 deletions
|
@ -20,8 +20,7 @@
|
||||||
"url-utils.rkt"
|
"url-utils.rkt"
|
||||||
"xexpr-utils.rkt")
|
"xexpr-utils.rkt")
|
||||||
|
|
||||||
(provide
|
(provide page-file)
|
||||||
page-file)
|
|
||||||
|
|
||||||
;(module+ test
|
;(module+ test
|
||||||
; (require rackunit)
|
; (require rackunit)
|
||||||
|
@ -36,21 +35,18 @@
|
||||||
(define (get-media-html url content-type)
|
(define (get-media-html url content-type)
|
||||||
(cond
|
(cond
|
||||||
[(eq? content-type #f) `""]
|
[(eq? content-type #f) `""]
|
||||||
[(regexp-match? #rx"(?i:^image/)" content-type)
|
[(regexp-match? #rx"(?i:^image/)" content-type) `(img (@ (src ,url)))]
|
||||||
`(img (@ (src ,url)))]
|
|
||||||
[(regexp-match? #rx"(?i:^audio/|^application/ogg(;|$))" content-type)
|
[(regexp-match? #rx"(?i:^audio/|^application/ogg(;|$))" content-type)
|
||||||
`(audio (@ (src ,url) (controls)))]
|
`(audio (@ (src ,url) (controls)))]
|
||||||
[(regexp-match? #rx"(?i:^video/)" content-type)
|
[(regexp-match? #rx"(?i:^video/)" content-type) `(video (@ (src ,url) (controls)))]
|
||||||
`(video (@ (src ,url) (controls)))]
|
|
||||||
[else `""]))
|
[else `""]))
|
||||||
|
|
||||||
(define (generate-results-page
|
(define (generate-results-page #:source-url source-url
|
||||||
#:source-url source-url
|
#:wikiname wikiname
|
||||||
#:wikiname wikiname
|
#:title title
|
||||||
#:title title
|
#:media-detail media-detail
|
||||||
#:media-detail media-detail
|
#:image-content-type image-content-type
|
||||||
#:image-content-type image-content-type
|
#:license [license #f])
|
||||||
#:license [license #f])
|
|
||||||
(define video-embed-code (jp "/videoEmbedCode" media-detail ""))
|
(define video-embed-code (jp "/videoEmbedCode" media-detail ""))
|
||||||
(define raw-image-url (jp "/rawImageUrl" media-detail))
|
(define raw-image-url (jp "/rawImageUrl" media-detail))
|
||||||
(define image-url (jp "/imageUrl" media-detail raw-image-url))
|
(define image-url (jp "/imageUrl" media-detail raw-image-url))
|
||||||
|
@ -59,9 +55,8 @@
|
||||||
(define smaller-article-list (jp "/smallerArticleList" media-detail))
|
(define smaller-article-list (jp "/smallerArticleList" media-detail))
|
||||||
(define article-list-is-smaller (jp "/articleListIsSmaller" media-detail))
|
(define article-list-is-smaller (jp "/articleListIsSmaller" media-detail))
|
||||||
(define image-description (jp "/imageDescription" media-detail #f))
|
(define image-description (jp "/imageDescription" media-detail #f))
|
||||||
(define maybe-proxied-raw-image-url (if (config-true? 'strict_proxy)
|
(define maybe-proxied-raw-image-url
|
||||||
(u-proxy-url raw-image-url)
|
(if (config-true? 'strict_proxy) (u-proxy-url raw-image-url) raw-image-url))
|
||||||
raw-image-url))
|
|
||||||
(generate-wiki-page
|
(generate-wiki-page
|
||||||
#:source-url source-url
|
#:source-url source-url
|
||||||
#:wikiname wikiname
|
#:wikiname wikiname
|
||||||
|
@ -69,35 +64,27 @@
|
||||||
#:license license
|
#:license license
|
||||||
`(div
|
`(div
|
||||||
,(if (non-empty-string? video-embed-code)
|
,(if (non-empty-string? video-embed-code)
|
||||||
(update-tree-wiki (html->xexp (preprocess-html-wiki video-embed-code)) wikiname)
|
(update-tree-wiki (html->xexp (preprocess-html-wiki video-embed-code)) wikiname)
|
||||||
(get-media-html image-url image-content-type))
|
(get-media-html image-url image-content-type))
|
||||||
(p
|
(p ,(if (non-empty-string? video-embed-code)
|
||||||
,(if (non-empty-string? video-embed-code)
|
`""
|
||||||
`""
|
`(span (a (@ (href ,maybe-proxied-raw-image-url)) "View original file") ". "))
|
||||||
`(span (a (@ (href ,maybe-proxied-raw-image-url)) "View original file") ". "))
|
"Added by "
|
||||||
"Added by "
|
(a (@ (href ,(format "/~a/wiki/User:~a" wikiname username))) ,username)
|
||||||
(a (@ (href ,(format "/~a/wiki/User:~a" wikiname username))) ,username)
|
"."
|
||||||
"."
|
,(if is-posted-in
|
||||||
,(if is-posted-in
|
`(span " Posted in "
|
||||||
`(span " Posted in "
|
,@(map (λ (article)
|
||||||
,@(map
|
(define page-path (jp "/title" article))
|
||||||
(λ (article)
|
(define title (jp "/titleText" article page-path))
|
||||||
(define page-path (jp "/title" article))
|
`(span ,(if (eq? (car smaller-article-list) article) "" ", ")
|
||||||
(define title (jp "/titleText" article page-path))
|
(a (@ (href ,(format "/~a/wiki/~a" wikiname page-path))) ,title)))
|
||||||
`(span
|
smaller-article-list)
|
||||||
,(if (eq? (car smaller-article-list) article)
|
,(if (eq? article-list-is-smaller 1) "…" "."))
|
||||||
""
|
`""))
|
||||||
", ")
|
|
||||||
(a (@ (href ,(format "/~a/wiki/~a" wikiname page-path)))
|
|
||||||
,title)))
|
|
||||||
smaller-article-list)
|
|
||||||
,(if (eq? article-list-is-smaller 1)
|
|
||||||
"…"
|
|
||||||
"."))
|
|
||||||
`""))
|
|
||||||
,(if (string? image-description)
|
,(if (string? image-description)
|
||||||
(update-tree-wiki (html->xexp (preprocess-html-wiki image-description)) wikiname)
|
(update-tree-wiki (html->xexp (preprocess-html-wiki image-description)) wikiname)
|
||||||
""))))
|
""))))
|
||||||
|
|
||||||
(define (page-file req)
|
(define (page-file req)
|
||||||
(define wikiname (path/param-path (first (url-path (request-uri req)))))
|
(define wikiname (path/param-path (first (url-path (request-uri req)))))
|
||||||
|
@ -105,45 +92,40 @@
|
||||||
(define origin (format "https://~a.fandom.com" wikiname))
|
(define origin (format "https://~a.fandom.com" wikiname))
|
||||||
(define source-url (format "~a/wiki/~a" origin prefixed-title))
|
(define source-url (format "~a/wiki/~a" origin prefixed-title))
|
||||||
|
|
||||||
(thread-let
|
(thread-let ([media-detail
|
||||||
([media-detail (define dest-url
|
(define dest-url
|
||||||
(format "~a/wikia.php?~a"
|
(format "~a/wikia.php?~a"
|
||||||
origin
|
origin
|
||||||
(params->query `(("format" . "json")
|
(params->query `(("format" . "json") ("controller" . "Lightbox")
|
||||||
("controller" . "Lightbox")
|
("method" . "getMediaDetail")
|
||||||
("method" . "getMediaDetail")
|
("fileTitle" . ,prefixed-title)))))
|
||||||
("fileTitle" . ,prefixed-title)))))
|
(log-outgoing dest-url)
|
||||||
(log-outgoing dest-url)
|
(define dest-res (easy:get dest-url #:timeouts timeouts))
|
||||||
(define dest-res (easy:get dest-url #:timeouts timeouts))
|
(easy:response-json dest-res)]
|
||||||
(easy:response-json dest-res)]
|
[license (license-auto wikiname)])
|
||||||
[license (license-auto wikiname)])
|
(if (not (jp "/exists" media-detail #f))
|
||||||
|
(next-dispatcher)
|
||||||
(if (not (jp "/exists" media-detail #f))
|
(response-handler
|
||||||
(next-dispatcher)
|
(define file-title (jp "/fileTitle" media-detail ""))
|
||||||
(response-handler
|
(define title
|
||||||
(define file-title (jp "/fileTitle" media-detail ""))
|
(if (non-empty-string? file-title) (format "File:~a" file-title) prefixed-title))
|
||||||
(define title (if (non-empty-string? file-title)
|
(define image-content-type
|
||||||
(format "File:~a" file-title)
|
(if (non-empty-string? (jp "/videoEmbedCode" media-detail ""))
|
||||||
prefixed-title))
|
#f
|
||||||
(define image-content-type (if (non-empty-string? (jp "/videoEmbedCode" media-detail ""))
|
(url-content-type (jp "/imageUrl" media-detail))))
|
||||||
#f
|
(define body
|
||||||
(url-content-type (jp "/imageUrl" media-detail))))
|
(generate-results-page #:source-url source-url
|
||||||
(define body (generate-results-page
|
#:wikiname wikiname
|
||||||
#:source-url source-url
|
#:title title
|
||||||
#:wikiname wikiname
|
#:media-detail media-detail
|
||||||
#:title title
|
#:image-content-type image-content-type
|
||||||
#:media-detail media-detail
|
#:license license))
|
||||||
#:image-content-type image-content-type
|
(when (config-true? 'debug)
|
||||||
#:license license))
|
; used for its side effects
|
||||||
|
; convert to string with error checking, error will be raised if xexp is invalid
|
||||||
(when (config-true? 'debug)
|
(xexp->html body))
|
||||||
; used for its side effects
|
(response/output #:code 200
|
||||||
; convert to string with error checking, error will be raised if xexp is invalid
|
(λ (out) (write-html body out)))))))
|
||||||
(xexp->html body))
|
|
||||||
(response/output
|
|
||||||
#:code 200
|
|
||||||
(λ (out)
|
|
||||||
(write-html body out)))))))
|
|
||||||
;(module+ test
|
;(module+ test
|
||||||
; (check-not-false ((query-selector (attribute-selector 'href "/test/wiki/Ankle_Monitor")
|
; (check-not-false ((query-selector (attribute-selector 'href "/test/wiki/Ankle_Monitor")
|
||||||
; (generate-results-page
|
; (generate-results-page
|
||||||
|
|
Loading…
Reference in a new issue