Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Paste
P1387
create-user tryout with dexador and avatar... at best, avatar is seen as invalid (400 response)
Active
Public
Actions
Authored by
ardumont
on Jun 18 2022, 4:08 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Subscribers
None
(defun create-user (user)
(when-unmapped-with-update (:user (forgerie-core:user-username user))
(let*
((avatar (forgerie-core:user-avatar user))
(avatar
(when avatar
(if (> (* 1024 200) (forgerie-core:file-size avatar))
avatar
(progn
(forgerie-core:add-mapping-error
:user-avatar-too-big
(forgerie-core:user-username user)
(format nil "User ~A's avatar is ~A, which is bigger than the allowed 200k" (forgerie-core:user-username user) (forgerie-core:file-size avatar)))))))
(avatar-filename
(when avatar
(if
(find-if
(lambda (ext) (cl-ppcre:scan (format nil "~A$" ext) (forgerie-core:file-name avatar)))
(list "png" "jpg" "jpeg" "gif" "bmp" "tiff" "ico" "webp"))
(forgerie-core:file-name avatar)
(format nil "~A.~A" (forgerie-core:file-name avatar)
(cond
((cl-ppcre:scan "^image/" (forgerie-core:file-mimetype avatar)) (subseq (forgerie-core:file-mimetype avatar) 6))
(t (error (format nil "Don't know profile mimetype ~A" (forgerie-core:file-mimetype avatar)))))))))
(avatar-filepath-with-mimetype
(when avatar-filename
(format nil "~A.~A"
(forgerie-core:file-location avatar)
(subseq (forgerie-core:file-mimetype avatar) 6))))
(gl-user
(progn
(when avatar-filepath-with-mimetype
(uiop:copy-file (forgerie-core:file-location avatar) avatar-filepath-with-mimetype))
(with-open-file (avatar-bytes (if avatar (forgerie-core:file-location avatar) "/dev/null") :element-type 'unsigned-byte)
;; (when avatar-filepath-with-mimetype
;; ;; rename avatar file with its mimetype extension
;; (uiop:copy-file (uiop:copy-file source-path target-path) (uiop:copy-file source-path target-path))
;; (with-open-file (copy-file-fd avatar-filepath-with-mimetype :direction :output
;; :if-exists :supersede
;; :if-does-not-exist :create)
;; (write-sequence (read-sequence avatar-bytes) copy-file-fd)))
(make-drakma-request
"users"
:post
`(("name" . ,(forgerie-core:user-name user))
("email" . ,(forgerie-core:email-address (forgerie-core:user-primary-email user)))
;; Everyone must be an admin to make some of the other import things work correctly
;; and then admin must be removed after
("admin" . "true")
("reset_password" . "true")
("username" . ,(forgerie-core:user-username user))
,@(when avatar
;; (list (cons "avatar" (list (forgerie-core:file-location avatar)
;; :content-type (forgerie-core:file-mimetype avatar)
;; :filename (drakma:url-encode avatar-filename :utf-8))))
;; (list (cons "avatar" avatar-filename))
;; (list (cons "avatar" (forgerie-core:file-location avatar)))
;; (list (cons "avatar" avatar-filepath-with-mimetype))
;; (list (cons "avatar" (list avatar-bytes
;; :content-type (forgerie-core:file-mimetype avatar)
;; :filename (drakma:url-encode avatar-filename :utf-8))))
;; `(("avatar" . ,(list (pathname (forgerie-core:file-location avatar))
;; :content-type (forgerie-core:file-mimetype avatar)
;; :filename (drakma:url-encode avatar-filename :utf-8))))
;; `(("avatar" . ,(list str
;; :content-type (forgerie-core:file-mimetype avatar)
;; :filename (drakma:url-encode avatar-filename :utf-8))))
)))))))
(mapcar
(lambda (email)
(post-request (format nil "/users/~A/emails" (getf gl-user :id))
`(("email" . ,(forgerie-core:email-address email)))))
(remove-if #'forgerie-core:email-is-primary (forgerie-core:user-emails user)))
gl-user)))
Event Timeline
ardumont
created this paste.
Jun 18 2022, 4:08 PM
2022-06-18 16:08:28 (UTC+2)
Log In to Comment