81 lines
12 KiB
HTML
81 lines
12 KiB
HTML
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
<title>Compress Files</title>
|
||
|
|
||
|
<style>
|
||
|
/* water.css: https://watercss.kognise.dev/ */
|
||
|
:root{--background-body:#202b38;--background:#161f27;--background-alt:#1a242f;--selection:#1c76c5;--text-main:#dbdbdb;--text-bright:#fff;--text-muted:#a9b1ba;--links:#41adff;--focus:rgba(0,150,191,0.67);--border:#526980;--code:#ffbe85;--animation-duration:0.1s;--button-base:#0c151c;--button-hover:#040a0f;--scrollbar-thumb:var(--button-hover);--scrollbar-thumb-hover:#000;--form-placeholder:#a9a9a9;--form-text:#fff;--variable:#d941e2;--highlight:#efdb43;--select-arrow:url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' height='63' width='117' fill='%23efefef'%3E%3Cpath d='M115 2c-1-2-4-2-5 0L59 53 7 2a4 4 0 00-5 5l54 54 2 2 3-2 54-54c2-1 2-4 0-5z'/%3E%3C/svg%3E")}html{scrollbar-color:#040a0f #202b38;scrollbar-color:var(--scrollbar-thumb) var(--background-body);scrollbar-width:thin}body{font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,Fira Sans,Droid Sans,Helvetica Neue,Segoe UI Emoji,Apple Color Emoji,Noto Color Emoji,sans-serif;line-height:1.4;max-width:800px;margin:20px auto;padding:0 10px;word-wrap:break-word;color:#dbdbdb;color:var(--text-main);background:#202b38;background:var(--background-body);text-rendering:optimizeLegibility}button,input,textarea{transition:background-color .1s linear,border-color .1s linear,color .1s linear,box-shadow .1s linear,transform .1s ease;transition:background-color var(--animation-duration) linear,border-color var(--animation-duration) linear,color var(--animation-duration) linear,box-shadow var(--animation-duration) linear,transform var(--animation-duration) ease}h1{font-size:2.2em;margin-top:0}h1,h2,h3,h4,h5,h6{margin-bottom:12px;margin-top:24px}h1,h2,h3,h4,h5,h6,strong{color:#fff;color:var(--text-bright)}b,h1,h2,h3,h4,h5,h6,strong,th{font-weight:600}q:after,q:before{content:none}blockquote,q{border-left:4px solid rgba(0,150,191,.67);border-left:4px solid var(--focus);margin:1.5em 0;padding:.5em 1em;font-style:italic}blockquote>footer{font-style:normal;border:0}address,blockquote cite{font-style:normal}a[href^=mailto\:]:before{content:"📧 "}a[href^=tel\:]:before{content:"📞 "}a[href^=sms\:]:before{content:"💬 "}mark{background-color:#efdb43;background-color:var(--highlight);border-radius:2px;padding:0 2px;color:#000}a>code,a>strong{color:inherit}button,input[type=button],input[type=checkbox],input[type=radio],input[type=range],input[type=reset],input[type=submit],select{cursor:pointer}input,select{display:block}[type=checkbox],[type=radio]{display:initial}button,input,select,textarea{color:#fff;color:var(--form-text);background-color:#161f27;background-color:var(--background);font-family:inherit;font-size:inherit;margin-right:6px;margin-bottom:6px;padding:10px;border:none;border-radius:6px;outline:none}button,input[type=button],input[type=reset],input[type=submit]{background-color:#0c151c;background-color:var(--button-base);padding-right:30px;padding-left:30px}button:hover,input[type=button]:hover,input[type=reset]:hover,input[type=submit]:hover{background:#040a0f;background:var(--button-hover)}input[type=color]{min-height:2rem;padding:8px;cursor:pointer}input[type=checkbox],input[type=radio]{height:1em;width:1em}input[type=radio]{border-radius:100%}input{vertical-align:top}label{vertical-align:middle;margin-bottom:4px;display:inline-block}button,input:not([type=checkbox]):not([type=radio]),input[type=range],select,textarea{-webkit-appearance:none}textarea{display:block;margin-right:0;box-sizing:border-box;resize:vertical}textarea:not([cols]){width:100%}textarea:not([rows]){min-height:40px;height:140px}select{background:#161f27 url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' height='63' width='117' fill='%23efefef'%3E%3Cpath d='M115 2c-1-2-4-2-5 0L59 53 7 2a4 4 0 00-5 5l54 54 2 2 3-2 54-54c2-1 2-4 0-5z'/%3E%3C/svg%3E") calc(100% - 12px) 50%/12px no-repeat;background:var(--background) var(--select-arrow) calc(100% - 12px) 50%/12px no-repeat;padding-right:35px}select::-ms-expand{display:none}select[multiple]{padding-right:10px;background-image:none;overflow-y:auto}but
|
||
|
|
||
|
#download-section {
|
||
|
display: none;
|
||
|
}
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<h1>Compress Files</h1>
|
||
|
<p>Compress files using Huffman Coding</p>
|
||
|
|
||
|
<form action="/api/accept_file" method="POST" enctype="multipart/form-data">
|
||
|
<div>
|
||
|
<label for="file">Choose file to upload</label>
|
||
|
<input type="file" id="file" name="file" />
|
||
|
</div>
|
||
|
<div>
|
||
|
<button>Compress</button>
|
||
|
</div>
|
||
|
</form>
|
||
|
|
||
|
<div id="download-section">
|
||
|
<h3>Original File Size</h3>
|
||
|
<p id="original-size"></p>
|
||
|
<h3>Compressed File Size</h3>
|
||
|
<p id="compressed-size"></p>
|
||
|
<h3>Compression Ratio</h3>
|
||
|
<p id="ratio"></p>
|
||
|
<a id="download" href="#" download>
|
||
|
<button>Download compressed file</button>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<script>
|
||
|
"use strict";
|
||
|
const form = document.querySelector('form');
|
||
|
form.addEventListener('submit', handleSubmit);
|
||
|
|
||
|
function handleSubmit(event) {
|
||
|
const url = new URL(form.action);
|
||
|
const formData = new FormData(form);
|
||
|
|
||
|
/** @type {Parameters<fetch>[1]} */
|
||
|
const fetchOptions = {
|
||
|
method: form.method,
|
||
|
body: formData,
|
||
|
};
|
||
|
|
||
|
// original_file_name = formData.getAll("file")[0].name;
|
||
|
|
||
|
fetch(url, fetchOptions)
|
||
|
.then(response => {
|
||
|
if (!response.ok) {
|
||
|
throw new Error("HTTP error " + response.status);
|
||
|
}
|
||
|
return response.json();
|
||
|
})
|
||
|
.then(json => {
|
||
|
document.getElementById("original-size").innerText = json.original_size + " bytes";
|
||
|
document.getElementById("compressed-size").innerText = json.compressed_size + " bytes";
|
||
|
document.getElementById("ratio").innerText = (json.compressed_size / json.original_size).toFixed(3);
|
||
|
document.getElementById("download").href = "/api/download_file/" + json.file_id;
|
||
|
document.getElementById("download-section").style.display = "unset";
|
||
|
})
|
||
|
|
||
|
event.preventDefault();
|
||
|
}
|
||
|
|
||
|
</script>
|
||
|
|
||
|
</body>
|
||
|
</html>
|