Implemented article get endpoint

This commit is contained in:
2022-02-02 16:15:01 +01:00
parent a0a6a3b799
commit 026bf1c3bc
3 changed files with 47 additions and 3 deletions

View File

@@ -28,7 +28,7 @@ async function login(username, password) {
let result = await fetch(`${prefix}/api/login`, {
method: "POST",
body: JSON.stringify({ "username": username, "password": password }),
credentials: "include"
credentials: "same-origin"
});
switch (result.status) {
case 200:
@@ -79,6 +79,22 @@ async function search(q) {
throw unknownResponse(result);
}
}
async function getArticle(id) {
let query = [["id", id]];
let result = await fetch(`${prefix}/api/article?${buildQuery(query)}`, {
method: "GET"
});
switch (result.status) {
case 200:
return await result.json();
case 401:
throw new Error("Not authorized");
case 404:
throw new Error("Article not found");
default:
throw await unknownResponse(result);
}
}
async function uploadArticle(payload) {
let result = await fetch(`${prefix}/api/article`, {
method: "POST",