|
|
@ -1,62 +1,63 @@
|
|
|
|
(ql:quickload :aserve)
|
|
|
|
(in-package :lolisp)
|
|
|
|
(ql:quickload :dexador)
|
|
|
|
|
|
|
|
(ql:quickload :jsown)
|
|
|
|
(defvar @html "text/html")
|
|
|
|
(ql:quickload :qbase64)
|
|
|
|
(defparameter *serb* nil
|
|
|
|
(ql:quickload :cl-ppcre)
|
|
|
|
"The hunchentoot acceptor (server) that will serve our handlers and
|
|
|
|
(ql:quickload :cl-rng)
|
|
|
|
files.")
|
|
|
|
(ql:quickload :manx-utils)
|
|
|
|
|
|
|
|
|
|
|
|
(defmacro str (&rest strs)
|
|
|
|
(load #p"config.lisp")
|
|
|
|
"Concatenate a list of strings `strs' to one string."
|
|
|
|
|
|
|
|
`(concatenate 'string ,@strs))
|
|
|
|
(when (null *host*)
|
|
|
|
|
|
|
|
(print "Host can't be nil")
|
|
|
|
(defmacro config-item (thing &aux (item (gensym)))
|
|
|
|
(exit :code -1))
|
|
|
|
"Get `thing' from the alist `config', error if it doesn't exist"
|
|
|
|
|
|
|
|
`(let ((,item (assoc ,thing config)))
|
|
|
|
(defun get-loli (rating)
|
|
|
|
(when (atom ,item)
|
|
|
|
(jsown:val
|
|
|
|
(error "No such config item"))
|
|
|
|
(car ;; %parse-json returns a list of a list
|
|
|
|
(cdr ,item)))
|
|
|
|
(jsown:parse
|
|
|
|
|
|
|
|
(dex:get
|
|
|
|
(defun loli-link (rating)
|
|
|
|
(manx-utils:to-string
|
|
|
|
"Extract file_url from the JSON returned by `dex:get' and replace
|
|
|
|
"https://lolibooru.moe/post/index.json?tags=rating:" rating "+-3dcg+-rape&limit=1&page="
|
|
|
|
escaped backslashes (\\\\/) with /.
|
|
|
|
(cl-rng:crandom :limit 25000 :transform 'floor)))))
|
|
|
|
|
|
|
|
"file_url"))
|
|
|
|
Use cl-rng to pick a random page from the lolibooru API"
|
|
|
|
|
|
|
|
(cl-ppcre:register-groups-bind (url)
|
|
|
|
(defun main (&rest args)
|
|
|
|
("(?:file_url\":\")(.*?)(?:\",)"
|
|
|
|
(net.aserve:start :port 8080 :host *host*)
|
|
|
|
(dex:get (str "https://lolibooru.moe/post/index.json?tags=rating:"
|
|
|
|
|
|
|
|
(or (cl-ppcre:scan-to-strings "-?[sqe]" rating) "s")
|
|
|
|
(net.aserve:publish
|
|
|
|
"+-3dcg+-rape&limit=1&page="
|
|
|
|
:path "/loli"
|
|
|
|
(write-to-string (cl-rng:crandom :limit 25000 :transform 'floor)))))
|
|
|
|
:content-type "text/html"
|
|
|
|
(cl-ppcre:regex-replace-all "\\\\/" url "/")))
|
|
|
|
:function 'this-is-bad-code)
|
|
|
|
|
|
|
|
|
|
|
|
(defun based-loli (url)
|
|
|
|
(net.aserve:publish-file
|
|
|
|
(str "data:image/jpeg;base64," (qbase64:encode-bytes (dex:get url))))
|
|
|
|
:path "/loli/about"
|
|
|
|
|
|
|
|
:file #p"about.html")
|
|
|
|
(henh:handle :get (loli :uri "/loli/") @html
|
|
|
|
|
|
|
|
(rating)
|
|
|
|
(loop (sleep 10000)))
|
|
|
|
(cl-who:with-html-output-to-string (x)
|
|
|
|
|
|
|
|
(:html
|
|
|
|
(defun loli-rating (rating)
|
|
|
|
(:head
|
|
|
|
(or (cl-ppcre:scan-to-strings "-?(s|q|e)" rating)
|
|
|
|
(:meta :charset "utf-8")
|
|
|
|
"s"))
|
|
|
|
(:meta :name "viewport" :content "width=device-width, initial-scale=1")
|
|
|
|
|
|
|
|
(:title "lolisp")
|
|
|
|
(defun based-loli (req)
|
|
|
|
(:style "body{position:relative;}img{object-fit:contain;width:100%;height:100%;}#about{position:absolute;top:8px;right:16px}"))
|
|
|
|
(manx-utils:to-string
|
|
|
|
(:body
|
|
|
|
"data:image/jpg;base64,"
|
|
|
|
(:img :src (based-loli (loli-link rating)))
|
|
|
|
(qbase64:encode-bytes
|
|
|
|
(:a :id "about" :href "/loli/about" "about")))
|
|
|
|
(dex:get (get-loli
|
|
|
|
x))
|
|
|
|
(loli-rating (net.aserve:request-query-value "rating" req)))))))
|
|
|
|
|
|
|
|
|
|
|
|
(henh:host-file "/loli/about" "about.html" @html)
|
|
|
|
(defun this-is-bad-code (req ent)
|
|
|
|
|
|
|
|
(net.aserve:with-http-response (req ent)
|
|
|
|
(defun configure ()
|
|
|
|
(net.aserve:with-http-body (req ent)
|
|
|
|
(setf *serb* (make-instance 'hunchentoot:easy-acceptor
|
|
|
|
(net.html.generator:html
|
|
|
|
:port (config-item :port)
|
|
|
|
(:html
|
|
|
|
:document-root (config-item :document-root))))
|
|
|
|
(:head
|
|
|
|
|
|
|
|
((:meta name "viewport" content "width=device-width, initial-scale=1")))
|
|
|
|
(defun start ()
|
|
|
|
((:body :style "position:relative")
|
|
|
|
(handler-case (configure)
|
|
|
|
((:img :style "object-fit: contain; width: 100%; height:100%"
|
|
|
|
(error (e) "Configuration failed: ~a" e))
|
|
|
|
:src (based-loli req)))
|
|
|
|
(hunchentoot:start *serb*))
|
|
|
|
((:a :style "position:absolute;top:8px;right:16px;" href "/loli/about") "about"))))))
|
|
|
|
|
|
|
|
(gc :full t)) ;; Removes downloaded files from memory
|
|
|
|
(export '(configure
|
|
|
|
(main)
|
|
|
|
start
|
|
|
|
|
|
|
|
*serb*))
|
|
|
|