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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="fa" dir="rtl">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>آپلودر پیشرفته فایل به Hugging Face</title>
|
| 7 |
+
<style>
|
| 8 |
+
body {
|
| 9 |
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
| 10 |
+
text-align: right;
|
| 11 |
+
margin: 20px;
|
| 12 |
+
background-color: #f4f4f9;
|
| 13 |
+
color: #333;
|
| 14 |
+
}
|
| 15 |
+
.container {
|
| 16 |
+
max-width: 600px;
|
| 17 |
+
margin: 40px auto;
|
| 18 |
+
padding: 30px;
|
| 19 |
+
background-color: #fff;
|
| 20 |
+
border-radius: 8px;
|
| 21 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
| 22 |
+
}
|
| 23 |
+
h1, h2 {
|
| 24 |
+
color: #4a4a4a;
|
| 25 |
+
text-align: center;
|
| 26 |
+
}
|
| 27 |
+
.upload-section {
|
| 28 |
+
margin-bottom: 25px;
|
| 29 |
+
padding: 20px;
|
| 30 |
+
border: 1px dashed #ccc;
|
| 31 |
+
border-radius: 5px;
|
| 32 |
+
}
|
| 33 |
+
label {
|
| 34 |
+
display: block;
|
| 35 |
+
margin-bottom: 8px;
|
| 36 |
+
font-weight: bold;
|
| 37 |
+
}
|
| 38 |
+
input[type="file"], input[type="text"] {
|
| 39 |
+
width: calc(100% - 22px);
|
| 40 |
+
padding: 10px;
|
| 41 |
+
margin-bottom: 15px;
|
| 42 |
+
border: 1px solid #ddd;
|
| 43 |
+
border-radius: 4px;
|
| 44 |
+
box-sizing: border-box;
|
| 45 |
+
}
|
| 46 |
+
button {
|
| 47 |
+
background-color: #5e72e4;
|
| 48 |
+
color: white;
|
| 49 |
+
padding: 12px 20px;
|
| 50 |
+
border: none;
|
| 51 |
+
border-radius: 5px;
|
| 52 |
+
cursor: pointer;
|
| 53 |
+
width: 100%;
|
| 54 |
+
font-size: 16px;
|
| 55 |
+
transition: background-color 0.2s;
|
| 56 |
+
}
|
| 57 |
+
button:hover {
|
| 58 |
+
background-color: #485ab8;
|
| 59 |
+
}
|
| 60 |
+
button:disabled {
|
| 61 |
+
background-color: #cccccc;
|
| 62 |
+
cursor: not-allowed;
|
| 63 |
+
}
|
| 64 |
+
#result {
|
| 65 |
+
margin-top: 25px;
|
| 66 |
+
padding: 15px;
|
| 67 |
+
border-radius: 5px;
|
| 68 |
+
background-color: #f0f0f0;
|
| 69 |
+
min-height: 50px;
|
| 70 |
+
word-wrap: break-word;
|
| 71 |
+
text-align: left;
|
| 72 |
+
}
|
| 73 |
+
.progress-container {
|
| 74 |
+
width: 100%;
|
| 75 |
+
background-color: #e0e0e0;
|
| 76 |
+
border-radius: 4px;
|
| 77 |
+
display: none;
|
| 78 |
+
margin-top: 15px;
|
| 79 |
+
overflow: hidden; /* برای گرد شدن گوشه های نوار پیشرفت */
|
| 80 |
+
}
|
| 81 |
+
.progress-bar {
|
| 82 |
+
width: 0%;
|
| 83 |
+
height: 20px;
|
| 84 |
+
background-color: #4caf50;
|
| 85 |
+
border-radius: 4px;
|
| 86 |
+
text-align: center;
|
| 87 |
+
line-height: 20px;
|
| 88 |
+
color: white;
|
| 89 |
+
transition: width 0.3s ease-in-out;
|
| 90 |
+
}
|
| 91 |
+
.success { color: #28a745; }
|
| 92 |
+
.error { color: #dc3545; }
|
| 93 |
+
.loading { color: #ffc107; }
|
| 94 |
+
.result-link {
|
| 95 |
+
font-weight: bold;
|
| 96 |
+
color: #5e72e4;
|
| 97 |
+
text-decoration: none;
|
| 98 |
+
}
|
| 99 |
+
.result-link:hover {
|
| 100 |
+
text-decoration: underline;
|
| 101 |
+
}
|
| 102 |
+
</style>
|
| 103 |
+
</head>
|
| 104 |
+
<body>
|
| 105 |
+
<div class="container">
|
| 106 |
+
<h1>آپلودر پیشرفته فایل</h1>
|
| 107 |
+
<div class="upload-section">
|
| 108 |
+
<h2>آپلود از کامپیوتر</h2>
|
| 109 |
+
<input type="file" id="fileInput" accept="*/*">
|
| 110 |
+
<button id="uploadFileBtn">آپلود فایل</button>
|
| 111 |
+
</div>
|
| 112 |
+
<div class="upload-section">
|
| 113 |
+
<h2>آپلود از طریق لینک</h2>
|
| 114 |
+
<input type="text" id="urlInput" placeholder="آدرس URL فایل را وارد کنید">
|
| 115 |
+
<button id="uploadUrlBtn">آپلود از لینک</button>
|
| 116 |
+
</div>
|
| 117 |
+
<div class="progress-container" id="progressContainer">
|
| 118 |
+
<div class="progress-bar" id="progressBar">0%</div>
|
| 119 |
+
</div>
|
| 120 |
+
<div id="result"><p>نتیجه اینجا نمایش داده میشود.</p></div>
|
| 121 |
+
</div>
|
| 122 |
+
<script>
|
| 123 |
+
const fileInput = document.getElementById('fileInput');
|
| 124 |
+
const uploadFileBtn = document.getElementById('uploadFileBtn');
|
| 125 |
+
const urlInput = document.getElementById('urlInput');
|
| 126 |
+
const uploadUrlBtn = document.getElementById('uploadUrlBtn');
|
| 127 |
+
const resultDiv = document.getElementById('result');
|
| 128 |
+
const progressContainer = document.getElementById('progressContainer');
|
| 129 |
+
const progressBar = document.getElementById('progressBar');
|
| 130 |
+
|
| 131 |
+
const API_URL = '/upload';
|
| 132 |
+
|
| 133 |
+
function showResult(message, type = 'info') {
|
| 134 |
+
resultDiv.innerHTML = `<p class="${type}">${message}</p>`;
|
| 135 |
+
}
|
| 136 |
+
function setButtonsEnabled(enabled) {
|
| 137 |
+
uploadFileBtn.disabled = !enabled;
|
| 138 |
+
uploadUrlBtn.disabled = !enabled;
|
| 139 |
+
}
|
| 140 |
+
function updateProgress(percent) {
|
| 141 |
+
progressContainer.style.display = 'block';
|
| 142 |
+
progressBar.style.width = percent + '%';
|
| 143 |
+
progressBar.textContent = percent + '%';
|
| 144 |
+
}
|
| 145 |
+
function hideProgress() {
|
| 146 |
+
setTimeout(() => {
|
| 147 |
+
progressContainer.style.display = 'none';
|
| 148 |
+
updateProgress(0);
|
| 149 |
+
}, 2000);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
function uploadWithXHR(requestData, isFormData = false) {
|
| 153 |
+
return new Promise((resolve, reject) => {
|
| 154 |
+
const xhr = new XMLHttpRequest();
|
| 155 |
+
xhr.open('POST', API_URL, true);
|
| 156 |
+
|
| 157 |
+
xhr.upload.onprogress = function(event) {
|
| 158 |
+
if (event.lengthComputable && isFormData) {
|
| 159 |
+
const percentComplete = Math.round((event.loaded / event.total) * 100);
|
| 160 |
+
updateProgress(percentComplete);
|
| 161 |
+
}
|
| 162 |
+
};
|
| 163 |
+
|
| 164 |
+
xhr.onload = function() {
|
| 165 |
+
if (xhr.status >= 200 && xhr.status < 300) {
|
| 166 |
+
resolve(JSON.parse(xhr.responseText));
|
| 167 |
+
} else {
|
| 168 |
+
try {
|
| 169 |
+
const errorData = JSON.parse(xhr.responseText);
|
| 170 |
+
reject(errorData.error || `Error ${xhr.status}: ${xhr.statusText}`);
|
| 171 |
+
} catch (e) {
|
| 172 |
+
reject(`Error ${xhr.status}: ${xhr.statusText}`);
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
};
|
| 176 |
+
|
| 177 |
+
xhr.onerror = function() {
|
| 178 |
+
reject('خطای ارتباط با شبکه رخ داد.');
|
| 179 |
+
};
|
| 180 |
+
|
| 181 |
+
if (isFormData) {
|
| 182 |
+
xhr.send(requestData);
|
| 183 |
+
} else {
|
| 184 |
+
xhr.setRequestHeader('Content-Type', 'application/json');
|
| 185 |
+
xhr.send(JSON.stringify(requestData));
|
| 186 |
+
}
|
| 187 |
+
});
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
uploadFileBtn.addEventListener('click', async () => {
|
| 191 |
+
const file = fileInput.files[0];
|
| 192 |
+
if (!file) {
|
| 193 |
+
showResult('لطفاً یک فایل انتخاب کنید.', 'error');
|
| 194 |
+
return;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
showResult('در حال آماده سازی برای آپلود...', 'loading');
|
| 198 |
+
setButtonsEnabled(false);
|
| 199 |
+
updateProgress(0);
|
| 200 |
+
|
| 201 |
+
const formData = new FormData();
|
| 202 |
+
formData.append('file', file);
|
| 203 |
+
|
| 204 |
+
try {
|
| 205 |
+
const data = await uploadWithXHR(formData, true);
|
| 206 |
+
showResult(`فایل با موفقیت آپلود شد! <br> لینک: <a href="${data.hf_url}" target="_blank" class="result-link">${data.hf_url}</a>`, 'success');
|
| 207 |
+
} catch (error) {
|
| 208 |
+
showResult(`خطا در آپلود: ${error}`, 'error');
|
| 209 |
+
} finally {
|
| 210 |
+
setButtonsEnabled(true);
|
| 211 |
+
hideProgress();
|
| 212 |
+
}
|
| 213 |
+
});
|
| 214 |
+
|
| 215 |
+
uploadUrlBtn.addEventListener('click', async () => {
|
| 216 |
+
const url = urlInput.value.trim();
|
| 217 |
+
if (!url) {
|
| 218 |
+
showResult('لطفاً آدرس URL را وارد کنید.', 'error');
|
| 219 |
+
return;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
showResult('در حال ارسال درخواست به سرور... (این ممکن است زمان ببرد)', 'loading');
|
| 223 |
+
setButtonsEnabled(false);
|
| 224 |
+
progressContainer.style.display = 'none';
|
| 225 |
+
|
| 226 |
+
try {
|
| 227 |
+
// ***** این خط اصلاح شد *****
|
| 228 |
+
const data = await uploadWithXHR({ url: url }, false);
|
| 229 |
+
showResult(`فایل با موفقیت از لینک آپلود شد! <br> لینک: <a href="${data.hf_url}" target="_blank" class="result-link">${data.hf_url}</a>`, 'success');
|
| 230 |
+
} catch (error) {
|
| 231 |
+
showResult(`خطا در آپلود: ${error}`, 'error');
|
| 232 |
+
} finally {
|
| 233 |
+
setButtonsEnabled(true);
|
| 234 |
+
}
|
| 235 |
+
});
|
| 236 |
+
</script>
|
| 237 |
+
</body>
|
| 238 |
+
</html>
|