|
1 | 1 | (ns ethlance.server.graphql.resolvers |
2 | 2 | (:require |
3 | 3 | [camel-snake-kebab.core] |
| 4 | + [cljs-ipfs-api.files :as ipfs-files] |
4 | 5 | [clojure.string :as string] |
5 | 6 | [district.graphql-utils :as graphql-utils] |
6 | 7 | [district.server.async-db :as db :include-macros true] |
|
9 | 10 | [ethlance.server.db :as ethlance-db] |
10 | 11 | [ethlance.server.event-replay-queue :as replay-queue] |
11 | 12 | [ethlance.server.graphql.authorization :as authorization] |
| 13 | + [ethlance.server.ipfs :as ipfs] |
12 | 14 | [ethlance.server.syncer :as syncer] |
13 | 15 | [ethlance.shared.spec :refer [validate-keys]] |
14 | 16 | [honeysql.core :as sql] |
|
1261 | 1263 | user))) |
1262 | 1264 |
|
1263 | 1265 |
|
| 1266 | +(defn data-to-buffer [data] |
| 1267 | + (let [matcher (re-matches #"data:(\w+/\w+);base64,(.+)" data)] |
| 1268 | + (if matcher |
| 1269 | + (let [base64-image (get matcher 2)] |
| 1270 | + (js/Buffer.from base64-image "base64")) |
| 1271 | + (ipfs/to-buffer data)))) |
| 1272 | + |
| 1273 | + |
| 1274 | +(defn upload-data-mutation |
| 1275 | + [_ {:keys [data]} _] |
| 1276 | + (js/Promise. |
| 1277 | + (fn [resolve reject] |
| 1278 | + (ipfs-files/add (data-to-buffer data) |
| 1279 | + (fn [error result] |
| 1280 | + (if (or error (empty? result)) |
| 1281 | + (let [err-txt "Error when adding data to ipfs"] |
| 1282 | + (log/error err-txt {:result result |
| 1283 | + :error error |
| 1284 | + :data data} |
| 1285 | + :upload-data-mutation) |
| 1286 | + (println ">>> upload-data-mutation REJECT") |
| 1287 | + (reject err-txt)) |
| 1288 | + (resolve (:Hash result)))))))) |
| 1289 | + |
1264 | 1290 | (defn replay-events |
1265 | 1291 | [_ _ _] |
1266 | 1292 | (db/with-async-resolver-tx conn |
|
1363 | 1389 | :removeJobProposal (require-auth remove-job-proposal-mutation) |
1364 | 1390 | :replayEvents replay-events |
1365 | 1391 | :githubSignUp (require-auth github-signup-mutation) |
1366 | | - :linkedinSignUp (require-auth linkedin-signup-mutation)} |
| 1392 | + :linkedinSignUp (require-auth linkedin-signup-mutation) |
| 1393 | + :uploadData (require-auth upload-data-mutation)} |
1367 | 1394 | ;; :Date ; TODO: https://www.apollographql.com/docs/apollo-server/schema/custom-scalars/#example-the-date-scalar |
1368 | 1395 | }) |
0 commit comments