Split the URL into two objects as URL and environment

This commit is contained in:
tekh 2025-09-19 11:41:41 +02:00
parent 8abf8260bf
commit 4075739522
2 changed files with 17 additions and 14 deletions

View File

@ -1,15 +1,4 @@
const url = {
get reject() {
return `/api/annotation/reject`;
},
get rejectRedir() {
return `/envelope/${url.envKey}`;
},
get share() {
return `/api/readonly`;
},
const env = {
__lazyXsrfToken: new Lazy(() => document.getElementsByName('__RequestVerificationToken')[0].value),
get xsrfToken() {
return this.__lazyXsrfToken.value;
@ -18,6 +7,20 @@ const url = {
get envKey() {
return this.__lazyEnvKey.value;
}
}
const url = {
get reject() {
return `/api/annotation/reject`;
},
get rejectRedir() {
return `/envelope/${env.envKey}`;
},
get share() {
return `/api/readonly`;
}
};
function submitForm(form) {
@ -36,7 +39,7 @@ function createRequest(method, url, body, contentType = 'application/json') {
method: method,
headers: {
'Content-Type': contentType,
'X-XSRF-TOKEN': url.xsrfToken
'X-XSRF-TOKEN': env.xsrfToken
},
body: JSON.stringify(body)
})

View File

@ -1 +1 @@
function submitForm(n){fetch(n.action,{method:n.method,body:new FormData(n),headers:{"X-Requested-With":"XMLHttpRequest"}})}function createRequest(n,t,i,r="application/json"){return fetch(t,{credentials:"include",method:n,headers:{"Content-Type":r,"X-XSRF-TOKEN":t.xsrfToken},body:JSON.stringify(i)})}function createPost(n,t,i="application/json"){return createRequest("POST",n,t,i)}function rejectEnvelope(n){return createPost(url.reject,n,Content.JSON)}function redirect(n){return window.location.href=n}function redirRejected(){return redirect(url.rejectRedir)}function shareEnvelope(n,t){return createPost(url.share,{receiverMail:n,dateValid:t},Content.JSON)}const url={get reject(){return`/api/annotation/reject`},get rejectRedir(){return`/envelope/${url.envKey}`},get share(){return`/api/readonly`},__lazyXsrfToken:new Lazy(()=>document.getElementsByName("__RequestVerificationToken")[0].value),get xsrfToken(){return this.__lazyXsrfToken.value},__lazyEnvKey:new Lazy(()=>document.querySelector('meta[name="env-key"]').getAttribute("content")),get envKey(){return this.__lazyEnvKey.value}};
function submitForm(n){fetch(n.action,{method:n.method,body:new FormData(n),headers:{"X-Requested-With":"XMLHttpRequest"}})}function createRequest(n,t,i,r="application/json"){return fetch(t,{credentials:"include",method:n,headers:{"Content-Type":r,"X-XSRF-TOKEN":env.xsrfToken},body:JSON.stringify(i)})}function createPost(n,t,i="application/json"){return createRequest("POST",n,t,i)}function rejectEnvelope(n){return createPost(url.reject,n,Content.JSON)}function redirect(n){return window.location.href=n}function redirRejected(){return redirect(url.rejectRedir)}function shareEnvelope(n,t){return createPost(url.share,{receiverMail:n,dateValid:t},Content.JSON)}const env={__lazyXsrfToken:new Lazy(()=>document.getElementsByName("__RequestVerificationToken")[0].value),get xsrfToken(){return this.__lazyXsrfToken.value},__lazyEnvKey:new Lazy(()=>document.querySelector('meta[name="env-key"]').getAttribute("content")),get envKey(){return this.__lazyEnvKey.value}},url={get reject(){return`/api/annotation/reject`},get rejectRedir(){return`/envelope/${env.envKey}`},get share(){return`/api/readonly`}};