multimodalart HF Staff commited on
Commit
9cc9e49
·
1 Parent(s): aa2eedb

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +20 -56
index.html CHANGED
@@ -1,62 +1,26 @@
1
- <!DOCTYPE html>
2
- <html>
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
- dropZone.ondragover = function (event) {
25
- event.preventDefault();
26
- this.style.backgroundColor = '#ccc';
27
- };
28
 
29
- dropZone.ondrop = function (event) {
30
- event.preventDefault();
31
- this.style.backgroundColor = '#fff';
32
 
33
- let items = event.dataTransfer.items;
34
- for (let i = 0; i < items.length; i++) {
35
- let item = items[i].webkitGetAsEntry();
36
- if (item) {
37
- traverseFileTree(item);
38
- }
39
- }
40
- };
41
 
42
- function traverseFileTree(item, path = '') {
43
- if (item.isFile) {
44
- // Get file
45
- item.file(function(file) {
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
- </script>
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>