summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2020-11-27 10:55:21 +0100
committertv <tv@krebsco.de>2020-11-27 10:55:21 +0100
commit4d31a33a7241ca3aee36c8ae45f5b3992bc2555c (patch)
tree546da4a2710a2da8c2c87776fc17bdc7be971770
parentba1bc1e8d493fd785d01fe39025cfe8888d72813 (diff)
tv elm-package-proxy: add POST /all-packages
-rw-r--r--tv/2configs/elm-packages-proxy.nix63
1 files changed, 47 insertions, 16 deletions
diff --git a/tv/2configs/elm-packages-proxy.nix b/tv/2configs/elm-packages-proxy.nix
index 7961bce37..b8bbcff4b 100644
--- a/tv/2configs/elm-packages-proxy.nix
+++ b/tv/2configs/elm-packages-proxy.nix
@@ -19,6 +19,11 @@ in {
sslCertificate = cfg.sslCertificate;
sslCertificateKey = cfg.sslCertificateKey;
+ locations."/all-packages".extraConfig = ''
+ proxy_pass http://127.0.0.1:${toString config.krebs.htgen.elm-packages-proxy.port};
+ proxy_pass_header Server;
+ '';
+
locations."/all-packages/since/".extraConfig = ''
proxy_pass http://127.0.0.1:${toString config.krebs.htgen.elm-packages-proxy.port};
proxy_pass_header Server;
@@ -166,11 +171,47 @@ in {
fi
exit
;;
+ 'POST /all-packages')
+
+ response=$(mktemp -t htgen.$$.elm-packages-proxy.all-packages.XXXXXXXX)
+ trap "rm $response >&2" EXIT
+
+ {
+ # upstream packages
+ curl -fsS https://package.elm-lang.org"$Request_URI"
+
+ # private packages
+ (cd ${cfg.packageDir}; find -mindepth 3 -maxdepth 3) |
+ jq -Rs '
+ split("\n") |
+ map(
+ select(.!="") |
+ match("^\\./(?<author>[^/]+)/(?<pname>[^/]+)/(?<version>[^/]+)$").captures |
+ map({key:.name,value:.string}) |
+ from_entries
+ ) |
+ reduce .[] as $item ({};
+ ($item|"\(.author)/\(.pname)") as $name |
+ . + { "\($name)": ((.[$name] // []) + [$item.version]) }
+ )
+ '
+ } |
+ jq -cs add > $response
+
+ file_response 200 OK "$response" 'application/json; charset=UTF-8'
+ exit
+ ;;
'POST /all-packages/since/'*)
- my_packages=$(
- cd ${cfg.packageDir}
- find -mindepth 3 -maxdepth 3 |
+ response=$(mktemp -t htgen.$$.elm-packages-proxy.all-packages.XXXXXXXX)
+ trap "rm $response >&2" EXIT
+
+ {
+ # upstream packages
+ curl -fsS https://package.elm-lang.org"$Request_URI"
+
+ # private packages
+ (cd ${cfg.packageDir}; find -mindepth 3 -maxdepth 3) |
jq -Rs '
split("\n") |
map(
@@ -180,20 +221,10 @@ in {
sort_by(split("@") | [.[0]]+(.[1]|split("."))) |
reverse
'
- )
-
- new_upstream_packages=$(
- curl -fsS https://package.elm-lang.org"$Request_URI"
- )
-
- response=$(
- jq -n \
- --argjson my_packages "$my_packages" \
- --argjson new_upstream_packages "$new_upstream_packages" \
- '$new_upstream_packages + $my_packages'
- )
+ } |
+ jq -cs add > $response
- string_response 200 OK "$response" 'application/json; charset=UTF-8'
+ file_response 200 OK "$response" 'application/json; charset=UTF-8'
exit
;;
esac