Added fully archive support!

This commit is contained in:
Daniel
2022-06-02 23:00:51 +04:30
parent b18ef2b905
commit 1d23855eac
10 changed files with 135 additions and 80 deletions
+46
View File
@@ -0,0 +1,46 @@
import config from '../config';
import { nanoid } from 'nanoid';
const addItem = async (name, link, tag, reFetch, onExit) => {
function isValidHttpUrl(string) {
let url;
try {
url = new URL(string);
} catch (_) {
return false;
}
return url.protocol === "http:" || url.protocol === "https:";
}
if(name !== '' && isValidHttpUrl(link) && tag !== '') {
const ADDRESS = config.API.ADDRESS + ":" + config.API.PORT;
fetch(ADDRESS + "/api", {
method: "POST",
body: JSON.stringify({
_id: nanoid(),
name: name,
title: '',
link: link,
tag: tag
}),
headers: {
"Content-type": "application/json; charset=UTF-8"
}
})
.then(res => res.text())
.then(message => {console.log(message)})
.then(() => reFetch());
onExit();
} else if(name !== '' && link !== '' && tag !== '') {
alert('Please make sure the link is valid.\n\n(i.e. starts with "http"/"https")');
}
else {
alert('Please fill all fields and make sure the link is valid.\n\n(i.e. starts with "http"/"https")');
}
}
export default addItem;