diff --git a/src/gemini-viewer.lisp b/src/gemini-viewer.lisp index 8ccfee6..dc01ab6 100644 --- a/src/gemini-viewer.lisp +++ b/src/gemini-viewer.lisp @@ -663,23 +663,13 @@ (push-url-to-history specials:*message-window* actual-iri) (gemini-client:request-dispatch url gemini-client::dispatch-table))))) (gemini-client:gemini-tofu-error (e) - (let ((host (gemini-client:host e))) - (flet ((on-input-complete (maybe-accepted) - (when (ui::boolean-input-accepted-p maybe-accepted) - (db-utils:with-ready-database (:connect nil) - (db:tofu-delete host) - (request url - :enqueue enqueue - :certificate certificate - :certificate-key certificate-key - :do-nothing-if-exists-in-db - do-nothing-if-exists-in-db))))) - (ui:ask-string-input #'on-input-complete - :prompt - (format nil - (_ "Host ~s signature changed! This is a potential security risk! Ignore this warning? [y/N] ") - host) - :priority program-events:+standard-event-priority+)))) + (gemini-client:with-ask-input-on-tofu-error (e) + (request url + :enqueue enqueue + :certificate certificate + :certificate-key certificate-key + :do-nothing-if-exists-in-db + do-nothing-if-exists-in-db))) (conditions:not-implemented-error (e) (ui:notify (format nil (_ "Error: ~a") e) :as-error t)) diff --git a/src/gemini/client.lisp b/src/gemini/client.lisp index 9f0048f..83f521f 100644 --- a/src/gemini/client.lisp +++ b/src/gemini/client.lisp @@ -523,3 +523,18 @@ TODO: Add client certificate." :ignore-warning t) (request-dispatch url dispatch-table)) (fs:slurp-file url :convert-to-string nil)))) + +(defmacro with-ask-input-on-tofu-error ((condition) &body body) + (with-gensyms (host) + `(let ((,host (gemini-client:host ,condition))) + (flet ((on-input-complete (maybe-accepted) + (when (ui::boolean-input-accepted-p maybe-accepted) + (db-utils:with-ready-database (:connect nil) + (db:tofu-delete ,host) + ,@body)))) + (ui:ask-string-input #'on-input-complete + :prompt + (format nil + (_ "Host ~s signature changed! This is a potential security risk! Ignore this warning? [y/N] ") + ,host) + :priority program-events:+standard-event-priority+))))) diff --git a/src/gemini/package.lisp b/src/gemini/package.lisp index 3d319bb..5c263af 100644 --- a/src/gemini/package.lisp +++ b/src/gemini/package.lisp @@ -147,7 +147,8 @@ :with-request-dispatch-table :fetch-cached-certificate :build-redirect-iri - :slurp-gemini-url)) + :slurp-gemini-url + :with-ask-input-on-tofu-error)) (defpackage :gemini-subscription (:use diff --git a/src/gemini/subscription.lisp b/src/gemini/subscription.lisp index 6c195e9..e1daa76 100644 --- a/src/gemini/subscription.lisp +++ b/src/gemini/subscription.lisp @@ -86,15 +86,5 @@ be subscribed before (see: 'gemini-subscription:subcribe'" date nil)))))) (gemini-client:gemini-tofu-error (e) - (let ((host (gemini-client:host e))) - (flet ((on-input-complete (maybe-accepted) - (when (ui::boolean-input-accepted-p maybe-accepted) - (db-utils:with-ready-database (:connect nil) - (db:tofu-delete host) - (refresh url))))) - (ui:ask-string-input #'on-input-complete - :prompt - (format nil - (_ "Host ~s signature changed! This is a potential security risk! Ignore this warning? [y/N] ") - host) - :priority program-events:+standard-event-priority+)))))) + (with-ask-input-on-tofu-error (e) + (refresh url)))))