Add 2 files
Browse files- index.html +52 -67
- prompts.txt +2 -1
index.html
CHANGED
@@ -28,6 +28,9 @@
|
|
28 |
from { transform: rotate(0deg); }
|
29 |
to { transform: rotate(360deg); }
|
30 |
}
|
|
|
|
|
|
|
31 |
</style>
|
32 |
</head>
|
33 |
<body class="bg-gray-50 min-h-screen">
|
@@ -91,7 +94,7 @@
|
|
91 |
<div class="mb-4">
|
92 |
<label class="block text-sm font-medium text-gray-700 mb-1">Folder Path</label>
|
93 |
<div class="flex">
|
94 |
-
<input type="text" id="folderPath" class="flex-1 px-3 py-2 border border-gray-300 rounded-l-md focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Enter folder path or drag & drop">
|
95 |
<button id="browseBtn" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-r-md hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
|
96 |
<i class="fas fa-folder-open mr-1"></i> Browse
|
97 |
</button>
|
@@ -104,6 +107,10 @@
|
|
104 |
<p class="text-sm text-gray-500">Supports multiple files and folders</p>
|
105 |
</div>
|
106 |
|
|
|
|
|
|
|
|
|
107 |
<div class="flex justify-between">
|
108 |
<div>
|
109 |
<label class="block text-sm font-medium text-gray-700 mb-1">Prefix (optional)</label>
|
@@ -193,6 +200,8 @@
|
|
193 |
const logConsole = document.getElementById('logConsole');
|
194 |
const testConnectionBtn = document.getElementById('testConnectionBtn');
|
195 |
const connectionStatus = document.getElementById('connectionStatus');
|
|
|
|
|
196 |
|
197 |
// State variables
|
198 |
let filesToUpload = [];
|
@@ -201,8 +210,7 @@
|
|
201 |
|
202 |
// Event Listeners
|
203 |
dropzone.addEventListener('click', () => {
|
204 |
-
|
205 |
-
addLog("File selection dialog would open here in a real application");
|
206 |
});
|
207 |
|
208 |
dropzone.addEventListener('dragover', (e) => {
|
@@ -218,19 +226,40 @@
|
|
218 |
e.preventDefault();
|
219 |
dropzone.classList.remove('active');
|
220 |
|
221 |
-
|
222 |
-
const files = []; // Array.from(e.dataTransfer.files);
|
223 |
if (files.length > 0) {
|
224 |
filesToUpload = files;
|
|
|
225 |
updateFileList();
|
226 |
addLog(`Added ${files.length} file(s) from drag & drop`);
|
227 |
}
|
228 |
});
|
229 |
|
230 |
browseBtn.addEventListener('click', () => {
|
231 |
-
|
232 |
-
|
233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
});
|
235 |
|
236 |
uploadBtn.addEventListener('click', () => {
|
@@ -265,8 +294,16 @@
|
|
265 |
});
|
266 |
|
267 |
document.getElementById('exportLogBtn').addEventListener('click', () => {
|
268 |
-
|
269 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
270 |
});
|
271 |
|
272 |
// Functions
|
@@ -289,7 +326,7 @@
|
|
289 |
<i class="fas fa-folder text-blue-500 mr-3"></i>
|
290 |
<div class="flex-1">
|
291 |
<div class="font-medium">${folderPathInput.value.split('/').pop() || folderPathInput.value.split('\\').pop()}</div>
|
292 |
-
<div class="text-xs text-gray-500">Folder (
|
293 |
</div>
|
294 |
<div class="text-sm text-gray-500">Pending</div>
|
295 |
</div>
|
@@ -377,7 +414,7 @@
|
|
377 |
|
378 |
// Reset counters
|
379 |
document.getElementById('filesProcessed').textContent = '0';
|
380 |
-
document.getElementById('totalFiles').textContent =
|
381 |
document.getElementById('successCount').textContent = '0';
|
382 |
document.getElementById('failedCount').textContent = '0';
|
383 |
document.getElementById('overallProgressBar').style.width = '0%';
|
@@ -394,62 +431,10 @@
|
|
394 |
|
395 |
if (folderPathInput.value) {
|
396 |
addLog(`Uploading folder: ${folderPathInput.value}`);
|
397 |
-
// In a real app, this would scan the folder and upload its contents
|
398 |
-
simulateFolderUpload(folderPathInput.value, prefix);
|
399 |
-
} else {
|
400 |
-
// In a real app, this would upload the selected files
|
401 |
-
simulateFileUpload(filesToUpload, prefix);
|
402 |
}
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
// Simulate folder scanning and file counting
|
407 |
-
setTimeout(() => {
|
408 |
-
const totalFiles = 42; // Simulated file count
|
409 |
-
document.getElementById('totalFiles').textContent = totalFiles;
|
410 |
-
addLog(`Found ${totalFiles} files in folder`);
|
411 |
-
|
412 |
-
// Simulate file uploads
|
413 |
-
let processed = 0;
|
414 |
-
let success = 0;
|
415 |
-
let failed = 0;
|
416 |
-
|
417 |
-
const uploadInterval = setInterval(() => {
|
418 |
-
if (uploadCancelled || processed >= totalFiles) {
|
419 |
-
clearInterval(uploadInterval);
|
420 |
-
finishUpload(processed, success, failed);
|
421 |
-
return;
|
422 |
-
}
|
423 |
-
|
424 |
-
processed++;
|
425 |
-
const isSuccess = Math.random() > 0.1; // 90% success rate
|
426 |
-
|
427 |
-
if (isSuccess) {
|
428 |
-
success++;
|
429 |
-
document.getElementById('successCount').textContent = success;
|
430 |
-
addLog(`✔ Successfully uploaded ${prefix ? prefix + '/' : ''}file${processed}.txt`, "success");
|
431 |
-
|
432 |
-
// Update file item status
|
433 |
-
const fileItems = fileList.querySelectorAll('.file-item');
|
434 |
-
if (fileItems.length > 0) {
|
435 |
-
const randomIndex = Math.floor(Math.random() * fileItems.length);
|
436 |
-
const statusDiv = fileItems[randomIndex].querySelector('div:last-child');
|
437 |
-
statusDiv.innerHTML = '<span class="text-green-600"><i class="fas fa-check mr-1"></i>Done</span>';
|
438 |
-
}
|
439 |
-
} else {
|
440 |
-
failed++;
|
441 |
-
document.getElementById('failedCount').textContent = failed;
|
442 |
-
addLog(`✖ Failed to upload ${prefix ? prefix + '/' : ''}file${processed}.txt`, "error");
|
443 |
-
}
|
444 |
-
|
445 |
-
document.getElementById('filesProcessed').textContent = processed;
|
446 |
-
const progress = Math.floor((processed / totalFiles) * 100);
|
447 |
-
document.getElementById('overallProgressBar').style.width = `${progress}%`;
|
448 |
-
document.getElementById('overallProgressText').textContent = `${progress}%`;
|
449 |
-
|
450 |
-
}, 200);
|
451 |
-
|
452 |
-
}, 1000);
|
453 |
}
|
454 |
|
455 |
function simulateFileUpload(files, prefix) {
|
|
|
28 |
from { transform: rotate(0deg); }
|
29 |
to { transform: rotate(360deg); }
|
30 |
}
|
31 |
+
#folderInput, #fileInput {
|
32 |
+
display: none;
|
33 |
+
}
|
34 |
</style>
|
35 |
</head>
|
36 |
<body class="bg-gray-50 min-h-screen">
|
|
|
94 |
<div class="mb-4">
|
95 |
<label class="block text-sm font-medium text-gray-700 mb-1">Folder Path</label>
|
96 |
<div class="flex">
|
97 |
+
<input type="text" id="folderPath" class="flex-1 px-3 py-2 border border-gray-300 rounded-l-md focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder="Enter folder path or drag & drop" readonly>
|
98 |
<button id="browseBtn" class="px-4 py-2 bg-gray-200 text-gray-700 rounded-r-md hover:bg-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2">
|
99 |
<i class="fas fa-folder-open mr-1"></i> Browse
|
100 |
</button>
|
|
|
107 |
<p class="text-sm text-gray-500">Supports multiple files and folders</p>
|
108 |
</div>
|
109 |
|
110 |
+
<!-- Hidden file inputs -->
|
111 |
+
<input type="file" id="fileInput" multiple>
|
112 |
+
<input type="file" id="folderInput" webkitdirectory directory multiple>
|
113 |
+
|
114 |
<div class="flex justify-between">
|
115 |
<div>
|
116 |
<label class="block text-sm font-medium text-gray-700 mb-1">Prefix (optional)</label>
|
|
|
200 |
const logConsole = document.getElementById('logConsole');
|
201 |
const testConnectionBtn = document.getElementById('testConnectionBtn');
|
202 |
const connectionStatus = document.getElementById('connectionStatus');
|
203 |
+
const fileInput = document.getElementById('fileInput');
|
204 |
+
const folderInput = document.getElementById('folderInput');
|
205 |
|
206 |
// State variables
|
207 |
let filesToUpload = [];
|
|
|
210 |
|
211 |
// Event Listeners
|
212 |
dropzone.addEventListener('click', () => {
|
213 |
+
fileInput.click();
|
|
|
214 |
});
|
215 |
|
216 |
dropzone.addEventListener('dragover', (e) => {
|
|
|
226 |
e.preventDefault();
|
227 |
dropzone.classList.remove('active');
|
228 |
|
229 |
+
const files = Array.from(e.dataTransfer.files);
|
|
|
230 |
if (files.length > 0) {
|
231 |
filesToUpload = files;
|
232 |
+
folderPathInput.value = '';
|
233 |
updateFileList();
|
234 |
addLog(`Added ${files.length} file(s) from drag & drop`);
|
235 |
}
|
236 |
});
|
237 |
|
238 |
browseBtn.addEventListener('click', () => {
|
239 |
+
folderInput.click();
|
240 |
+
});
|
241 |
+
|
242 |
+
fileInput.addEventListener('change', (e) => {
|
243 |
+
const files = Array.from(e.target.files);
|
244 |
+
if (files.length > 0) {
|
245 |
+
filesToUpload = files;
|
246 |
+
folderPathInput.value = '';
|
247 |
+
updateFileList();
|
248 |
+
addLog(`Added ${files.length} file(s) from file selection`);
|
249 |
+
}
|
250 |
+
fileInput.value = ''; // Reset to allow selecting same files again
|
251 |
+
});
|
252 |
+
|
253 |
+
folderInput.addEventListener('change', (e) => {
|
254 |
+
const files = Array.from(e.target.files);
|
255 |
+
if (files.length > 0) {
|
256 |
+
filesToUpload = files;
|
257 |
+
const path = e.target.files[0].webkitRelativePath.split('/')[0];
|
258 |
+
folderPathInput.value = path;
|
259 |
+
updateFileList();
|
260 |
+
addLog(`Added folder "${path}" containing ${files.length} files`);
|
261 |
+
}
|
262 |
+
folderInput.value = ''; // Reset to allow selecting same folder again
|
263 |
});
|
264 |
|
265 |
uploadBtn.addEventListener('click', () => {
|
|
|
294 |
});
|
295 |
|
296 |
document.getElementById('exportLogBtn').addEventListener('click', () => {
|
297 |
+
const blob = new Blob([logConsole.textContent], { type: 'text/plain' });
|
298 |
+
const url = URL.createObjectURL(blob);
|
299 |
+
const a = document.createElement('a');
|
300 |
+
a.href = url;
|
301 |
+
a.download = 'cloudsync-log.txt';
|
302 |
+
document.body.appendChild(a);
|
303 |
+
a.click();
|
304 |
+
document.body.removeChild(a);
|
305 |
+
URL.revokeObjectURL(url);
|
306 |
+
addLog("Log exported as text file");
|
307 |
});
|
308 |
|
309 |
// Functions
|
|
|
326 |
<i class="fas fa-folder text-blue-500 mr-3"></i>
|
327 |
<div class="flex-1">
|
328 |
<div class="font-medium">${folderPathInput.value.split('/').pop() || folderPathInput.value.split('\\').pop()}</div>
|
329 |
+
<div class="text-xs text-gray-500">Folder (${filesToUpload.length} files)</div>
|
330 |
</div>
|
331 |
<div class="text-sm text-gray-500">Pending</div>
|
332 |
</div>
|
|
|
414 |
|
415 |
// Reset counters
|
416 |
document.getElementById('filesProcessed').textContent = '0';
|
417 |
+
document.getElementById('totalFiles').textContent = filesToUpload.length;
|
418 |
document.getElementById('successCount').textContent = '0';
|
419 |
document.getElementById('failedCount').textContent = '0';
|
420 |
document.getElementById('overallProgressBar').style.width = '0%';
|
|
|
431 |
|
432 |
if (folderPathInput.value) {
|
433 |
addLog(`Uploading folder: ${folderPathInput.value}`);
|
|
|
|
|
|
|
|
|
|
|
434 |
}
|
435 |
+
|
436 |
+
// Simulate file uploads
|
437 |
+
simulateFileUpload(filesToUpload, prefix);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
438 |
}
|
439 |
|
440 |
function simulateFileUpload(files, prefix) {
|
prompts.txt
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
import os import boto3 from dotenv import load_dotenv # 加载.env文件中的环境变量 load_dotenv() ACCOUNT_ID = os.getenv("S3_ACCOUNT_ID") ACCESS_KEY = os.getenv("S3_ACCESS_KEY") SECRET_KEY = os.getenv("S3_SECRET_KEY") BUCKET = "scrapydocs" s3 = boto3.client( "s3", endpoint_url=f"https://75f5ed467c14e39214f3a6f2a169f3d0.r2.cloudflarestorage.com/scrapydocs", aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY, region_name="auto", ) def upload_folder_contents(folder_path, bucket, prefix=""): try: file_count = 0 for root, _, files in os.walk(folder_path): for file in files: full_path = os.path.join(root, file) key = f"{prefix}/{file}" if prefix else file try: s3.upload_file(full_path, bucket, key) print(f"✔ Successfully uploaded {key}") file_count += 1 except Exception as e: print(f"✖ Failed to upload {key}: {str(e)}") print(f"\nUpload complete. Total files processed: {file_count}") return file_count except Exception as e: print(f"✖ Fatal error: {str(e)}") return 0 if __name__ == "__main__": print("Starting S3 upload process...") folder_path = "D:/app/JupyterLab/crawl4ai/output/docs_scrapy" if not os.path.exists(folder_path): print(f"✖ Error: Folder not found at {folder_path}") else: print(f"Testing connection to {s3.meta.endpoint_url}") print(s3.list_buckets()) # 这会验证你的凭证是否有效 upload_folder_contents(folder_path, BUCKET) print("Process completed.")
|
|
|
|
1 |
+
import os import boto3 from dotenv import load_dotenv # 加载.env文件中的环境变量 load_dotenv() ACCOUNT_ID = os.getenv("S3_ACCOUNT_ID") ACCESS_KEY = os.getenv("S3_ACCESS_KEY") SECRET_KEY = os.getenv("S3_SECRET_KEY") BUCKET = "scrapydocs" s3 = boto3.client( "s3", endpoint_url=f"https://75f5ed467c14e39214f3a6f2a169f3d0.r2.cloudflarestorage.com/scrapydocs", aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY, region_name="auto", ) def upload_folder_contents(folder_path, bucket, prefix=""): try: file_count = 0 for root, _, files in os.walk(folder_path): for file in files: full_path = os.path.join(root, file) key = f"{prefix}/{file}" if prefix else file try: s3.upload_file(full_path, bucket, key) print(f"✔ Successfully uploaded {key}") file_count += 1 except Exception as e: print(f"✖ Failed to upload {key}: {str(e)}") print(f"\nUpload complete. Total files processed: {file_count}") return file_count except Exception as e: print(f"✖ Fatal error: {str(e)}") return 0 if __name__ == "__main__": print("Starting S3 upload process...") folder_path = "D:/app/JupyterLab/crawl4ai/output/docs_scrapy" if not os.path.exists(folder_path): print(f"✖ Error: Folder not found at {folder_path}") else: print(f"Testing connection to {s3.meta.endpoint_url}") print(s3.list_buckets()) # 这会验证你的凭证是否有效 upload_folder_contents(folder_path, BUCKET) print("Process completed.")
|
2 |
+
Drag & drop files here or click to select Supports multiple files and folders 点击没有提示动作。还有 Browse点击不会自动打开本地文件目录选择文件
|