mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-17 15:40:12 +01:00
Move static web assets to /web dir
This commit is contained in:
parent
130429b10a
commit
41ce5a3b32
13 changed files with 1 additions and 1 deletions
91
web/static/api.js
Normal file
91
web/static/api.js
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
|
||||
const apiFactory = () => {
|
||||
const baseUrl = "http://localhost:8080/v1";
|
||||
let token = "";
|
||||
|
||||
const headers = () => ({
|
||||
'Authorization': 'Bearer ' + token
|
||||
});
|
||||
|
||||
const checkLogin = async () => {
|
||||
const token = localStorage.getItem("token");
|
||||
|
||||
if (token) {
|
||||
const isLoggedIn = await logIn(token);
|
||||
return isLoggedIn;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const logIn = async (password, remember) => {
|
||||
token = password;
|
||||
const response = await fetch(baseUrl + "/list", {
|
||||
credentials: 'include',
|
||||
headers: headers()
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
if (remember === true) {
|
||||
localStorage.setItem("token", password);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
token = "";
|
||||
return false;
|
||||
};
|
||||
|
||||
const logOut = () => {
|
||||
localStorage.clear();
|
||||
};
|
||||
|
||||
const list = async () => {
|
||||
const response = await fetch(baseUrl + "/list", {
|
||||
credentials: 'include',
|
||||
headers: headers()
|
||||
});
|
||||
const data = await response.json();
|
||||
return data;
|
||||
};
|
||||
|
||||
const check = async (containerId) => {
|
||||
const requestData = {
|
||||
ContainerId: containerId
|
||||
};
|
||||
const response = await fetch(baseUrl + "/check", {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
...headers(),
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(requestData)
|
||||
});
|
||||
const data = await response.json();
|
||||
return data;
|
||||
};
|
||||
|
||||
const update = async (images) => {
|
||||
let updateUrl = new URL(baseUrl + "/update");
|
||||
|
||||
if (images instanceof Array) {
|
||||
images.map(image => updateUrl.searchParams.append("image", image));
|
||||
}
|
||||
|
||||
const response = await fetch(updateUrl.toString(), {
|
||||
credentials: 'include',
|
||||
headers: headers(),
|
||||
});
|
||||
|
||||
return response.ok;
|
||||
};
|
||||
|
||||
return {
|
||||
checkLogin,
|
||||
logIn,
|
||||
logOut,
|
||||
list,
|
||||
check,
|
||||
update
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue