Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial data wish impl #56

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions virtual-programs/data.folk
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
proc sanitizeURL {url} {
set url [string map {http:// "" https:// ""} $url]
set url [string map {/ _ ? "" * "" < "" > "" : "" | "" " " ""} $url]
if {[string length $url] > 255} {
set url [string range $url 0 254]
}
return $url
}

When when /page/ has data /data/ from /address/ /lambda/ with environment /e/ {
set sanitized [sanitizeURL $address]
set path "~/page-data/$sanitized"
set path [file normalize $path]
if {[file exists $path]} {
set fileId [open $path "r"]
set data [read $fileId]
close $fileId
Claim $page has data $data from $address
} else {
set data [exec -ignorestderr curl $address]
set fileId [open $path "w"]
puts $fileId $data
close $fileId
Claim $page has data $data from $address
}
}