-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
54 lines (44 loc) · 1.63 KB
/
scripts.js
File metadata and controls
54 lines (44 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
document.getElementById('uploadForm').addEventListener('submit', function(event) {
event.preventDefault();
let mangaTitle = document.getElementById('mangaTitle').value;
let description = document.getElementById('description').value;
let mangaFiles = document.getElementById('mangaFiles').files;
if (mangaFiles.length > 0) {
let formData = new FormData();
formData.append('mangaTitle', mangaTitle);
formData.append('description', description);
for (let i = 0; i < mangaFiles.length; i++) {
formData.append('mangaFiles', mangaFiles[i]);
}
// Send the data to the server
fetch('/upload', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('Manga uploaded successfully!');
displayManga(data.manga);
} else {
alert('Upload failed.');
}
})
.catch(error => console.error('Error:', error));
}
});
function displayManga(manga) {
const gallery = document.getElementById('gallery');
let mangaItem = document.createElement('div');
mangaItem.classList.add('manga-item');
let title = document.createElement('h3');
title.innerText = manga.title;
let desc = document.createElement('p');
desc.innerText = manga.description;
let img = document.createElement('img');
img.src = `/uploads/${manga.fileName}`;
mangaItem.appendChild(title);
mangaItem.appendChild(desc);
mangaItem.appendChild(img);
gallery.appendChild(mangaItem);
}