@@ -2,11 +2,13 @@ import base64 from "base-64";
22import formatISO from "date-fns/formatISO" ;
33
44export async function getAuthToken ( username , password ) {
5- let response = await fetch ( "/auth/token" , {
5+ let url = "/auth/token"
6+ let response = await fetch ( url , {
67 method : 'GET' ,
78 headers : {
89 'Authorization' : 'Basic ' + base64 . encode ( username + ":" + password )
9- }
10+ } ,
11+
1012 } )
1113 if ( response . ok ) {
1214 return await response . json ( ) ;
@@ -15,9 +17,13 @@ export async function getAuthToken(username, password) {
1517 }
1618}
1719
18- export async function getRecsTag ( tag , token ) {
20+ export async function getRecs ( tag , token ) {
1921 try {
20- let response = await fetch ( "/recs/tag/" + tag , {
22+ var url = "/recs"
23+ if ( tag != "" ) {
24+ url = url + "?" + new URLSearchParams ( { tag : tag } )
25+ }
26+ let response = await fetch ( url , {
2127 method : 'GET' ,
2228 headers : {
2329 'Authorization' : 'Bearer ' + token
@@ -31,7 +37,11 @@ export async function getRecsTag(tag, token) {
3137
3238export async function getHis ( id , start , end , token ) {
3339 try {
34- let response = await fetch ( "/his/" + id + "?start=" + start + "&end=" + end , {
40+ let url = `/recs/${ id } /history?` + new URLSearchParams ( {
41+ start : start ,
42+ end : end ,
43+ } )
44+ let response = await fetch ( url , {
3545 method : 'GET' ,
3646 headers : {
3747 'Authorization' : 'Bearer ' + token
@@ -50,7 +60,8 @@ export async function postHis(id, ts, value, token) {
5060 ts : formatISO ( ts ) , // We use date-fns implementation here to avoid milliseconds (Swift hates them and me)
5161 value : value
5262 } ;
53- await fetch ( "/his/" + id , {
63+ let url = `/rec/${ id } /history`
64+ await fetch ( url , {
5465 method : 'POST' ,
5566 headers : {
5667 'Authorization' : 'Bearer ' + token ,
0 commit comments