generated from calcit-lang/calcit-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Termina/token
Token API
- Loading branch information
Showing
9 changed files
with
1,121 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,5 @@ js-out/ | |
node_modules | ||
|
||
example/ | ||
|
||
secrets.cirru |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,91 @@ | ||
|
||
{} (:package |app) | ||
:configs $ {} (:init-fn |app.main/main!) (:reload-fn |app.main/reload!) (:version |0.0.1) | ||
:modules $ [] | ||
:modules $ [] |skir/ |lilac/ | ||
:entries $ {} | ||
:test $ {} (:init-fn |app.test/main!) (:reload-fn |app.test/reload!) | ||
:modules $ [] |calcit-test/ | ||
:files $ {} | ||
|app.http $ %{} :FileEntry | ||
:defs $ {} | ||
|extract-body $ %{} :CodeEntry (:doc |) | ||
:code $ quote | ||
defn extract-body (req cb) | ||
let | ||
*buf $ atom "\"" | ||
.!on req "\"data" $ fn (d) (swap! *buf str d) | ||
.!on req "\"end" $ fn () | ||
cb $ parse-cirru-edn (deref *buf) | ||
:ns $ %{} :CodeEntry (:doc |) | ||
:code $ quote (ns app.http) | ||
|app.main $ %{} :FileEntry | ||
:defs $ {} | ||
|handle-token $ %{} :CodeEntry (:doc |) | ||
:code $ quote | ||
defn handle-token (bucket app-id secret file-key cb) | ||
&let | ||
cos-obj $ new COS | ||
js-object (:SecretId app-id) (:SecretKey secret) | ||
w-js-log $ .!getObjectUrl cos-obj | ||
js-object (:Bucket bucket) (:Region "\"ap-hongkong") | ||
:Key $ str "\"cos-up/" (or file-key "\"demo0") | ||
:Method "\"PUT" | ||
:Sign true | ||
fn (err data) (js/console.log "\"COS DATA:" err data) | ||
if (some? err) | ||
cb $ {} (:code 400) | ||
:body $ {} | ||
:message $ str err | ||
cb $ {} (:code 200) | ||
:headers $ {} ("\"Access-Control-Allow-Origin" "\"*") | ||
:body $ {} | ||
:url $ .-Url data | ||
|main! $ %{} :CodeEntry (:doc |) | ||
:code $ quote | ||
defn main! () $ println "\"DO" | ||
defn main! () | ||
println "\"COS get" $ .-getAuthorization COS | ||
skir/create-server! on-request! $ {} | ||
|on-request! $ %{} :CodeEntry (:doc |) | ||
:code $ quote | ||
defn on-request! (req-data res) | ||
println $ format-cirru-edn | ||
-> req-data (dissoc :original-request) (dissoc :headers) | ||
if | ||
and | ||
= :post $ :method req-data | ||
= "\"/token" $ :path req-data | ||
let | ||
secrets $ parse-cirru-edn | ||
fs/readFileSync | ||
path/join (fileURLToPath js/import.meta.url) "\"../../secrets.cirru" | ||
, "\"utf8" | ||
data $ {} | ||
fn (cb) | ||
extract-body (:original-request req-data) | ||
fn (body) (println "\"BODY" body) | ||
if | ||
and | ||
= (:user body) (:user secrets) | ||
= (:pass body) (:pass-md5 secrets) | ||
handle-token (:bucket secrets) (:app-id secrets) (:secret secrets) (:file-key body) cb | ||
{} (:code 403) (:message "\"Not user") | ||
:headers $ {} | ||
:body $ {} (:message "\"not open for all users...") | ||
if | ||
= :options $ :method req-data | ||
{} (:code 200) (:message "\"OK") | ||
:headers $ {} ("\"Access-Control-Allow-Origin" "\"*") | ||
{} (:code 404) (:message "\"Non hit") | ||
:headers $ {} | ||
:body $ {} (:message "\"only token is impelemented") | ||
|reload! $ %{} :CodeEntry (:doc |) | ||
:code $ quote | ||
defn reload! () $ println "\"Reloaded." | ||
defn reload! () (skir/reset-req-handler! on-request!) (println "\"Reloaded.") | ||
:ns $ %{} :CodeEntry (:doc |) | ||
:code $ quote | ||
ns app.main $ :require | ||
ns app.main $ :require ("\"cos-nodejs-sdk-v5" :default COS) (skir.core :as skir) | ||
app.$meta :refer $ calcit-dirname | ||
"\"node:path" :as path | ||
"\"node:url" :refer $ fileURLToPath | ||
"\"node:fs" :as fs | ||
app.http :refer $ extract-body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import { main_$x_, reload_$x_ } from "./js-out/app.test.mjs" | ||
import { main_$x_, reload_$x_ } from "./js-out/app.main.mjs" | ||
|
||
main_$x_() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
|
||
{} | ||
:dependencies $ {} | ||
|calcit-lang/skir |main | ||
|calcit-lang/lilac |main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.