More rework

This commit is contained in:
Patrick Jentsch
2023-03-09 14:55:08 +01:00
parent fdad10991c
commit 59de68e6fa
11 changed files with 129 additions and 423 deletions

View File

@ -11,6 +11,14 @@ Requests.JSONfetch = (input, init={}) => {
fetch(input, Utils.mergeObjectsDeep(init, fixedInit))
.then(
(response) => {
if (response.ok) {
resolve(response.clone());
} else {
reject(response);
}
if (response.status === 204) {
return;
}
response.json()
.then(
(json) => {
@ -22,11 +30,6 @@ Requests.JSONfetch = (input, init={}) => {
app.flash(`[${response.status}]: ${response.statusText}`, 'error');
}
);
if (response.ok) {
resolve(response);
} else {
reject(response);
}
},
(response) => {
app.flash('Something went wrong', 'error');

View File

@ -4,9 +4,9 @@
*****************************************************************************/
Requests.corpora = {};
Requests.corpora.ent = {};
Requests.corpora.entity = {};
Requests.corpora.ent.delete = (corpusId) => {
Requests.corpora.entity.delete = (corpusId) => {
let input = `/corpora/${corpusId}`;
let init = {
method: 'DELETE'
@ -14,7 +14,7 @@ Requests.corpora.ent.delete = (corpusId) => {
return Requests.JSONfetch(input, init);
};
Requests.corpora.ent.build = (corpusId) => {
Requests.corpora.entity.build = (corpusId) => {
let input = `/corpora/${corpusId}/build`;
let init = {
method: 'POST',
@ -22,9 +22,18 @@ Requests.corpora.ent.build = (corpusId) => {
return Requests.JSONfetch(input, init);
};
Requests.corpora.ent.isPublic = {};
Requests.corpora.entity.generateShareLink = (corpusId, role, expiration) => {
let input = `/corpora/${corpusId}/generate-corpus-share-link`;
let init = {
method: 'POST',
body: JSON.stringify({role: role, expiration: expiration})
};
return Requests.JSONfetch(input, init);
};
Requests.corpora.ent.isPublic.update = (corpusId, value) => {
Requests.corpora.entity.isPublic = {};
Requests.corpora.entity.isPublic.update = (corpusId, value) => {
let input = `/corpora/${corpusId}/is_public`;
let init = {
method: 'PUT',
@ -33,46 +42,5 @@ Requests.corpora.ent.isPublic.update = (corpusId, value) => {
return Requests.JSONfetch(input, init);
};
Requests.corpora.ent.files = {};
Requests.corpora.ent.files.ent = {};
Requests.corpora.ent.files.ent.delete = (corpusId, corpusFileId) => {
let input = `/corpora/${corpusId}/files/${corpusFileId}`;
let init = {
method: 'DELETE',
};
return Requests.JSONfetch(input, init);
};
Requests.corpora.ent.followers = {};
Requests.corpora.ent.followers.add = (corpusId, usernames) => {
let input = `/corpora/${corpusId}/followers`;
let init = {
method: 'POST',
body: JSON.stringify(usernames)
};
return Requests.JSONfetch(input, init);
};
Requests.corpora.ent.followers.ent = {};
Requests.corpora.ent.followers.ent.delete = (corpusId, followerId) => {
let input = `/corpora/${corpusId}/followers/${followerId}`;
let init = {
method: 'DELETE',
};
return Requests.JSONfetch(input, init);
};
Requests.corpora.ent.followers.ent.role = {};
Requests.corpora.ent.followers.ent.role.update = (corpusId, followerId, value) => {
let input = `/corpora/${corpusId}/followers/${followerId}/role`;
let init = {
method: 'PUT',
body: JSON.stringify(value)
};
return Requests.JSONfetch(input, init);
};

View File

@ -0,0 +1,15 @@
/*****************************************************************************
* Corpora *
* Fetch requests for /corpora/<entity>/files routes *
*****************************************************************************/
Requests.corpora.entity.files = {};
Requests.corpora.entity.files.ent = {};
Requests.corpora.entity.files.ent.delete = (corpusId, corpusFileId) => {
let input = `/corpora/${corpusId}/files/${corpusFileId}`;
let init = {
method: 'DELETE',
};
return Requests.JSONfetch(input, init);
};

View File

@ -0,0 +1,35 @@
/*****************************************************************************
* Corpora *
* Fetch requests for /corpora/<entity>/followers routes *
*****************************************************************************/
Requests.corpora.entity.followers = {};
Requests.corpora.entity.followers.add = (corpusId, usernames) => {
let input = `/corpora/${corpusId}/followers`;
let init = {
method: 'POST',
body: JSON.stringify(usernames)
};
return Requests.JSONfetch(input, init);
};
Requests.corpora.entity.followers.entity = {};
Requests.corpora.entity.followers.entity.delete = (corpusId, followerId) => {
let input = `/corpora/${corpusId}/followers/${followerId}`;
let init = {
method: 'DELETE',
};
return Requests.JSONfetch(input, init);
};
Requests.corpora.entity.followers.entity.role = {};
Requests.corpora.entity.followers.entity.role.update = (corpusId, followerId, value) => {
let input = `/corpora/${corpusId}/followers/${followerId}/role`;
let init = {
method: 'PUT',
body: JSON.stringify(value)
};
return Requests.JSONfetch(input, init);
};