aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoradam <adam@>2021-02-12 13:24:58 +0200
committeradam <adam@>2021-02-12 13:24:58 +0200
commit907a4604fd7b8415c166b0949f059da9a5463554 (patch)
treebe76a12972788051b5883de8930f017c088109fa
parent077cab20146bf7cb26c330465fbd56cc0e0ddada (diff)
parent5c4c710eb10902da89f872b41b8ffcb0faaab713 (diff)
downloadfileup-907a4604fd7b8415c166b0949f059da9a5463554.tar.gz
Merge branch 'master' of https://github.com/alexvitkov/india
-rw-r--r--index.php1
-rw-r--r--loggedin.js48
-rw-r--r--loggedin.php7
3 files changed, 47 insertions, 9 deletions
diff --git a/index.php b/index.php
index 645e31f..f8a1e14 100644
--- a/index.php
+++ b/index.php
@@ -5,6 +5,7 @@
<html>
<head>
<meta charset="utf-8">
+ <link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
<title>shady file upload</title> <link rel="stylesheet" type="text/css" href="css/style.css">
</head>
diff --git a/loggedin.js b/loggedin.js
index 8980586..436719f 100644
--- a/loggedin.js
+++ b/loggedin.js
@@ -1,21 +1,42 @@
+var FORM_ASYNC = false;
+
const upload_form = document.getElementById("upload_form");
const the_file = document.getElementById("the_file");
const filename_input = document.getElementById("filename");
const upload_btn = document.getElementById("upload_btn");
+const current_directory = document.getElementById("current_directory");
the_file.onchange = on_file_added;
-function on_file_added(e) {
+const files = [];
+
+const pending_uploads = [];
+
+function on_file_added(_e) {
if (the_file.files.length >= 1) {
filename_input.value = the_file.files[0].name;
+ if (!FORM_ASYNC) {
+ upload_form.submit();
+ return;
+ }
+
// Send the form asynchronously through the fetch api
fetch(upload_form.action, {
method: upload_form.method,
body: new FormData(upload_form)
- })
+ }).then((resp) => {
+ if (resp.status == 200) {
+ add_file_visuals(filename_input.value, true);
+ }
+ else {
+ alert("Upload failed");
+ }
+ }, () => {
+ alert("Upload failed")
+ });
+
- alert("Sent the upload request");
}
else {
alert("No files selected");
@@ -23,6 +44,27 @@ function on_file_added(e) {
}
+function add_file_visuals(name, pending) {
+ var fileDiv = document.createElement('div');
+
+ var img = document.createElement('img');
+ var filename = document.createElement('div');
+
+ img.src="/mimeicons/application-pdf.png";
+ fileDiv.classList.add('file');
+ filename.classList.add('filename');
+ filename.innerText = name;
+
+ fileDiv.appendChild(img);
+ fileDiv.appendChild(filename);
+
+ current_directory.appendChild(fileDiv);
+
+ files.push([name, fileDiv]);
+
+ return fileDiv;
+}
+
function begin_upload() {
the_file.click();
}
diff --git a/loggedin.php b/loggedin.php
index 85e59cc..74c0b10 100644
--- a/loggedin.php
+++ b/loggedin.php
@@ -1,4 +1,3 @@
-
<div>
<div class="filesystem">
<h2 style="display: flex; gap: 1rem;">
@@ -7,11 +6,7 @@
<input id="upload_btn" type="button" value="Upload" onclick="begin_upload()">
</h2>
- <div class="files">
- <div class="file">
- <img src="/mimeicons/application-pdf.png">
- <div class="filename">asdf</div>
- </div>
+ <div class="files" id="current_directory">
</div>
</div>