Compare commits

..

2 commits

Author SHA1 Message Date
bf80692c4e
Add support for File: pages
Fixes https://lists.sr.ht/~cadence/breezewiki-discuss/%3Cb2835a70-5118-4df0-90c9-4333486a4b69%40nixnetmail.com%3E
2022-10-09 14:54:08 +07:00
5a59545963
Set Referrer-Policy to no-referrer
Fandom sends a fake 404 to media if there's a Referer header that has an origin
that's not Fandom. However, we can choose not to send the header by setting
Referrer-Policy. See also:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
2022-10-09 10:53:02 +07:00

View file

@ -25,7 +25,17 @@
(module+ test
(require rackunit)
(define test-media-detail
'#hasheq((fileTitle . "Example file") (videoEmbedCode . "") (imageUrl . "https://static.wikia.nocookie.net/examplefile") (rawImageUrl . "https://static.wikia.nocookie.net/examplefile") (userName . "blankie") (isPostedIn . #t) (smallerArticleList . (#hasheq((title . "Example_article") (titleText . "Example article")))) (articleListIsSmaller . 0) (exists . #t) (imageDescription . #f))))
'#hasheq((fileTitle . "Example file")
(videoEmbedCode . "")
(imageUrl . "https://static.wikia.nocookie.net/examplefile")
(rawImageUrl . "https://static.wikia.nocookie.net/examplefile")
(userName . "blankie")
(isPostedIn . #t)
(smallerArticleList . (#hasheq((title . "Example_article")
(titleText . "Example article"))))
(articleListIsSmaller . 0)
(exists . #t)
(imageDescription . #f))))
(define (url-content-type url)
(log-outgoing url)
@ -63,29 +73,29 @@
#: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)
(get-media-html image-url image-content-type))
(p ,(if (non-empty-string? video-embed-code)
`""
`(span (a (@ (href ,maybe-proxied-raw-image-url)) "View original file") ". "))
"Added by "
(a (@ (href ,(format "/~a/wiki/User:~a" wikiname username))) ,username)
"."
,(if is-posted-in
`(span " Posted in "
,@(map (λ (article)
(define page-path (jp "/title" article))
(define title (jp "/titleText" article page-path))
`(span ,(if (eq? (car smaller-article-list) article) "" ", ")
(a (@ (href ,(format "/~a/wiki/~a" wikiname page-path))) ,title)))
smaller-article-list)
,(if (eq? article-list-is-smaller 1) "" "."))
`""))
,(if (string? image-description)
(update-tree-wiki (html->xexp (preprocess-html-wiki image-description)) wikiname)
""))))
`(div ,(if (non-empty-string? video-embed-code)
(update-tree-wiki (html->xexp (preprocess-html-wiki video-embed-code)) wikiname)
(get-media-html image-url image-content-type))
(p ,(if (non-empty-string? video-embed-code)
`""
`(span (a (@ (href ,maybe-proxied-raw-image-url)) "View original file") ". "))
"Added by "
(a (@ (href ,(format "/~a/wiki/User:~a" wikiname username))) ,username)
"."
,(if is-posted-in
`(span " Posted in "
,@(map (λ (article)
(define page-path (jp "/title" article))
(define title (jp "/titleText" article page-path))
`(span ,(if (eq? (car smaller-article-list) article) "" ", ")
(a (@ (href ,(format "/~a/wiki/~a" wikiname page-path)))
,title)))
smaller-article-list)
,(if (eq? article-list-is-smaller 1) "" "."))
`""))
,(if (string? image-description)
(update-tree-wiki (html->xexp (preprocess-html-wiki image-description)) wikiname)
""))))
(define (page-file req)
(define wikiname (path/param-path (first (url-path (request-uri req)))))
@ -146,10 +156,11 @@
(check-equal? (get-media-html "https://example.com" #f) `""))
(module+ test
(parameterize ([(config-parameter 'strict_proxy) "true"])
(check-not-false ((query-selector (attribute-selector 'src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fexamplefile")
(generate-results-page
#:source-url ""
#:wikiname "test"
#:title "File:Example file"
#:media-detail test-media-detail
#:image-content-type "image/jpeg"))))))
(check-not-false
((query-selector
(attribute-selector 'src "/proxy?dest=https%3A%2F%2Fstatic.wikia.nocookie.net%2Fexamplefile")
(generate-results-page #:source-url ""
#:wikiname "test"
#:title "File:Example file"
#:media-detail test-media-detail
#:image-content-type "image/jpeg"))))))