mirror of https://codeberg.org/cage/tinmop/
- [GUI] refactored gemini stram function.
This commit is contained in:
parent
5b52ac26ef
commit
fb7b398608
|
@ -381,6 +381,24 @@
|
|||
(subseq res 1)
|
||||
res)))
|
||||
|
||||
(defun write-out-stream (file-stream wrapper-object line)
|
||||
(let ((parsed-line (gemini-parser:parse-gemini-file line)))
|
||||
(write-sequence line file-stream)
|
||||
(increment-bytes-count wrapper-object line :convert-to-octets t)
|
||||
(append-parsed-line wrapper-object parsed-line)))
|
||||
|
||||
(defun maybe-write-out-preformat-wrapper (file-stream wrapper-object gemini-format)
|
||||
(when (and (os-utils:open-resource-with-tinmop-p (download-iri wrapper-object))
|
||||
(not gemini-format))
|
||||
(write-out-stream file-stream
|
||||
wrapper-object
|
||||
(format nil "~a~%" gemini-parser:+preformatted-prefix+))))
|
||||
|
||||
(defun append-parsed-line (wrapper-object parsed-line)
|
||||
(setf (parsed-lines wrapper-object)
|
||||
(append (parsed-lines wrapper-object)
|
||||
parsed-line)))
|
||||
|
||||
(defun request-stream-gemini-document-thread (wrapper-object scheme host
|
||||
port path query fragment favicon
|
||||
gemini-format-p
|
||||
|
@ -456,10 +474,7 @@
|
|||
(new-title-event (make-instance 'program-events:change-window-title-event
|
||||
:payload url-header
|
||||
:window *message-window*)))
|
||||
(write-sequence url-header file-stream)
|
||||
(increment-bytes-count wrapper-object url-header :convert-to-octets t)
|
||||
(setf (parsed-lines wrapper-object)
|
||||
(gemini-parser:parse-gemini-file url-header))
|
||||
(write-out-stream file-stream wrapper-object url-header)
|
||||
(maybe-change-title new-title-event)
|
||||
(maybe-render-line url-event)
|
||||
(maybe-render-preformat-wrapper file-stream wrapper-object)
|
||||
|
@ -478,11 +493,7 @@
|
|||
(parsed-line (gemini-parser:parse-gemini-file line)))
|
||||
(gemini-client:debug-gemini "[stream] gemini file stream got data line : ~a"
|
||||
line)
|
||||
(write-sequence line file-stream)
|
||||
(increment-bytes-count wrapper-object line :convert-to-octets t)
|
||||
(setf (parsed-lines wrapper-object)
|
||||
(append (parsed-lines wrapper-object)
|
||||
parsed-line))
|
||||
(write-out-stream file-stream wrapper-object line)
|
||||
(let ((event (make-gemini-download-event line
|
||||
parsed-line
|
||||
wrapper-object
|
||||
|
|
|
@ -100,59 +100,44 @@
|
|||
(download-stream gw:download-stream)
|
||||
(octet-count gw:octet-count)
|
||||
(support-file gw:support-file)) wrapper-object
|
||||
(labels ((maybe-render-preformat-wrapper (file-stream wrapper-object)
|
||||
(when (and (os-utils:open-resource-with-tinmop-p (gw:download-iri wrapper-object))
|
||||
(not gemini-format-p))
|
||||
(write-out-stream file-stream
|
||||
wrapper-object
|
||||
(format nil "~a~%" gemini-parser:+preformatted-prefix+))))
|
||||
(write-out-stream (file-stream wrapper-object line)
|
||||
(let ((parsed-line (gemini-parser:parse-gemini-file line)))
|
||||
(write-sequence line file-stream)
|
||||
(gw::increment-bytes-count wrapper-object line :convert-to-octets t)
|
||||
(append-parsed-line wrapper-object parsed-line)))
|
||||
(append-parsed-line (wrapper-object parsed-line)
|
||||
(setf (gw:parsed-lines wrapper-object)
|
||||
(append (gw:parsed-lines wrapper-object)
|
||||
parsed-line))))
|
||||
(lambda ()
|
||||
(gemini-parser:with-initialized-parser
|
||||
(a:when-let ((extension (fs:get-extension path)))
|
||||
(setf support-file (fs:temporary-file :extension extension)))
|
||||
(gw::with-open-support-file (file-stream support-file character)
|
||||
(let* ((url (gemini-parser:make-gemini-iri host
|
||||
path
|
||||
:scheme scheme
|
||||
:query query
|
||||
:port port
|
||||
:fragment fragment))
|
||||
(url-header (format nil "~a ~a~2%" favicon url)))
|
||||
(write-out-stream file-stream wrapper-object url-header)
|
||||
(maybe-render-preformat-wrapper file-stream wrapper-object)
|
||||
(handler-case
|
||||
(loop
|
||||
named download-loop
|
||||
for ct from 0
|
||||
for line-as-array = (read-line-into-array download-stream)
|
||||
while line-as-array do
|
||||
(gemini-client:debug-gemini "[stream] gemini file stream raw data line : ~a"
|
||||
line-as-array)
|
||||
(if (gw:downloading-allowed-p wrapper-object)
|
||||
(let* ((line (if (= ct 0)
|
||||
(gw::array->string line-as-array t)
|
||||
(gw::array->string line-as-array nil))))
|
||||
(gemini-client:debug-gemini "[stream] gemini file stream got data line : ~a"
|
||||
line)
|
||||
(write-out-stream file-stream wrapper-object line))
|
||||
(return-from download-loop nil)))
|
||||
(error (e)
|
||||
(let ((message (gemini-parser:make-error-parsing-line (format nil
|
||||
(_ "Gemini stream error: ~a")
|
||||
e))))
|
||||
(append-parsed-line wrapper-object (list message)))))
|
||||
(setf (gw:stream-status wrapper-object) :completed)
|
||||
(maybe-render-preformat-wrapper file-stream wrapper-object)
|
||||
(gemini-client:close-ssl-socket download-socket))))))))
|
||||
(lambda ()
|
||||
(gemini-parser:with-initialized-parser
|
||||
(a:when-let ((extension (fs:get-extension path)))
|
||||
(setf support-file (fs:temporary-file :extension extension)))
|
||||
(gw::with-open-support-file (file-stream support-file character)
|
||||
(let* ((url (gemini-parser:make-gemini-iri host
|
||||
path
|
||||
:scheme scheme
|
||||
:query query
|
||||
:port port
|
||||
:fragment fragment))
|
||||
(url-header (format nil "~a ~a~2%" favicon url)))
|
||||
(gw::write-out-stream file-stream wrapper-object url-header)
|
||||
(gw::maybe-write-out-preformat-wrapper file-stream wrapper-object gemini-format-p)
|
||||
(handler-case
|
||||
(loop
|
||||
named download-loop
|
||||
for ct from 0
|
||||
for line-as-array = (read-line-into-array download-stream)
|
||||
while line-as-array do
|
||||
(gemini-client:debug-gemini "[stream] gemini file stream raw data line : ~a"
|
||||
line-as-array)
|
||||
(if (gw:downloading-allowed-p wrapper-object)
|
||||
(let* ((line (if (= ct 0)
|
||||
(gw::array->string line-as-array t)
|
||||
(gw::array->string line-as-array nil))))
|
||||
(gemini-client:debug-gemini "[stream] gemini file stream got data line : ~a"
|
||||
line)
|
||||
(gw::write-out-stream file-stream wrapper-object line))
|
||||
(return-from download-loop nil)))
|
||||
(error (e)
|
||||
(let ((message (gemini-parser:make-error-parsing-line (format nil
|
||||
(_ "Gemini stream error: ~a")
|
||||
e))))
|
||||
(gw::append-parsed-line wrapper-object (list message)))))
|
||||
(setf (gw:stream-status wrapper-object) :completed)
|
||||
(gw::maybe-write-out-preformat-wrapper file-stream wrapper-object gemini-format-p)
|
||||
(gemini-client:close-ssl-socket download-socket)))))))
|
||||
|
||||
(defun request-success-dispatched-fn (status code-description meta response socket iri parsed-iri)
|
||||
(declare (ignore iri))
|
||||
|
|
Loading…
Reference in New Issue