initial commit

This commit is contained in:
xenia 2020-10-30 18:25:27 -04:00
commit 524487fc36
3 changed files with 38 additions and 0 deletions

1
README.md Normal file
View File

@ -0,0 +1 @@
# snippets of code, or something

1
racket/fedi/README.md Normal file
View File

@ -0,0 +1 @@
## also see: https://git.lain.faith/haskal/awoobot.git

36
racket/fedi/upload.rkt Normal file
View File

@ -0,0 +1,36 @@
;; String String Bytes -> String
;; Uploads some media, returns the media ID
(define (upload-media filename mime-type data-bytes)
(define MULTIPART-BOUNDARY "hashlanguwu")
(define s->b string->bytes/utf-8)
;; aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
(define multipart-data
(bytes-append
#"--" (s->b MULTIPART-BOUNDARY) #"\r\n"
#"Content-Disposition: form-data; name=\"file\"; filename=\"" (s->b filename) #"\"\r\n"
#"Content-Type: " (s->b mime-type) #"\r\n"
#"\r\n"
data-bytes
#"\r\n"
#"--" (s->b MULTIPART-BOUNDARY) #"--\r\n"))
;; send it
(define-values (status headers rsp)
(http-sendrecv/url (make-api-url '("media"))
#:method "POST"
#:headers (list
(make-header "Authorization" (get-authorization))
(make-header "Content-Type"
(string-append "multipart/form-data; boundary="
MULTIPART-BOUNDARY)))
#:data multipart-data))
(hash-ref (string->jsexpr (port->string rsp)) 'id))
(define (bot-run)
(define thank (file->bytes "thank.png"))
(define thank-id (upload-media "thank.png" "image/png" thank))
(define toot (make-toot "test post pls ignore"
#:cw "bot post, no caption"
#:media (list thank-id)))
(displayln toot)
(send-toot toot)
(void))