summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--dynamic/api.scm26
-rw-r--r--haunt/jakob/builder/blog.scm3
-rw-r--r--haunt/jakob/utils/comments.scm12
-rw-r--r--haunt/static/js/proof-of-work.js34
5 files changed, 53 insertions, 23 deletions
diff --git a/.gitignore b/.gitignore
index 546a074..5a0d758 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.stfolder
publish.sh
/haunt/images/*
diff --git a/dynamic/api.scm b/dynamic/api.scm
index 8bbff1e..451c5c6 100644
--- a/dynamic/api.scm
+++ b/dynamic/api.scm
@@ -14,7 +14,8 @@
;;; along with this program. If not, see
;;; <http://www.gnu.org/licenses/>.
-(use-modules (dynamic capabilities comments)
+(use-modules (dynamic capabilities comment-form)
+ (dynamic capabilities comments)
(dynamic capabilities gallery)
(dynamic capabilities rsvp)
(dynamic logging)
@@ -38,14 +39,15 @@
(args (uri-query (request-uri request))))
(log-append! 'info (format #f "~a ~a (~a) (~a)" method endpoint args originating-ip)))
((match (cons (request-method request) endpoint)
- ;; ('(GET "challenge") make-challenge)
- ('(GET "comments") get-comments)
- ('(POST "comment") put-comment)
- ('(POST "react") put-reaction)
- ('(GET "gallery") get-gallery)
- ('(GET "gallery" "image") get-image)
- ('(GET "rsvp" "event-info") get-event-info)
- ('(POST "rsvp") post-event-rsvp)
+ ('(GET "dynamic" "comment-form") get-comment-form)
+ ('(GET "challenge") make-challenge)
+ ('(GET "api" "comments") get-comments)
+ ('(POST "api" "comment") put-comment)
+ ('(POST "api" "react") put-reaction)
+ ('(GET "api" "gallery") get-gallery)
+ ('(GET "api" "gallery" "image") get-image)
+ ('(GET "api" "rsvp" "event-info") get-event-info)
+ ('(POST "api" "rsvp") post-event-rsvp)
(_ (lambda (. args) (not-found request))))
request body))
@@ -68,8 +70,10 @@
(let* ((path-encoded (uri-path (request-uri request)))
(path (split-and-decode-uri-path path-encoded)))
(define-values (response resp-body)
- (if (string= "api" (first path))
- (handle-api-request request body (drop path 1))
+ (if (or (string= "api" (first path))
+ (string= "dynamic" (first path)))
+ ;; (handle-api-request request body (drop path 1))
+ (handle-api-request request body path)
(not-found request)))
(values (wrap-response response) resp-body)))
diff --git a/haunt/jakob/builder/blog.scm b/haunt/jakob/builder/blog.scm
index 76782dc..b1e19fa 100644
--- a/haunt/jakob/builder/blog.scm
+++ b/haunt/jakob/builder/blog.scm
@@ -26,8 +26,8 @@
#:use-module (jakob utils pagination)
#:use-module (jakob utils sxml)
#:use-module (jakob utils tags)
- #:use-module (jakob utils webmention)
#:use-module (jakob utils comments)
+ ;; #:use-module (jakob utils webmention)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-19)
#:use-module (srfi srfi-26)
@@ -86,6 +86,7 @@
(h2 ,(hyperlink "https://indieweb.org/Webmention" "Webmentions")
" for this Page")
(ul (@ (id "webmention-container"))
+ ;; ,@(render-comment-view (fetch-webmentions (post-identifier post))))
,@(render-comment-view (fetch-comments (post-identifier post))))
(form
(@ (action "https://webmention.io/jakob.space/webmention")
diff --git a/haunt/jakob/utils/comments.scm b/haunt/jakob/utils/comments.scm
index 7cb4768..3f55345 100644
--- a/haunt/jakob/utils/comments.scm
+++ b/haunt/jakob/utils/comments.scm
@@ -102,14 +102,4 @@
(define (fetch-comments slug)
"Blocking call to webmention.io to retrieve a vector of all Webmentions for `slug'"
- (get-comments-by-slug slug)
- ;; (list '((id . 1)
- ;; (published . "20220514122120")
- ;; (name . "Jakob")
- ;; (subject . "Test")
- ;; (email . "jakob@memeware.net")
- ;; (comment . "Test")
- ;; (url . "jakob.space")
- ;; (reactions . (("🎖️" . 2)))))
- )
-;; dynamic
+ (get-comments-by-slug slug))
diff --git a/haunt/static/js/proof-of-work.js b/haunt/static/js/proof-of-work.js
new file mode 100644
index 0000000..5207ac6
--- /dev/null
+++ b/haunt/static/js/proof-of-work.js
@@ -0,0 +1,34 @@
+const text = 'An obscure body in the S-K System, your majesty. The inhabitants refer to it as the planet Earth.';
+
+function makeid(length) {
+ var result = '';
+ var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
+ var charactersLength = characters.length;
+ for ( var i = 0; i < length; i++ ) {
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
+ }
+ return result;
+}
+
+async function digestMessage(message) {
+ const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
+ const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8); // hash the message
+ const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
+ const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string
+ return hashHex;
+}
+
+const HARDNESS = 4;
+
+async function findPrefix(challenge) {
+ while (true) {
+ let prefix = makeid(32);
+ let digestHex = await digestMessage(prefix + challenge);
+ if (digestHex.startsWith("0".repeat(HARDNESS))) {
+ return [prefix + challenge, digestHex];
+ }
+ }
+}
+
+const suffix = "p12IyPB2dZsmBHYZyaEMrR5OUxqNc5Z9Cijal+9/iuQ=";
+findPrefix(suffix).then(console.log);