commit 4ea835742102cdd0cd48b4beb3e2abde09e0edc1
parent 0142e3b5104399da011915bb3cae11e77a13fc68
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Sat, 31 Aug 2024 19:06:51 -0700
Add api request path substitution
The only substituion currently provided is :user, which expands the
the current user.
Diffstat:
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/files/lib/api.js b/files/lib/api.js
@@ -42,7 +42,7 @@ function api_fetch(method, endpoint, body) {
params["body"] = JSON.stringify(body)
}
- return fetch(proto + "://" + host + "/" + version + "/" + endpoint, params)
+ return fetch(proto + "://" + host + "/" + version + "/" + requestPath(endpoint), params)
.then(verify_response)
.then(parse_response)
.then(status)
@@ -126,3 +126,18 @@ export function authorized_duration(t) {
export function logged_in() {
return authorized_duration() > 0
}
+
+function requestPath(s) {
+ let a = s.split("/")
+ let subs = {
+ ":user": localStorage.getItem("username")
+ }
+
+ for (let i in a) {
+ if (subs[a[i]] != undefined) {
+ a[i] = subs[a[i]]
+ }
+ }
+
+ return a.join("/")
+}