You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
65 lines
1.5 KiB
(mapc
|
|
(lambda (x) (ql:quickload x))
|
|
'(:cl-rng
|
|
:manx-utils
|
|
:cl-ppcre
|
|
:aserve
|
|
:dexador
|
|
:jsown
|
|
:qbase64))
|
|
|
|
(load #p"config.lisp")
|
|
|
|
(when (null *host*)
|
|
(print "Host can't be nil")
|
|
(exit :code -1))
|
|
|
|
(defun get-loli (rating)
|
|
(jsown:val
|
|
(car ;; %parse-json returns a list of a list
|
|
(jsown:parse
|
|
(dex:get
|
|
(manx-utils:to-string
|
|
"https://lolibooru.moe/post/index.json?tags=rating:" rating "+-3dcg+-rape&limit=1&page="
|
|
(cl-rng:crandom :limit 25000 :transform 'floor)))))
|
|
"file_url"))
|
|
|
|
(defun main (&rest args)
|
|
(net.aserve:start :port 8080 :host *host*)
|
|
|
|
(net.aserve:publish
|
|
:path "/loli"
|
|
:content-type "text/html"
|
|
:function 'this-is-bad-code)
|
|
|
|
(net.aserve:publish-file
|
|
:path "/loli/about"
|
|
:file #p"about.html")
|
|
|
|
(loop (sleep 10000)))
|
|
|
|
(defun loli-rating (req)
|
|
(let ((rating (net.aserve:request-query-value "rating" req)))
|
|
(or (cl-ppcre:scan-to-strings "-?(s|q|e)" rating)
|
|
"s")))
|
|
|
|
(defun based-loli (req)
|
|
(manx-utils:to-string
|
|
"data:image/jpg;base64,"
|
|
(qbase64:encode-bytes
|
|
(dex:get (get-loli (loli-rating req))))))
|
|
|
|
(defun this-is-bad-code (req ent)
|
|
(net.aserve:with-http-response (req ent)
|
|
(net.aserve:with-http-body (req ent)
|
|
(net.html.generator:html
|
|
(:html
|
|
(:head
|
|
((:meta name "viewport" content "width=device-width, initial-scale=1")))
|
|
((:body :style "position:relative")
|
|
((:img :style "object-fit: contain; width: 100%; height:100%"
|
|
:src (based-loli req)))
|
|
((:a :style "position:absolute;top:8px;right:16px;" href "/loli/about") "about")))))))
|
|
|
|
(main)
|