-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodpack.html
More file actions
379 lines (318 loc) · 19.6 KB
/
Copy pathmodpack.html
File metadata and controls
379 lines (318 loc) · 19.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<!DOCTYPE html>
<html lang="en" class="h-full">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload Klocki Time Modpack</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
/* Custom styles for consistency */
body { font-family: 'Inter', system-ui, -apple-system, sans-serif; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #18181b; }
::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #52525b; }
.progress-bar-fill {
transition: width 0.3s ease-in-out;
}
</style>
<script>
let xhr;
let abortController;
// Custom Modal Logic (Replacing Bootstrap)
function showModal(title, contentHtml) {
const modal = document.getElementById('customModal');
const modalTitle = document.getElementById('modalTitle');
const modalBody = document.getElementById('modalBody');
modalTitle.textContent = title;
modalBody.innerHTML = contentHtml;
modal.classList.remove('hidden');
setTimeout(() => {
modal.firstElementChild.classList.remove('opacity-0', 'scale-95');
modal.firstElementChild.classList.add('opacity-100', 'scale-100');
}, 10);
}
function closeModal() {
const modal = document.getElementById('customModal');
modal.firstElementChild.classList.remove('opacity-100', 'scale-100');
modal.firstElementChild.classList.add('opacity-0', 'scale-95');
setTimeout(() => {
modal.classList.add('hidden');
}, 300);
}
async function uploadFile() {
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
if (!file) {
showModal('Error', '<p class="text-red-400">Please select a file first.</p>');
return;
}
if (!file.name.endsWith('.zip')) {
showModal('Error', '<p class="text-red-400">Only ZIP files are allowed.</p>');
return;
}
// UI Reset
document.getElementById('uploadBtn').disabled = true;
document.getElementById('uploadBtn').classList.add('opacity-50', 'cursor-not-allowed');
const chunkSize = 80 * 1024 * 1024; // 80MB
const totalChunks = Math.ceil(file.size / chunkSize);
const fileId = `${Date.now()}-${file.name}`;
// Notify server to clear chunks directory
try {
await fetch('upload.php?clear_chunks=1');
} catch (e) {
console.error("Could not clear chunks", e);
}
const progressBar = document.getElementById('progressBar');
const chunkProgressBar = document.getElementById('chunkProgressBar');
// Text Elements
const statusText = document.getElementById('statusText');
const speedText = document.getElementById('speedText');
const timeText = document.getElementById('timeText');
const totalPercentText = document.getElementById('totalPercentText'); // NEW
const chunkPercentText = document.getElementById('chunkPercentText'); // NEW
progressBar.style.width = '0%';
chunkProgressBar.style.width = '0%';
totalPercentText.innerText = '0%';
chunkPercentText.innerText = '0%';
let startTime = Date.now();
let uploadedBytes = 0;
statusText.innerHTML = `<span class="text-indigo-400 font-bold">Starting upload...</span>`;
for (let i = 0; i < totalChunks; i++) {
const start = i * chunkSize;
const end = Math.min(file.size, start + chunkSize);
const chunk = file.slice(start, end);
const formData = new FormData();
formData.append('chunk', chunk);
formData.append('fileId', fileId);
formData.append('chunkIndex', i);
formData.append('totalChunks', totalChunks);
chunkProgressBar.style.width = '0%';
chunkPercentText.innerText = '0%';
try {
await new Promise((resolve, reject) => {
xhr = new XMLHttpRequest();
xhr.open('POST', 'upload.php');
xhr.upload.onprogress = (event) => {
if (event.lengthComputable) {
const chunkPercentage = ((event.loaded / event.total) * 100).toFixed(2);
// Update Chunk Progress UI
chunkProgressBar.style.width = `${chunkPercentage}%`;
chunkPercentText.innerText = `${chunkPercentage}%`; // Update Text
const currentUploadedBytes = uploadedBytes + event.loaded;
const elapsedTime = (Date.now() - startTime) / 1000; // seconds
const uploadSpeed = currentUploadedBytes / (1024 * 1024) / elapsedTime; // MB/s
const remainingBytes = file.size - currentUploadedBytes;
const estimatedTime = remainingBytes / (uploadSpeed * 1024 * 1024); // seconds
speedText.innerText = `${uploadSpeed.toFixed(2)} MB/s`;
const hours = Math.floor(estimatedTime / 3600);
const minutes = Math.floor((estimatedTime % 3600) / 60);
const seconds = Math.floor(estimatedTime % 60);
timeText.innerText = `ETA: ${hours}h ${minutes}m ${seconds}s`;
}
};
xhr.onload = () => {
if (xhr.status === 200) {
try {
const result = JSON.parse(xhr.responseText);
if (result.success) {
resolve();
} else {
reject(result.message);
}
} catch(e) {
reject("Invalid server response");
}
} else {
reject('Upload failed with status ' + xhr.status);
}
};
xhr.onerror = () => reject('An error occurred during upload.');
xhr.send(formData);
});
uploadedBytes += chunk.size;
const percentage = ((i + 1) / totalChunks * 100).toFixed(2);
// Update Total Progress UI
progressBar.style.width = `${percentage}%`;
totalPercentText.innerText = `${percentage}%`; // Update Text
statusText.innerHTML = `Uploaded <span class="text-white font-mono">${i + 1}</span> / <span class="text-zinc-400 font-mono">${totalChunks}</span> chunks`;
} catch (error) {
if (xhr.readyState !== 4) {
xhr.abort();
}
statusText.innerText = 'Upload canceled.';
speedText.innerText = '-';
timeText.innerText = '-';
// Clear chunks folder on cancel
await fetch('upload.php?clear_chunks=1');
document.getElementById('uploadBtn').disabled = false;
document.getElementById('uploadBtn').classList.remove('opacity-50', 'cursor-not-allowed');
return;
}
}
// Rename file
await fetch('upload.php?rename_to_new=1&fileId=' + fileId);
showModal('Upload Complete', '<p class="text-emerald-400">File uploaded successfully and saved as <strong>KT-new.zip</strong>. Do not forget to roll out the new version so that users will able to download it.</p>');
statusText.innerText = 'Upload complete!';
speedText.innerText = '';
timeText.innerText = '';
document.getElementById('uploadBtn').disabled = false;
document.getElementById('uploadBtn').classList.remove('opacity-50', 'cursor-not-allowed');
// Refresh date
fetchUploadDate();
}
function cancelUpload() {
if (xhr) {
xhr.abort();
fetch('upload.php?clear_chunks=1');
document.getElementById('uploadBtn').disabled = false;
document.getElementById('uploadBtn').classList.remove('opacity-50', 'cursor-not-allowed');
document.getElementById('statusText').innerText = 'Upload cancelled by user.';
}
}
async function fetchUploadDate() {
try {
const response = await fetch('upload.php?get_upload_date=1');
const result = await response.json();
if (result.success) {
document.getElementById('uploadDate').innerText = result.date;
} else {
document.getElementById('uploadDate').innerText = 'Unknown';
}
} catch (e) {
document.getElementById('uploadDate').innerText = 'Error loading date';
}
}
document.addEventListener('DOMContentLoaded', fetchUploadDate);
async function makeLiveVersion() {
try {
const response = await fetch('upload.php?make_live=1');
const result = await response.json();
if (result.success) {
showModal('Success', `
<p class="mb-4 text-zinc-300">Modpack live version was successfully changed.</p>
<div class="bg-indigo-900/30 border border-indigo-500/50 p-4 rounded-lg">
<p class="text-sm text-indigo-200">
⚠ Do not forget to update version
<a href="https://www.technicpack.net/modpack/edit/2000598/versions" target="_blank" class="text-white underline hover:text-indigo-300 font-bold">here</a>
and add the changelog.
</p>
<p class="text-xs text-indigo-300/70 mt-2">Without that users won't be able to update their modpacks in TechnicLauncher.</p>
</div>
`);
} else {
showModal('Error', `<p class="text-red-400">${result.message}</p>`);
}
} catch (e) {
showModal('Error', '<p class="text-red-400">Connection error.</p>');
}
}
</script>
</head>
<body class="bg-zinc-950 text-zinc-200 h-full flex flex-col min-h-screen">
<header class="pt-8 pb-4 flex justify-center">
<div class="text-center">
<img src="https://alleria.pl/image/logo-clr.png" alt="Alleria Logo" class="h-16 mb-2 mx-auto drop-shadow-2xl">
<h1 class="text-2xl font-bold tracking-tight text-white mt-2">Upload Client</h1>
<p class="text-zinc-500 text-sm font-mono uppercase tracking-widest">of Klocki Time Modpack</p>
</div>
</header>
<main class="flex-grow container mx-auto px-4 py-6 max-w-3xl">
<div class="bg-zinc-900/50 backdrop-blur-sm border border-zinc-800 rounded-xl p-6 mb-8 text-center shadow-xl">
<div class="flex items-center justify-center mb-4 text-amber-500">
<svg class="w-6 h-6 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path></svg>
<span class="font-bold text-sm uppercase tracking-wide">Important Notice</span>
</div>
<p class="text-zinc-300 mb-2">Before adding new mods, make sure you are working on the <strong class="text-white">latest version</strong>.</p>
<p class="text-zinc-500 text-sm mb-6">his is especially crucial when more than one person is working on the modpack.</p>
<div class="flex flex-col sm:flex-row justify-center items-center gap-4">
<a href="/dl/KT-latest.zip" download class="group flex items-center px-6 py-3 bg-zinc-800 hover:bg-zinc-700 text-zinc-200 rounded-lg transition-all border border-zinc-700 hover:border-zinc-500">
<svg class="w-5 h-5 mr-2 text-indigo-400 group-hover:text-indigo-300" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"></path></svg>
Download Current Modpack
</a>
</div>
<p class="mt-4 text-xs text-zinc-600 font-mono">Current version upload date: <span id="uploadDate" class="text-zinc-400">Loading...</span> [YYYY-MM-DD]</p>
</div>
<div class="bg-zinc-900 border border-zinc-800 rounded-xl p-6 lg:p-8 shadow-2xl relative overflow-hidden">
<div class="absolute top-0 right-0 -mr-16 -mt-16 w-64 h-64 bg-indigo-600/10 rounded-full blur-3xl pointer-events-none"></div>
<div class="mb-6 relative z-10">
<label for="fileInput" class="block text-sm font-medium text-zinc-400 mb-2">Select ZIP File</label>
<input type="file" id="fileInput" class="block w-full text-sm text-zinc-300
file:mr-4 file:py-2.5 file:px-4
file:rounded-lg file:border-0
file:text-sm file:font-semibold
file:bg-indigo-600 file:text-white
hover:file:bg-indigo-500
bg-zinc-950 border border-zinc-800 rounded-lg cursor-pointer focus:outline-none focus:ring-2 focus:ring-indigo-500/50"
/>
</div>
<div class="flex gap-4 mb-8 relative z-10">
<button id="uploadBtn" onclick="uploadFile()" class="flex-1 bg-indigo-600 hover:bg-indigo-500 text-white font-bold py-3 px-4 rounded-lg transition-colors flex justify-center items-center shadow-lg shadow-indigo-600/20">
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"></path></svg>
Start Upload
</button>
<button onclick="cancelUpload()" class="bg-zinc-800 hover:bg-red-900/30 hover:text-red-400 text-zinc-400 font-bold py-3 px-6 rounded-lg transition-colors border border-zinc-700 hover:border-red-800/50">
Cancel
</button>
</div>
<div class="space-y-6 relative z-10">
<div>
<div class="flex justify-between text-xs font-medium text-zinc-500 mb-1">
<span class="flex items-center">
Total Progress
<span id="totalPercentText" class="ml-2 text-indigo-400 font-bold font-mono">0%</span>
</span>
<span id="statusText">Waiting...</span>
</div>
<div class="w-full bg-zinc-950 rounded-full h-3 border border-zinc-800 overflow-hidden">
<div id="progressBar" class="bg-indigo-500 h-3 rounded-full progress-bar-fill shadow-[0_0_10px_rgba(99,102,241,0.5)]" style="width: 0%"></div>
</div>
</div>
<div>
<div class="flex justify-between text-xs font-medium text-zinc-500 mb-1">
<span class="flex items-center">
Chunk Upload
<span id="chunkPercentText" class="ml-2 text-purple-400 font-bold font-mono">0%</span>
</span>
<div class="flex space-x-4">
<span id="speedText" class="text-zinc-300 font-mono"></span>
<span id="timeText" class="text-zinc-300 font-mono"></span>
</div>
</div>
<div class="w-full bg-zinc-950 rounded-full h-1.5 border border-zinc-800 overflow-hidden">
<div id="chunkProgressBar" class="bg-purple-500 h-1.5 rounded-full progress-bar-fill" style="width: 0%"></div>
</div>
</div>
</div>
</div>
<div class="mt-8 text-center">
<button onclick="makeLiveVersion()" class="group relative inline-flex items-center justify-center px-8 py-3 font-bold text-white transition-all duration-200 bg-emerald-600 font-lg rounded-lg hover:bg-emerald-500 hover:shadow-lg hover:shadow-emerald-500/30 focus:outline-none ring-offset-2 focus:ring-2 ring-emerald-500">
<span class="mr-2">Rollout New Version</span>
<svg class="w-5 h-5 transition-transform group-hover:rotate-12" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg>
</button>
<p class="mt-2 text-xs text-zinc-600">This will replace the current KT-latest.zip file for all technic launcher users.</p>
</div>
</main>
<div class="text-center text-xs text-zinc-500 font-mono">
Upload & Rollout System made by henas_pl entirely for the purpose of Klocki Time Management
</div>
<div class="mt-8"></div>
<div id="customModal" class="fixed inset-0 z-50 hidden bg-zinc-950/80 backdrop-blur-sm flex items-center justify-center transition-opacity">
<div class="bg-zinc-900 border border-zinc-700 w-full max-w-md p-6 rounded-xl shadow-2xl transform scale-95 opacity-0 transition-all duration-300 m-4">
<div class="flex justify-between items-center mb-4 border-b border-zinc-800 pb-2">
<h3 id="modalTitle" class="text-lg font-bold text-white">Notification</h3>
<button onclick="closeModal()" class="text-zinc-500 hover:text-white">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path></svg>
</button>
</div>
<div id="modalBody" class="text-zinc-300 text-sm leading-relaxed">
</div>
<div class="mt-6 flex justify-end">
<button onclick="closeModal()" class="bg-zinc-800 hover:bg-zinc-700 text-white text-sm font-medium py-2 px-4 rounded-lg transition-colors border border-zinc-700">
Close
</button>
</div>
</div>
</div>
</body>
</html>