Add API cache validation to the API

Signed-off-by: Ari Archer <ari.web.xyz@gmail.com>
This commit is contained in:
Ari Archer 2022-09-23 01:39:49 +03:00
parent a2483d6b2b
commit c514345b91
4 changed files with 32 additions and 5 deletions

2
.gitignore vendored
View file

@ -2,4 +2,4 @@ _*.css
node_modules/
*.min.css
/api/apis.json
/api_hash

View file

@ -9,9 +9,7 @@
<p align="center">
<a href="https://app.netlify.com/sites/ari-web/deploys">
<img alt="Netlify Status" src="https://api.netlify.com/api/v1/badges/4ac67547-6444-4c67-9a54-c7f8fb28427b/deploy-status"/>
</a>
</p>
<img alt="Netlify Status" src="https://api.netlify.com/api/v1/badges/4ac67547-6444-4c67-9a54-c7f8fb28427b/deploy-status"/> </a> </p>
### [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: <https://www.ari-web.xyz/api_hash/apis_json.txt>
# Usage API
The [usage api](https://www.ari-web.xyz/api/usage.json)

View file

@ -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 = "/*"

View file

@ -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 "$@"