Spaces:
Sleeping
Sleeping
Upload 12 files
Browse files- README.md +3 -8
- dashboardlogic.js +33 -15
- logic.js +22 -4
README.md
CHANGED
|
@@ -1,8 +1,3 @@
|
|
| 1 |
-
---
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
colorFrom: blue
|
| 5 |
-
colorTo: purple
|
| 6 |
-
sdk: docker
|
| 7 |
-
pinned: false
|
| 8 |
-
---
|
|
|
|
| 1 |
+

|
| 2 |
+
# Animated-attractive-Login-Page
|
| 3 |
+
Creating Animated Login Page with awesome background HTML & CSS.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dashboardlogic.js
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
|
|
| 1 |
import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client@1.9.0/dist/index.min.js";
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
let client;
|
| 4 |
let currentUser = null;
|
| 5 |
let currentPassword = null;
|
|
@@ -58,7 +76,7 @@ async function initDashboard() {
|
|
| 58 |
async function loadUserData() {
|
| 59 |
try {
|
| 60 |
console.log('Loading user data...');
|
| 61 |
-
const result = await client.predict("/search_user", { user_id: currentUser });
|
| 62 |
const [log, isDev, isPro, isTester, capacityUsed, usedTotal] = result.data;
|
| 63 |
|
| 64 |
// Determine role
|
|
@@ -105,10 +123,10 @@ async function loadFiles() {
|
|
| 105 |
try {
|
| 106 |
console.log('Loading files...');
|
| 107 |
loading(true);
|
| 108 |
-
const result = await client.predict("/get_files_secure", {
|
| 109 |
user_id: currentUser,
|
| 110 |
password: currentPassword,
|
| 111 |
-
});
|
| 112 |
// API returns [dropdown, status]
|
| 113 |
const dropdownData = result.data[0];
|
| 114 |
console.log('Raw dropdownData:', dropdownData);
|
|
@@ -282,11 +300,11 @@ async function loadPreviewContent(file) {
|
|
| 282 |
previewContainer.innerHTML = '<span style="color:#aaa">Loading preview...</span>';
|
| 283 |
try {
|
| 284 |
// Try /handle_preview_secure first
|
| 285 |
-
const result = await client.predict("/handle_preview_secure", {
|
| 286 |
user_id: currentUser,
|
| 287 |
password: currentPassword,
|
| 288 |
filename: file.name,
|
| 289 |
-
});
|
| 290 |
// result.data: [file, localPath, html, image, code]
|
| 291 |
let previewHtml = '';
|
| 292 |
if (result.data[3] && typeof result.data[3] === 'string' && result.data[3].startsWith('data:image')) {
|
|
@@ -300,11 +318,11 @@ async function loadPreviewContent(file) {
|
|
| 300 |
previewHtml = `<pre class="pv-code">${escapeHtml(result.data[4])}</pre>`;
|
| 301 |
} else {
|
| 302 |
// Try /get_preview_text_action for text preview
|
| 303 |
-
const textResult = await client.predict("/get_preview_text_action", {
|
| 304 |
user_id: currentUser,
|
| 305 |
password: currentPassword,
|
| 306 |
filename: file.name,
|
| 307 |
-
});
|
| 308 |
if (textResult.data && typeof textResult.data[0] === 'string' && textResult.data[0].length > 0) {
|
| 309 |
previewHtml = `<pre class="pv-text">${escapeHtml(textResult.data[0])}</pre>`;
|
| 310 |
} else {
|
|
@@ -336,11 +354,11 @@ async function deleteFile(id) {
|
|
| 336 |
|
| 337 |
try {
|
| 338 |
loading(true);
|
| 339 |
-
const result = await client.predict("/delete_file_secure", {
|
| 340 |
user_id: currentUser,
|
| 341 |
password: currentPassword,
|
| 342 |
filename: file.name,
|
| 343 |
-
});
|
| 344 |
|
| 345 |
console.log('Deleted:', file.name);
|
| 346 |
|
|
@@ -395,11 +413,11 @@ async function downloadFile(id) {
|
|
| 395 |
try {
|
| 396 |
loading(true);
|
| 397 |
// Use /get_download_link_action to get the raw download link
|
| 398 |
-
const result = await client.predict("/get_download_link_action", {
|
| 399 |
user_id: currentUser,
|
| 400 |
password: currentPassword,
|
| 401 |
filename: file.name,
|
| 402 |
-
});
|
| 403 |
const fileUrl = result.data[0];
|
| 404 |
if (typeof fileUrl === 'string' && (fileUrl.startsWith('http') || fileUrl.startsWith('https'))) {
|
| 405 |
// Fetch as blob to force download, with optional Hugging Face token
|
|
@@ -455,12 +473,12 @@ async function handleUpload(input) {
|
|
| 455 |
loading(true);
|
| 456 |
// Use File object and pass custom_name for filename preservation
|
| 457 |
console.log('Uploading file:', file, 'type:', file.constructor.name);
|
| 458 |
-
const result = await client.predict("/upload_file_secure", {
|
| 459 |
user_id: currentUser,
|
| 460 |
password: currentPassword,
|
| 461 |
filepath: file,
|
| 462 |
custom_name: file.name,
|
| 463 |
-
});
|
| 464 |
console.log('Uploaded:', file.name);
|
| 465 |
// Update storage
|
| 466 |
const [status, capacityUsed, usedTotal] = result.data;
|
|
@@ -529,10 +547,10 @@ async function changePassword() {
|
|
| 529 |
|
| 530 |
try {
|
| 531 |
loading(true);
|
| 532 |
-
const result = await client.predict("/update_password", {
|
| 533 |
user_id: currentUser,
|
| 534 |
new_password: p1,
|
| 535 |
-
});
|
| 536 |
|
| 537 |
if (result.data[0].toLowerCase().includes('success') || result.data[0].toLowerCase().includes('updated')) {
|
| 538 |
currentPassword = p1;
|
|
|
|
| 1 |
+
|
| 2 |
import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client@1.9.0/dist/index.min.js";
|
| 3 |
|
| 4 |
+
// Read/write tokens from sessionStorage
|
| 5 |
+
function getReadToken() {
|
| 6 |
+
return sessionStorage.getItem('hf_read_token') || '';
|
| 7 |
+
}
|
| 8 |
+
function getWriteToken() {
|
| 9 |
+
return sessionStorage.getItem('hf_write_token') || '';
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
// Helper to add tokens to every API call
|
| 13 |
+
function withTokens(obj = {}) {
|
| 14 |
+
return {
|
| 15 |
+
...obj,
|
| 16 |
+
read_token: getReadToken(),
|
| 17 |
+
write_token: getWriteToken(),
|
| 18 |
+
};
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
let client;
|
| 22 |
let currentUser = null;
|
| 23 |
let currentPassword = null;
|
|
|
|
| 76 |
async function loadUserData() {
|
| 77 |
try {
|
| 78 |
console.log('Loading user data...');
|
| 79 |
+
const result = await client.predict("/search_user", withTokens({ user_id: currentUser }));
|
| 80 |
const [log, isDev, isPro, isTester, capacityUsed, usedTotal] = result.data;
|
| 81 |
|
| 82 |
// Determine role
|
|
|
|
| 123 |
try {
|
| 124 |
console.log('Loading files...');
|
| 125 |
loading(true);
|
| 126 |
+
const result = await client.predict("/get_files_secure", withTokens({
|
| 127 |
user_id: currentUser,
|
| 128 |
password: currentPassword,
|
| 129 |
+
}));
|
| 130 |
// API returns [dropdown, status]
|
| 131 |
const dropdownData = result.data[0];
|
| 132 |
console.log('Raw dropdownData:', dropdownData);
|
|
|
|
| 300 |
previewContainer.innerHTML = '<span style="color:#aaa">Loading preview...</span>';
|
| 301 |
try {
|
| 302 |
// Try /handle_preview_secure first
|
| 303 |
+
const result = await client.predict("/handle_preview_secure", withTokens({
|
| 304 |
user_id: currentUser,
|
| 305 |
password: currentPassword,
|
| 306 |
filename: file.name,
|
| 307 |
+
}));
|
| 308 |
// result.data: [file, localPath, html, image, code]
|
| 309 |
let previewHtml = '';
|
| 310 |
if (result.data[3] && typeof result.data[3] === 'string' && result.data[3].startsWith('data:image')) {
|
|
|
|
| 318 |
previewHtml = `<pre class="pv-code">${escapeHtml(result.data[4])}</pre>`;
|
| 319 |
} else {
|
| 320 |
// Try /get_preview_text_action for text preview
|
| 321 |
+
const textResult = await client.predict("/get_preview_text_action", withTokens({
|
| 322 |
user_id: currentUser,
|
| 323 |
password: currentPassword,
|
| 324 |
filename: file.name,
|
| 325 |
+
}));
|
| 326 |
if (textResult.data && typeof textResult.data[0] === 'string' && textResult.data[0].length > 0) {
|
| 327 |
previewHtml = `<pre class="pv-text">${escapeHtml(textResult.data[0])}</pre>`;
|
| 328 |
} else {
|
|
|
|
| 354 |
|
| 355 |
try {
|
| 356 |
loading(true);
|
| 357 |
+
const result = await client.predict("/delete_file_secure", withTokens({
|
| 358 |
user_id: currentUser,
|
| 359 |
password: currentPassword,
|
| 360 |
filename: file.name,
|
| 361 |
+
}));
|
| 362 |
|
| 363 |
console.log('Deleted:', file.name);
|
| 364 |
|
|
|
|
| 413 |
try {
|
| 414 |
loading(true);
|
| 415 |
// Use /get_download_link_action to get the raw download link
|
| 416 |
+
const result = await client.predict("/get_download_link_action", withTokens({
|
| 417 |
user_id: currentUser,
|
| 418 |
password: currentPassword,
|
| 419 |
filename: file.name,
|
| 420 |
+
}));
|
| 421 |
const fileUrl = result.data[0];
|
| 422 |
if (typeof fileUrl === 'string' && (fileUrl.startsWith('http') || fileUrl.startsWith('https'))) {
|
| 423 |
// Fetch as blob to force download, with optional Hugging Face token
|
|
|
|
| 473 |
loading(true);
|
| 474 |
// Use File object and pass custom_name for filename preservation
|
| 475 |
console.log('Uploading file:', file, 'type:', file.constructor.name);
|
| 476 |
+
const result = await client.predict("/upload_file_secure", withTokens({
|
| 477 |
user_id: currentUser,
|
| 478 |
password: currentPassword,
|
| 479 |
filepath: file,
|
| 480 |
custom_name: file.name,
|
| 481 |
+
}));
|
| 482 |
console.log('Uploaded:', file.name);
|
| 483 |
// Update storage
|
| 484 |
const [status, capacityUsed, usedTotal] = result.data;
|
|
|
|
| 547 |
|
| 548 |
try {
|
| 549 |
loading(true);
|
| 550 |
+
const result = await client.predict("/update_password", withTokens({
|
| 551 |
user_id: currentUser,
|
| 552 |
new_password: p1,
|
| 553 |
+
}));
|
| 554 |
|
| 555 |
if (result.data[0].toLowerCase().includes('success') || result.data[0].toLowerCase().includes('updated')) {
|
| 556 |
currentPassword = p1;
|
logic.js
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
|
|
| 1 |
import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client@1.9.0/dist/index.min.js";
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
const loginForm = document.getElementById('loginForm');
|
| 4 |
const signupForm = document.getElementById('signupForm');
|
| 5 |
|
|
@@ -45,10 +63,10 @@ if (signupForm) {
|
|
| 45 |
|
| 46 |
try {
|
| 47 |
const client = await Client.connect("pockit-cloud/main");
|
| 48 |
-
const result = await client.predict("/create_user", {
|
| 49 |
user_id: user,
|
| 50 |
password: pass,
|
| 51 |
-
});
|
| 52 |
|
| 53 |
// Debug: log the result
|
| 54 |
console.log("/create_user result:", result.data);
|
|
@@ -88,10 +106,10 @@ if (loginForm) {
|
|
| 88 |
|
| 89 |
try {
|
| 90 |
const client = await Client.connect("pockit-cloud/main");
|
| 91 |
-
const result = await client.predict("/get_files_secure", {
|
| 92 |
user_id: user,
|
| 93 |
password: pass,
|
| 94 |
-
});
|
| 95 |
|
| 96 |
// Status message is at index 1 for get_files_secure
|
| 97 |
const status = result.data[1].toLowerCase();
|
|
|
|
| 1 |
+
|
| 2 |
import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client@1.9.0/dist/index.min.js";
|
| 3 |
|
| 4 |
+
// Read/write tokens from sessionStorage
|
| 5 |
+
function getReadToken() {
|
| 6 |
+
return sessionStorage.getItem('hf_read_token') || '';
|
| 7 |
+
}
|
| 8 |
+
function getWriteToken() {
|
| 9 |
+
return sessionStorage.getItem('hf_write_token') || '';
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
+
// Helper to add tokens to every API call
|
| 13 |
+
function withTokens(obj = {}) {
|
| 14 |
+
return {
|
| 15 |
+
...obj,
|
| 16 |
+
read_token: getReadToken(),
|
| 17 |
+
write_token: getWriteToken(),
|
| 18 |
+
};
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
const loginForm = document.getElementById('loginForm');
|
| 22 |
const signupForm = document.getElementById('signupForm');
|
| 23 |
|
|
|
|
| 63 |
|
| 64 |
try {
|
| 65 |
const client = await Client.connect("pockit-cloud/main");
|
| 66 |
+
const result = await client.predict("/create_user", withTokens({
|
| 67 |
user_id: user,
|
| 68 |
password: pass,
|
| 69 |
+
}));
|
| 70 |
|
| 71 |
// Debug: log the result
|
| 72 |
console.log("/create_user result:", result.data);
|
|
|
|
| 106 |
|
| 107 |
try {
|
| 108 |
const client = await Client.connect("pockit-cloud/main");
|
| 109 |
+
const result = await client.predict("/get_files_secure", withTokens({
|
| 110 |
user_id: user,
|
| 111 |
password: pass,
|
| 112 |
+
}));
|
| 113 |
|
| 114 |
// Status message is at index 1 for get_files_secure
|
| 115 |
const status = result.data[1].toLowerCase();
|