diff --git a/.gitignore b/.gitignore index 713b34f..5ee4716 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ _*.css node_modules/ *.min.css /api/apis.json - +/api_hash diff --git a/README.md b/README.md index 0fe336d..f957ef8 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,7 @@

- Netlify Status - -

+ Netlify Status

### [My website's](https://www.ari-web.xyz/) source code. @@ -25,6 +23,16 @@ 6. Edit all stuff that is `ARI-WEB-SPECIFIC` in [netlify.toml](/netlify.toml) 7. Publish on [netlify](https://netlify.com/) +# API hashes + +If you want to call to a very expensive API it might become +slow, so there's hashes for them, they are sha256 hashes of +those JSON files in the api + +So what you do, replace all `.` in the API name with \_, +then make the request to `/api_hash/....txt` and you will +get the hash, for example: + # Usage API The [usage api](https://www.ari-web.xyz/api/usage.json) diff --git a/netlify.toml b/netlify.toml index aef52be..7afccd8 100644 --- a/netlify.toml +++ b/netlify.toml @@ -174,6 +174,13 @@ Access-Control-Allow-Origin = "*" Access-Control-Allow-Methods = "GET" +[[headers]] + for = "/api_hash/*" + + [headers.values] + Access-Control-Allow-Origin = "*" + Access-Control-Allow-Methods = "GET" + [[headers]] for = "/*" diff --git a/scripts/apis.sh b/scripts/apis.sh index 146fd18..705c6e8 100755 --- a/scripts/apis.sh +++ b/scripts/apis.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env sh +#!/usr/bin/env bash set -e @@ -22,6 +22,18 @@ main() { } >"$apis" echo 'done' + + printf ' * %s... ' 'Generating api hashes' + + mkdir -p -- api_hash + rm -rf -- api_hash/* + + for api in api/*; do + api_base="${api##*/}" + sha256sum "$api" | awk '{ print $1 }' >"api_hash/${api_base//./_}.txt" + done + + echo 'done' } main "$@"