Spaces:
Running
Running
Commit
·
9cc9e49
1
Parent(s):
aa2eedb
Update index.html
Browse files- index.html +20 -56
index.html
CHANGED
@@ -1,62 +1,26 @@
|
|
1 |
-
|
2 |
-
<
|
3 |
-
<head>
|
4 |
-
<title>Drag and Drop Demo</title>
|
5 |
-
<style>
|
6 |
-
#drop_zone {
|
7 |
-
width: 300px;
|
8 |
-
height: 200px;
|
9 |
-
border: 2px dashed #aaa;
|
10 |
-
line-height: 200px;
|
11 |
-
text-align: center;
|
12 |
-
}
|
13 |
-
</style>
|
14 |
-
</head>
|
15 |
-
<body>
|
16 |
-
<div id="drop_zone">Drop files or folders here</div>
|
17 |
-
<ul id="file_list"></ul>
|
18 |
-
<input type="file" id="fileInput" multiple />
|
19 |
-
<input type="file" id="dirInput" webkitdirectory="" />
|
20 |
-
<script>
|
21 |
-
let dropZone = document.getElementById('drop_zone');
|
22 |
-
let fileList = document.getElementById('file_list');
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
this.style.backgroundColor = '#ccc';
|
27 |
-
};
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
let listItem = document.createElement('li');
|
47 |
-
listItem.textContent = path + file.name;
|
48 |
-
fileList.appendChild(listItem);
|
49 |
-
});
|
50 |
-
} else if (item.isDirectory) {
|
51 |
-
// Get folder contents
|
52 |
-
let dirReader = item.createReader();
|
53 |
-
dirReader.readEntries(function(entries) {
|
54 |
-
for (let i=0; i<entries.length; i++) {
|
55 |
-
traverseFileTree(entries[i], path + item.name + "/");
|
56 |
-
}
|
57 |
});
|
58 |
-
}
|
59 |
}
|
60 |
-
|
61 |
-
</body>
|
62 |
-
</html>
|
|
|
1 |
+
<input type="file" id="fileInput" multiple>
|
2 |
+
<button onClick="upload()">Upload</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
<script>
|
5 |
+
// Assumes that the `uploadFiles`, `repo`, and `credentials` are available in this scope
|
|
|
|
|
6 |
|
7 |
+
async function upload() {
|
8 |
+
const input = document.getElementById('fileInput');
|
9 |
+
const files = Array.from(input.files); // Convert FileList to an Array
|
10 |
|
11 |
+
// Prompt the user for a unique upload path for each file
|
12 |
+
const filesToUpload = await Promise.all(files.map(async (file) => {
|
13 |
+
const path = prompt(`Enter the upload path for ${file.name}`);
|
14 |
+
return {
|
15 |
+
path,
|
16 |
+
content: file,
|
17 |
+
};
|
18 |
+
}));
|
19 |
|
20 |
+
await uploadFiles({
|
21 |
+
repo,
|
22 |
+
credentials,
|
23 |
+
files: filesToUpload,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
});
|
|
|
25 |
}
|
26 |
+
</script>
|
|
|
|