Merge branch 'chunked'
All checks were successful
Deploy / Explore-Gitea-Actions (push) Successful in 8m45s
All checks were successful
Deploy / Explore-Gitea-Actions (push) Successful in 8m45s
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package com.gregor_lohaus.gtransfer.controller;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -12,11 +12,13 @@ import org.springframework.stereotype.Controller;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import com.gregor_lohaus.gtransfer.model.File;
|
||||
import com.gregor_lohaus.gtransfer.model.FileRepository;
|
||||
import com.gregor_lohaus.gtransfer.services.filewriter.AbstractStorageService;
|
||||
import com.gregor_lohaus.gtransfer.services.filewriter.StorageKeys;
|
||||
|
||||
@Controller
|
||||
public class DownloadController {
|
||||
@@ -32,52 +34,109 @@ public class DownloadController {
|
||||
return "download/page";
|
||||
}
|
||||
|
||||
@GetMapping("/download/{id}/data")
|
||||
@GetMapping("/download/{id}/metadata")
|
||||
@ResponseBody
|
||||
@Transactional
|
||||
public ResponseEntity<byte[]> data(@PathVariable String id) {
|
||||
Optional<File> fileOpt = fileRepository.findById(id);
|
||||
if (fileOpt.isEmpty()) {
|
||||
return ResponseEntity.notFound().build();
|
||||
public ResponseEntity<Map<String, Object>> metadata(@PathVariable String id) {
|
||||
AvailableFile available = getAvailableFile(id);
|
||||
if (!available.found()) {
|
||||
return ResponseEntity.status(available.status()).build();
|
||||
}
|
||||
|
||||
File file = fileOpt.get();
|
||||
|
||||
// Check expiry
|
||||
if (file.getExpireyDateTime() != null && LocalDateTime.now().isAfter(file.getExpireyDateTime())) {
|
||||
storageService.delete(id);
|
||||
fileRepository.delete(file);
|
||||
return ResponseEntity.status(HttpStatus.GONE).build();
|
||||
File file = available.file();
|
||||
return ResponseEntity.ok(Map.of(
|
||||
"name", file.getName(),
|
||||
"chunkCount", file.getChunkCount()));
|
||||
}
|
||||
|
||||
// Check download limit before serving
|
||||
if (file.getDownloadLimit() != null && file.getDownloads() >= file.getDownloadLimit()) {
|
||||
storageService.delete(id);
|
||||
fileRepository.delete(file);
|
||||
return ResponseEntity.status(HttpStatus.GONE).build();
|
||||
@GetMapping("/download/{id}/chunk/{index}")
|
||||
@ResponseBody
|
||||
@Transactional
|
||||
public ResponseEntity<byte[]> chunk(@PathVariable String id, @PathVariable Integer index) {
|
||||
AvailableFile available = getAvailableFile(id);
|
||||
if (!available.found()) {
|
||||
return ResponseEntity.status(available.status()).build();
|
||||
}
|
||||
|
||||
Optional<byte[]> data = storageService.get(id);
|
||||
File file = available.file();
|
||||
if (index == null || index < 0 || index >= file.getChunkCount()) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
|
||||
Optional<byte[]> data = storageService.get(StorageKeys.chunk(file.getId(), index));
|
||||
if (data.isEmpty()) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
// Increment counter
|
||||
file.setDownloads(file.getDownloads() + 1);
|
||||
fileRepository.save(file);
|
||||
|
||||
// Clean up if limit now reached
|
||||
if (file.getDownloadLimit() != null && file.getDownloads() >= file.getDownloadLimit()) {
|
||||
storageService.delete(id);
|
||||
fileRepository.delete(file);
|
||||
}
|
||||
|
||||
String disposition = "attachment; filename=\""
|
||||
+ file.getName().replace("\\", "\\\\").replace("\"", "\\\"") + "\"";
|
||||
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, disposition)
|
||||
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
||||
.body(data.get());
|
||||
}
|
||||
|
||||
@PostMapping("/download/{id}/complete")
|
||||
@ResponseBody
|
||||
@Transactional
|
||||
public ResponseEntity<Void> complete(@PathVariable String id) {
|
||||
AvailableFile available = getAvailableFile(id);
|
||||
if (!available.found()) {
|
||||
return ResponseEntity.status(available.status()).build();
|
||||
}
|
||||
|
||||
File file = available.file();
|
||||
file.setDownloads(file.getDownloads() + 1);
|
||||
fileRepository.save(file);
|
||||
|
||||
if (file.getDownloadLimit() != null && file.getDownloads() >= file.getDownloadLimit()) {
|
||||
deleteStoredFile(file);
|
||||
fileRepository.delete(file);
|
||||
}
|
||||
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
private AvailableFile getAvailableFile(String id) {
|
||||
Optional<File> fileOpt = fileRepository.findById(id);
|
||||
if (fileOpt.isEmpty()) {
|
||||
return AvailableFile.notFound();
|
||||
}
|
||||
|
||||
File file = fileOpt.get();
|
||||
if (file.getExpireyDateTime() != null && LocalDateTime.now().isAfter(file.getExpireyDateTime())) {
|
||||
deleteStoredFile(file);
|
||||
fileRepository.delete(file);
|
||||
return AvailableFile.gone();
|
||||
}
|
||||
|
||||
if (file.getDownloadLimit() != null && file.getDownloads() >= file.getDownloadLimit()) {
|
||||
deleteStoredFile(file);
|
||||
fileRepository.delete(file);
|
||||
return AvailableFile.gone();
|
||||
}
|
||||
|
||||
return AvailableFile.ok(file);
|
||||
}
|
||||
|
||||
private void deleteStoredFile(File file) {
|
||||
for (int i = 0; i < file.getChunkCount(); i++) {
|
||||
storageService.delete(StorageKeys.chunk(file.getId(), i));
|
||||
}
|
||||
}
|
||||
|
||||
private record AvailableFile(File file, HttpStatus status) {
|
||||
static AvailableFile ok(File file) {
|
||||
return new AvailableFile(file, HttpStatus.OK);
|
||||
}
|
||||
|
||||
static AvailableFile notFound() {
|
||||
return new AvailableFile(null, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
static AvailableFile gone() {
|
||||
return new AvailableFile(null, HttpStatus.GONE);
|
||||
}
|
||||
|
||||
boolean found() {
|
||||
return file != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,15 @@ package com.gregor_lohaus.gtransfer.controller;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.OptionalLong;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -15,6 +19,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import com.gregor_lohaus.gtransfer.model.File;
|
||||
import com.gregor_lohaus.gtransfer.model.FileRepository;
|
||||
import com.gregor_lohaus.gtransfer.services.filewriter.AbstractStorageService;
|
||||
import com.gregor_lohaus.gtransfer.services.filewriter.StorageKeys;
|
||||
|
||||
@Controller
|
||||
public class UploadController {
|
||||
@@ -41,21 +46,44 @@ public class UploadController {
|
||||
|
||||
@PostMapping("/upload")
|
||||
public String upload(
|
||||
@RequestParam("file") MultipartFile file,
|
||||
@RequestParam("hash") String hash,
|
||||
@RequestParam("name") String name,
|
||||
@RequestParam("chunkCount") Integer chunkCount,
|
||||
@RequestParam(required = false) Integer expiryDays,
|
||||
@RequestParam(required = false) Integer downloadLimit) throws IOException {
|
||||
|
||||
storageService.put(hash, file.getBytes());
|
||||
@RequestParam(required = false) Integer downloadLimit) {
|
||||
if (!isValidId(hash) || chunkCount == null || chunkCount < 1) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid upload metadata");
|
||||
}
|
||||
|
||||
int days = expiryDays != null ? Math.min(expiryDays, maxExpiryDays) : maxExpiryDays;
|
||||
Integer limit = downloadLimit != null ? Math.min(downloadLimit, maxDownloadLimit) : null;
|
||||
|
||||
File f = new File(hash, hash, name, LocalDateTime.now().plusDays(days));
|
||||
f.setChunkCount(chunkCount);
|
||||
f.setDownloadLimit(limit);
|
||||
fileRepository.save(f);
|
||||
|
||||
return "upload/result :: view";
|
||||
}
|
||||
|
||||
@PostMapping("/upload/chunk")
|
||||
public ResponseEntity<Void> uploadChunk(
|
||||
@RequestParam("chunk") MultipartFile chunk,
|
||||
@RequestParam("hash") String hash,
|
||||
@RequestParam("index") Integer index) throws IOException {
|
||||
if (!isValidId(hash) || index == null || index < 0) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
|
||||
OptionalLong written = storageService.put(StorageKeys.chunk(hash, index), chunk.getBytes());
|
||||
if (written.isEmpty()) {
|
||||
return ResponseEntity.internalServerError().build();
|
||||
}
|
||||
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
private boolean isValidId(String id) {
|
||||
return id != null && id.matches("[a-f0-9]{64}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ public class File {
|
||||
private String id;
|
||||
private String path;
|
||||
private String name;
|
||||
private Integer chunkCount;
|
||||
private LocalDateTime expireyDateTime;
|
||||
private Integer downloadLimit;
|
||||
@Column(columnDefinition = "integer default 0")
|
||||
@@ -41,6 +42,12 @@ public class File {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public Integer getChunkCount() {
|
||||
return chunkCount == null ? 1 : chunkCount;
|
||||
}
|
||||
public void setChunkCount(Integer chunkCount) {
|
||||
this.chunkCount = chunkCount;
|
||||
}
|
||||
public Integer getDownloadLimit() {
|
||||
return downloadLimit;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import com.gregor_lohaus.gtransfer.model.File;
|
||||
import com.gregor_lohaus.gtransfer.model.FileRepository;
|
||||
import com.gregor_lohaus.gtransfer.services.filewriter.AbstractStorageService;
|
||||
import com.gregor_lohaus.gtransfer.services.filewriter.StorageKeys;
|
||||
|
||||
public class FileCleanupService {
|
||||
private Boolean enabled;
|
||||
@@ -43,9 +44,15 @@ public class FileCleanupService {
|
||||
};
|
||||
|
||||
for (File file : expired) {
|
||||
storageService.delete(file.getId());
|
||||
deleteStoredFile(file);
|
||||
fileRepository.delete(file);
|
||||
}
|
||||
log.info("Cleaned up {} expired file(s)", expired.size());
|
||||
}
|
||||
|
||||
private void deleteStoredFile(File file) {
|
||||
for (int i = 0; i < file.getChunkCount(); i++) {
|
||||
storageService.delete(StorageKeys.chunk(file.getId(), i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,12 @@ public class LocalStorageService extends AbstractStorageService {
|
||||
@Override
|
||||
public OptionalLong put(String id, byte[] data) {
|
||||
try {
|
||||
Files.createDirectories(root);
|
||||
Files.write(root.resolve(id), data);
|
||||
Path target = root.resolve(id);
|
||||
Path parent = target.getParent();
|
||||
if (parent != null) {
|
||||
Files.createDirectories(parent);
|
||||
}
|
||||
Files.write(target, data);
|
||||
return OptionalLong.of(data.length);
|
||||
} catch (IOException e) {
|
||||
return OptionalLong.empty();
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.gregor_lohaus.gtransfer.services.filewriter;
|
||||
|
||||
public final class StorageKeys {
|
||||
private StorageKeys() {}
|
||||
|
||||
public static String chunk(String id, int index) {
|
||||
return id + "/chunks/" + index;
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,39 @@
|
||||
async function encryptFile(arrayBuffer) {
|
||||
var DEFAULT_CHUNK_SIZE = 4 * 1024 * 1024;
|
||||
|
||||
async function encryptFile(file, chunkSize = DEFAULT_CHUNK_SIZE) {
|
||||
const key = await crypto.subtle.generateKey(
|
||||
{ name: 'AES-GCM', length: 256 },
|
||||
true,
|
||||
['encrypt', 'decrypt']
|
||||
);
|
||||
|
||||
const rawKey = await crypto.subtle.exportKey('raw', key);
|
||||
const hash = await hashKey(rawKey);
|
||||
const base64urlKey = encodeKey(rawKey);
|
||||
const chunkCount = Math.max(1, Math.ceil(file.size / chunkSize));
|
||||
|
||||
return {
|
||||
hash,
|
||||
base64urlKey,
|
||||
chunkCount,
|
||||
chunks: encryptedChunks(file, key, chunkCount, chunkSize)
|
||||
};
|
||||
}
|
||||
|
||||
async function* encryptedChunks(file, key, chunkCount, chunkSize) {
|
||||
for (let index = 0; index < chunkCount; index++) {
|
||||
const start = index * chunkSize;
|
||||
const end = Math.min(start + chunkSize, file.size);
|
||||
const plaintext = await file.slice(start, end).arrayBuffer();
|
||||
const iv = crypto.getRandomValues(new Uint8Array(12));
|
||||
const ciphertext = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, plaintext);
|
||||
|
||||
const ciphertext = await crypto.subtle.encrypt({ name: 'AES-GCM', iv }, key, arrayBuffer);
|
||||
|
||||
// Payload: 12-byte IV prepended to ciphertext
|
||||
const payload = new Uint8Array(12 + ciphertext.byteLength);
|
||||
payload.set(iv, 0);
|
||||
payload.set(new Uint8Array(ciphertext), 12);
|
||||
|
||||
// SHA-256(rawKey) → file identifier sent to server; server never sees the key itself
|
||||
const rawKey = await crypto.subtle.exportKey('raw', key);
|
||||
const hash = await hashKey(rawKey);
|
||||
|
||||
const base64urlKey = encodeKey(rawKey);
|
||||
|
||||
return { payload, hash, base64urlKey };
|
||||
yield { index, payload };
|
||||
}
|
||||
}
|
||||
|
||||
async function hashKey(rawKey) {
|
||||
@@ -29,7 +42,7 @@ async function hashKey(rawKey) {
|
||||
.join('');
|
||||
}
|
||||
|
||||
async function decryptFile(payload, key) {
|
||||
async function decryptChunk(payload, key) {
|
||||
const bytes = new Uint8Array(payload);
|
||||
const iv = bytes.slice(0, 12);
|
||||
const ciphertext = bytes.slice(12);
|
||||
|
||||
@@ -11,24 +11,46 @@ if (!fragment) {
|
||||
'raw', rawKeyBytes, { name: 'AES-GCM' }, false, ['decrypt']
|
||||
);
|
||||
|
||||
setStatus('Downloading\u2026');
|
||||
const response = await fetch('/download/' + id + '/data');
|
||||
setProgress('Loading metadata\u2026', 0, 1);
|
||||
const metadataResponse = await fetch('/download/' + id + '/metadata');
|
||||
|
||||
if (response.status === 410) {
|
||||
if (metadataResponse.status === 410) {
|
||||
showError('This file has expired or reached its download limit.');
|
||||
} else if (!response.ok) {
|
||||
showError(`Download failed (${response.status}).`);
|
||||
} else if (!metadataResponse.ok) {
|
||||
showError(`Download failed (${metadataResponse.status}).`);
|
||||
} else {
|
||||
const disposition = response.headers.get('Content-Disposition') || '';
|
||||
const filename = disposition.match(/filename="?([^"]+)"?/)?.[1] || 'download';
|
||||
const metadata = await metadataResponse.json();
|
||||
const filename = metadata.name || 'download';
|
||||
const chunkCount = metadata.chunkCount || 1;
|
||||
const chunks = [];
|
||||
|
||||
setStatus('Decrypting\u2026');
|
||||
const plaintext = await decryptFile(await response.arrayBuffer(), key);
|
||||
for (let index = 0; index < chunkCount; index++) {
|
||||
setProgress(`Downloading chunk ${index + 1} of ${chunkCount}\u2026`, index, chunkCount);
|
||||
const chunkResponse = await fetch('/download/' + id + '/chunk/' + index);
|
||||
if (chunkResponse.status === 410) {
|
||||
throw new Error('This file has expired or reached its download limit.');
|
||||
}
|
||||
if (!chunkResponse.ok) {
|
||||
throw new Error(`Chunk download failed (${chunkResponse.status})`);
|
||||
}
|
||||
|
||||
setProgress(`Decrypting chunk ${index + 1} of ${chunkCount}\u2026`, index + 0.5, chunkCount);
|
||||
const plaintextChunk = await decryptChunk(await chunkResponse.arrayBuffer(), key);
|
||||
chunks.push(new Uint8Array(plaintextChunk));
|
||||
setProgress(`Downloaded ${index + 1} of ${chunkCount} chunks`, index + 1, chunkCount);
|
||||
}
|
||||
|
||||
const completeResponse = await fetch('/download/' + id + '/complete', { method: 'POST' });
|
||||
if (!completeResponse.ok && completeResponse.status !== 404 && completeResponse.status !== 410) {
|
||||
throw new Error(`Download completion failed (${completeResponse.status})`);
|
||||
}
|
||||
|
||||
setProgress('Preparing preview\u2026', chunkCount, chunkCount);
|
||||
const plaintext = combineChunks(chunks);
|
||||
showPreview(filename, plaintext);
|
||||
}
|
||||
} catch (err) {
|
||||
showError('Decryption failed: ' + err.message);
|
||||
showError(err.message);
|
||||
}
|
||||
|
||||
function setStatus(msg) {
|
||||
@@ -36,6 +58,16 @@ function setStatus(msg) {
|
||||
if (el) el.textContent = msg;
|
||||
}
|
||||
|
||||
function setProgress(msg, completed, total) {
|
||||
setStatus(msg);
|
||||
const percent = Math.round((completed / total) * 100);
|
||||
const bar = htmx.find('#download-progress');
|
||||
if (!bar) return;
|
||||
bar.style.width = `${percent}%`;
|
||||
bar.textContent = `${percent}%`;
|
||||
bar.setAttribute('aria-valuenow', String(percent));
|
||||
}
|
||||
|
||||
function escapeHtml(str) {
|
||||
return str.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
||||
}
|
||||
@@ -58,6 +90,17 @@ function getMimeType(filename) {
|
||||
return types[ext] || 'application/octet-stream';
|
||||
}
|
||||
|
||||
function combineChunks(chunks) {
|
||||
const size = chunks.reduce((sum, chunk) => sum + chunk.byteLength, 0);
|
||||
const combined = new Uint8Array(size);
|
||||
let offset = 0;
|
||||
for (const chunk of chunks) {
|
||||
combined.set(chunk, offset);
|
||||
offset += chunk.byteLength;
|
||||
}
|
||||
return combined.buffer;
|
||||
}
|
||||
|
||||
function showPreview(filename, plaintext) {
|
||||
const mimeType = getMimeType(filename);
|
||||
const blob = new Blob([plaintext], { type: mimeType });
|
||||
|
||||
@@ -43,27 +43,44 @@ async function startUpload() {
|
||||
<span class="visually-hidden">Loading\u2026</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="drop-zone-text" id="upload-status">Encrypting\u2026</div>`,
|
||||
<div class="drop-zone-text mb-3" id="upload-status">Preparing\u2026</div>
|
||||
<div class="progress" role="progressbar" aria-label="Upload progress" aria-valuemin="0" aria-valuemax="100">
|
||||
<div id="upload-progress" class="progress-bar bg-success" style="width: 0%">0%</div>
|
||||
</div>`,
|
||||
{ swapStyle: 'innerHTML' });
|
||||
|
||||
try {
|
||||
const { payload, hash, base64urlKey } = await encryptFile(await selectedFile.arrayBuffer());
|
||||
const encryptedFile = await encryptFile(selectedFile);
|
||||
|
||||
setStatus('Uploading\u2026');
|
||||
for await (const { index, payload } of encryptedFile.chunks) {
|
||||
const chunkCount = encryptedFile.chunkCount;
|
||||
setProgress(`Encrypting chunk ${index + 1} of ${chunkCount}\u2026`, index, chunkCount);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', new Blob([payload]), selectedFile.name);
|
||||
formData.append('hash', hash);
|
||||
formData.append('name', selectedFile.name);
|
||||
if (expiryDays) formData.append('expiryDays', expiryDays);
|
||||
if (downloadLimit) formData.append('downloadLimit', downloadLimit);
|
||||
setProgress(`Uploading chunk ${index + 1} of ${chunkCount}\u2026`, index + 0.5, chunkCount);
|
||||
const chunkData = new FormData();
|
||||
chunkData.append('chunk', new Blob([payload]), String(index));
|
||||
chunkData.append('hash', encryptedFile.hash);
|
||||
chunkData.append('index', index);
|
||||
|
||||
const response = await fetch('/upload', { method: 'POST', body: formData });
|
||||
const chunkResponse = await fetch('/upload/chunk', { method: 'POST', body: chunkData });
|
||||
if (!chunkResponse.ok) throw new Error(`Chunk upload failed (${chunkResponse.status})`);
|
||||
setProgress(`Uploaded chunk ${index + 1} of ${chunkCount}`, index + 1, chunkCount);
|
||||
}
|
||||
|
||||
setProgress('Finalizing\u2026', encryptedFile.chunkCount, encryptedFile.chunkCount);
|
||||
const metadata = new FormData();
|
||||
metadata.append('hash', encryptedFile.hash);
|
||||
metadata.append('name', selectedFile.name);
|
||||
metadata.append('chunkCount', encryptedFile.chunkCount);
|
||||
if (expiryDays) metadata.append('expiryDays', expiryDays);
|
||||
if (downloadLimit) metadata.append('downloadLimit', downloadLimit);
|
||||
|
||||
const response = await fetch('/upload', { method: 'POST', body: metadata });
|
||||
if (!response.ok) throw new Error(`Server error ${response.status}`);
|
||||
|
||||
htmx.swap(dropZone, await response.text(), { swapStyle: 'innerHTML' });
|
||||
htmx.process(dropZone);
|
||||
htmx.find('#share-link').value = window.location.origin + '/download#' + base64urlKey;
|
||||
htmx.find('#share-link').value = window.location.origin + '/download#' + encryptedFile.base64urlKey;
|
||||
|
||||
} catch (err) {
|
||||
htmx.swap(dropZone, `
|
||||
@@ -79,6 +96,16 @@ function setStatus(msg) {
|
||||
if (el) el.textContent = msg;
|
||||
}
|
||||
|
||||
function setProgress(msg, completed, total) {
|
||||
setStatus(msg);
|
||||
const percent = Math.round((completed / total) * 100);
|
||||
const bar = htmx.find('#upload-progress');
|
||||
if (!bar) return;
|
||||
bar.style.width = `${percent}%`;
|
||||
bar.textContent = `${percent}%`;
|
||||
bar.setAttribute('aria-valuenow', String(percent));
|
||||
}
|
||||
|
||||
function resetUpload() {
|
||||
selectedFile = null;
|
||||
fileInput.value = '';
|
||||
|
||||
@@ -20,7 +20,10 @@
|
||||
<main class="flex-grow-1 d-flex align-items-center justify-content-center py-5 px-3">
|
||||
<div id="download-state" class="drop-zone text-center py-5 px-4" style="max-width: 520px; width: 100%;">
|
||||
<div class="drop-zone-icon mb-3">🔒</div>
|
||||
<div class="drop-zone-text" id="download-status">Preparing…</div>
|
||||
<div class="drop-zone-text mb-3" id="download-status">Preparing…</div>
|
||||
<div class="progress" role="progressbar" aria-label="Download progress" aria-valuemin="0" aria-valuemax="100">
|
||||
<div id="download-progress" class="progress-bar bg-success" style="width: 0%">0%</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user