Restructure corpora blueprint

This commit is contained in:
Patrick Jentsch
2024-12-16 11:39:54 +01:00
parent 6c1f48eb2f
commit c405061574
8 changed files with 100 additions and 319 deletions

View File

@ -5,53 +5,89 @@ nopaque.app.endpoints.Corpora = class Corpora {
this.socket = io('/corpora', {transports: ['websocket'], upgrade: false});
}
async delete(id) {
const response = await this.socket.emitWithAck('delete', id);
async delete(corpusId) {
const options = {
headers: {
Accept: 'application/json'
},
method: 'DELETE'
};
if (response.status != 202) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
const response = await fetch(`/corpora/${corpusId}`, options);
const data = await response.json();
return response.body;
if (!response.ok) {throw new Error(`${data.name}: ${data.description}`);}
return data;
}
async build(id) {
const response = await this.socket.emitWithAck('build', id);
async build(corpusId) {
const options = {
headers: {
Accept: 'application/json'
},
method: 'POST'
};
if (response.status != 202) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
const response = await fetch(`/corpora/${corpusId}/build`, options);
const data = await response.json();
return response.body;
if (!response.ok) {throw new Error(`${data.name}: ${data.description}`);}
return data;
}
async getStopwords() {
const response = await this.socket.emitWithAck('get_stopwords');
async getStopwords(corpusId) {
const options = {
headers: {
Accept: 'application/json'
}
};
if (response.status != 200) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
const response = await fetch(`/corpora/${corpusId}/analysis/stopwords`, options);
const data = await response.json();
return response.body;
if (!response.ok) {throw new Error(`${data.name}: ${data.description}`);}
return data;
}
async createShareLink(id, expirationDate, roleName) {
const response = await this.socket.emitWithAck('create_share_link', id, expirationDate, roleName);
async createShareLink(corpusId, expirationDate, roleName) {
const options = {
body: JSON.stringify({
'expiration_date': expirationDate,
'role_name': roleName
}),
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
method: 'POST'
};
if (response.status != 200) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
const response = await fetch(`/corpora/${corpusId}/create-share-link`, options);
const data = await response.json();
return response.body;
if (!response.ok) {throw new Error(`${data.name}: ${data.description}`);}
return data;
}
async setIsPublic(id, newValue) {
const response = await this.socket.emitWithAck('set_is_public', id, newValue);
async updateIsPublic(corpusId, newValue) {
const options = {
body: JSON.stringify(newValue),
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
method: 'PUT',
};
if (response.status != 200) {
throw new Error(`[${response.status}] ${response.statusText}`);
}
const response = await fetch(`/corpora/${corpusId}/is-public`, options);
const data = await response.json();
return response.body;
if (!response.ok) {throw new Error(`${data.name}: ${data.description}`);}
return data;
}
}

View File

@ -73,7 +73,7 @@ nopaque.corpus_analysis.StaticVisualizationExtension = class StaticVisualization
}
async getStopwords() {
const stopwords = await app.corpora.getStopwords();
const stopwords = await app.corpora.getStopwords(this.app.corpusId);
this.data.originalStopwords = structuredClone(stopwords);
this.data.stopwords = structuredClone(stopwords);
return stopwords;