move logout-method to api-service

This commit is contained in:
tekh 2025-09-19 13:36:47 +02:00
parent f04fcde7b9
commit 62411b4d2b
4 changed files with 10 additions and 16 deletions

View File

@ -71,4 +71,12 @@ async function setLanguage(language) {
if (response.redirected)
redirect(response.url);
});
}
function logout() {
return postRequest(`/auth/logout`)
.then(res => {
if (res.ok)
window.location.href = "/";
});
}

View File

@ -1 +1 @@
function sendRequest(n,t,i=undefined){const r={credentials:"include",method:n,headers:{"X-XSRF-TOKEN":env.xsrfToken}};return i!==undefined&&(r.body=JSON.stringify(i),r.headers["Content-Type"]="application/json"),fetch(t,r)}function getRequest(n){return sendRequest("GET",n)}function postRequest(n,t=undefined){return sendRequest("POST",n,t)}function redirect(n){window.location.href=n}function signEnvelope(n){return postRequest(`/api/annotation`,n)}function rejectEnvelope(n){return postRequest(url.reject,n)}function shareEnvelope(n,t){return postRequest(url.share,{receiverMail:n,dateValid:t})}function redirRejected(){redirect(url.rejectRedir)}async function setLanguage(n){const t=await getRequest("/api/localization/lang").then(n=>n.json()).then(t=>t.includes(n));t&&postRequest(`/api/localization/lang/${n}`).then(n=>{n.redirected&&redirect(n.url)})}const env=Object.freeze({xsrfToken:document.getElementsByName("__RequestVerificationToken")[0].value,envKey:document.querySelector('meta[name="env-key"]').getAttribute("content")}),url=Object.freeze({reject:`/api/annotation/reject`,rejectRedir:`/envelope/${env.envKey}`,share:`/api/readonly`});
function sendRequest(n,t,i=undefined){const r={credentials:"include",method:n,headers:{"X-XSRF-TOKEN":env.xsrfToken}};return i!==undefined&&(r.body=JSON.stringify(i),r.headers["Content-Type"]="application/json"),fetch(t,r)}function getRequest(n){return sendRequest("GET",n)}function postRequest(n,t=undefined){return sendRequest("POST",n,t)}function redirect(n){window.location.href=n}function signEnvelope(n){return postRequest(`/api/annotation`,n)}function rejectEnvelope(n){return postRequest(url.reject,n)}function shareEnvelope(n,t){return postRequest(url.share,{receiverMail:n,dateValid:t})}function redirRejected(){redirect(url.rejectRedir)}async function setLanguage(n){const t=await getRequest("/api/localization/lang").then(n=>n.json()).then(t=>t.includes(n));t&&postRequest(`/api/localization/lang/${n}`).then(n=>{n.redirected&&redirect(n.url)})}function logout(){return postRequest(`/auth/logout`).then(n=>{n.ok&&(window.location.href="/")})}const env=Object.freeze({xsrfToken:document.getElementsByName("__RequestVerificationToken")[0].value,envKey:document.querySelector('meta[name="env-key"]').getAttribute("content")}),url=Object.freeze({reject:`/api/annotation/reject`,rejectRedir:`/envelope/${env.envKey}`,share:`/api/readonly`});

View File

@ -5,20 +5,6 @@ function getCsrfToken() {
return { 'X-XSRF-TOKEN': document.getElementsByName('__RequestVerificationToken')[0].value }
}
async function logout() {
return await fetch(`/auth/logout`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
}).then(res => {
if (res.ok)
window.location.href = "/";
});
}
async function getAnnotationParams(leftInInch = 0, topInInch = 0, inchToPointFactor = 72) {
const annotParams = await fetch(`${window.location.origin}/api/Config/Annotations`, {

View File

@ -1 +1 @@
function getCsrfToken(){return{"X-XSRF-TOKEN":document.getElementsByName("__RequestVerificationToken")[0].value}}async function logout(){return await fetch(`/auth/logout`,{method:"POST",headers:{"Content-Type":"application/json"}}).then(n=>{n.ok&&(window.location.href="/")})}async function getAnnotationParams(n=0,t=0,i=72){var f,r;const u=await fetch(`${window.location.origin}/api/Config/Annotations`,{credentials:"include",method:"GET"}).then(n=>n.json());for(f in u)r=u[f],r.width*=i,r.height*=i,r.left+=n-.7,r.left*=i,r.top+=t-.5,r.top*=i;return u}
function getCsrfToken(){return{"X-XSRF-TOKEN":document.getElementsByName("__RequestVerificationToken")[0].value}}async function getAnnotationParams(n=0,t=0,i=72){var f,r;const u=await fetch(`${window.location.origin}/api/Config/Annotations`,{credentials:"include",method:"GET"}).then(n=>n.json());for(f in u)r=u[f],r.width*=i,r.height*=i,r.left+=n-.7,r.left*=i,r.top+=t-.5,r.top*=i;return u}