Spaces:
Running
Running
Create index.html
Browse files- index.html +57 -19
index.html
CHANGED
|
@@ -1,19 +1,57 @@
|
|
| 1 |
-
<
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<script>
|
| 2 |
+
// Use environment variable instead of hardcoding
|
| 3 |
+
const HF_TOKEN = process.env.HF_TOKEN;
|
| 4 |
+
const BUCKET = "aerovortex-storage";
|
| 5 |
+
|
| 6 |
+
async function uploadFile() {
|
| 7 |
+
const fileInput = document.getElementById('fileInput');
|
| 8 |
+
const file = fileInput.files[0];
|
| 9 |
+
if (!file) return alert("No file selected");
|
| 10 |
+
|
| 11 |
+
const url = `https://huggingface.co/api/buckets/${BUCKET}/upload/${file.name}`;
|
| 12 |
+
const response = await fetch(url, {
|
| 13 |
+
method: "PUT",
|
| 14 |
+
headers: { "Authorization": `Bearer ${HF_TOKEN}` },
|
| 15 |
+
body: file
|
| 16 |
+
});
|
| 17 |
+
|
| 18 |
+
if (response.ok) {
|
| 19 |
+
alert(`✅ Uploaded ${file.name}`);
|
| 20 |
+
await prewarmFile(file.name);
|
| 21 |
+
listFiles();
|
| 22 |
+
} else {
|
| 23 |
+
alert("❌ Upload failed");
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
async function listFiles() {
|
| 28 |
+
const url = `https://huggingface.co/api/buckets/${BUCKET}/list`;
|
| 29 |
+
const response = await fetch(url, {
|
| 30 |
+
headers: { "Authorization": `Bearer ${HF_TOKEN}` }
|
| 31 |
+
});
|
| 32 |
+
const files = await response.json();
|
| 33 |
+
|
| 34 |
+
const list = document.getElementById('fileList');
|
| 35 |
+
list.innerHTML = "";
|
| 36 |
+
files.forEach(file => {
|
| 37 |
+
const li = document.createElement("li");
|
| 38 |
+
li.className = "file-box";
|
| 39 |
+
li.innerHTML = `<a href="${file.url}" target="_blank">${file.name}</a>`;
|
| 40 |
+
list.appendChild(li);
|
| 41 |
+
});
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
async function prewarmFile(fileName) {
|
| 45 |
+
const url = `https://huggingface.co/api/buckets/${BUCKET}/prewarm`;
|
| 46 |
+
await fetch(url, {
|
| 47 |
+
method: "POST",
|
| 48 |
+
headers: {
|
| 49 |
+
"Authorization": `Bearer ${HF_TOKEN}`,
|
| 50 |
+
"Content-Type": "application/json"
|
| 51 |
+
},
|
| 52 |
+
body: JSON.stringify({ files: [fileName] })
|
| 53 |
+
});
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
listFiles();
|
| 57 |
+
</script>
|