first
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
.cargo/
|
||||||
|
/target
|
||||||
|
/data/storage/*
|
||||||
|
/data/logs/*
|
||||||
11
.vscode/settings.json
vendored
Normal file
11
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"cSpell.words": [
|
||||||
|
"actix",
|
||||||
|
"localtime",
|
||||||
|
"noconfirm",
|
||||||
|
"pacman",
|
||||||
|
"realip",
|
||||||
|
"traceroute",
|
||||||
|
"tzdata"
|
||||||
|
]
|
||||||
|
}
|
||||||
1939
Cargo.lock
generated
Normal file
1939
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
21
Cargo.toml
Normal file
21
Cargo.toml
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
[package]
|
||||||
|
name = "black_hole_share"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
actix-web = "4.12.1"
|
||||||
|
actix-files = "0.6"
|
||||||
|
anyhow = "1.0.100"
|
||||||
|
chrono = "0.4"
|
||||||
|
futures = "0.3.31"
|
||||||
|
serde = { version = "1.0.228", features = ["derive"] }
|
||||||
|
serde_json = "1.0.148"
|
||||||
|
tokio = { version = "1.48.0", features = [
|
||||||
|
"macros",
|
||||||
|
"rt-multi-thread",
|
||||||
|
"signal",
|
||||||
|
"time",
|
||||||
|
] }
|
||||||
|
uuid = { version = "1.19.0", features = ["v4"] }
|
||||||
|
base64 = "0.22.1"
|
||||||
24
Dockerfile
Normal file
24
Dockerfile
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
FROM archlinux:latest
|
||||||
|
|
||||||
|
ENV TERM=xterm-256color
|
||||||
|
|
||||||
|
RUN pacman -Syu --noconfirm --needed \
|
||||||
|
base-devel \
|
||||||
|
git \
|
||||||
|
curl \
|
||||||
|
wget \
|
||||||
|
vim \
|
||||||
|
nano \
|
||||||
|
tzdata \
|
||||||
|
ca-certificates \
|
||||||
|
iputils \
|
||||||
|
net-tools \
|
||||||
|
traceroute \
|
||||||
|
&& pacman -Sc --noconfirm \
|
||||||
|
&& rm -rf /var/cache/pacman/pkg/*
|
||||||
|
|
||||||
|
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
|
||||||
|
ENV PATH="/root/.cargo/bin:${PATH}"
|
||||||
|
|
||||||
|
WORKDIR /data
|
||||||
|
CMD ["black_hole_share"]
|
||||||
341
data/html/index.html
Normal file
341
data/html/index.html
Normal file
@@ -0,0 +1,341 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Image Upload</title>
|
||||||
|
<link rel="stylesheet" href="style.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<h1>Black Hole Share</h1>
|
||||||
|
|
||||||
|
<div class="upload-container">
|
||||||
|
<div class="upload-area">
|
||||||
|
<input type="file" id="fileInput" accept="image/*" style="display: none;">
|
||||||
|
<div id="uploadZone" class="upload-zone">
|
||||||
|
<p>Click to select file, paste image data, or drag & drop</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="duration-container">
|
||||||
|
<label for="durationSlider">Duration: <span id="durationValue">5</span> min</label>
|
||||||
|
<input type="range" id="durationSlider" min="1" max="60" value="5" step="1">
|
||||||
|
<div class="button-row">
|
||||||
|
<button id="resetBtn" class="reset-btn" style="display: none;">Reset</button>
|
||||||
|
<button id="uploadBtn" class="upload-btn" style="display: none;">Upload</button>
|
||||||
|
</div>
|
||||||
|
<div id="linkContainer" class="link-container" style="display: none;">
|
||||||
|
<p>Link:</p>
|
||||||
|
<a id="uploadedLink" href="#" target="_blank"></a>
|
||||||
|
<p id="clipboardMessage" class="clipboard-message" style="display: none;"></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer class="powered-by">
|
||||||
|
<span>Powered by: <img src="logo.png" alt="ICSBox" class="footer-logo"></span>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<!-- Zoom overlay -->
|
||||||
|
<div id="zoomOverlay" class="zoom-overlay" style="display: none;">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
let currentContentData = null;
|
||||||
|
const fileInput = document.getElementById('fileInput');
|
||||||
|
const uploadZone = document.getElementById('uploadZone');
|
||||||
|
const uploadContainer = document.querySelector('.upload-container');
|
||||||
|
const durationSlider = document.getElementById('durationSlider');
|
||||||
|
const durationValue = document.getElementById('durationValue');
|
||||||
|
const uploadBtn = document.getElementById('uploadBtn');
|
||||||
|
const resetBtn = document.getElementById('resetBtn');
|
||||||
|
const zoomOverlay = document.getElementById('zoomOverlay');
|
||||||
|
const linkContainer = document.getElementById('linkContainer');
|
||||||
|
const uploadedLink = document.getElementById('uploadedLink');
|
||||||
|
const clipboardMessage = document.getElementById('clipboardMessage');
|
||||||
|
|
||||||
|
// Update duration display
|
||||||
|
durationSlider.addEventListener('input', function () {
|
||||||
|
durationValue.textContent = this.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
uploadBtn.addEventListener('click', async () => {
|
||||||
|
const duration = durationSlider.value;
|
||||||
|
const isText = uploadZone.querySelector('.text-content') !== null;
|
||||||
|
const mimeType = isText ? 'text/plain' : 'image/png';
|
||||||
|
const contentData = currentContentData;
|
||||||
|
|
||||||
|
if (!contentData) {
|
||||||
|
console.log('❌ No content to upload!');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sendUpload(duration, mimeType, contentData);
|
||||||
|
});
|
||||||
|
|
||||||
|
async function sendUpload(duration, mimeType, contentData) {
|
||||||
|
const isText = mimeType === 'text/plain';
|
||||||
|
let content = contentData;
|
||||||
|
|
||||||
|
// For images, remove data URL prefix to send only base64 string
|
||||||
|
if (!isText && contentData.includes('base64,')) {
|
||||||
|
content = contentData.split('base64,')[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
duration: parseInt(duration),
|
||||||
|
content_type: mimeType,
|
||||||
|
content: content
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/upload', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
console.log(`✅ Upload received!\n${JSON.stringify(result, null, 2)}`);
|
||||||
|
|
||||||
|
// Hide duration controls and buttons
|
||||||
|
document.querySelector('label[for="durationSlider"]').style.display = 'none';
|
||||||
|
durationSlider.style.display = 'none';
|
||||||
|
uploadBtn.style.display = 'none';
|
||||||
|
resetBtn.style.display = 'none';
|
||||||
|
|
||||||
|
// Show link
|
||||||
|
const fullLink = window.location.origin + result.link;
|
||||||
|
uploadedLink.href = fullLink;
|
||||||
|
uploadedLink.textContent = fullLink;
|
||||||
|
linkContainer.style.display = 'block';
|
||||||
|
|
||||||
|
// Copy to clipboard
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(fullLink);
|
||||||
|
clipboardMessage.textContent = '✓ Copied to clipboard!';
|
||||||
|
clipboardMessage.style.color = 'var(--accent-green)';
|
||||||
|
clipboardMessage.style.cursor = 'default';
|
||||||
|
clipboardMessage.style.display = 'block';
|
||||||
|
clipboardMessage.onclick = null;
|
||||||
|
} catch (error) {
|
||||||
|
clipboardMessage.textContent = '⚠ Click here to copy link';
|
||||||
|
clipboardMessage.style.color = 'var(--accent-cyan)';
|
||||||
|
clipboardMessage.style.cursor = 'pointer';
|
||||||
|
clipboardMessage.style.display = 'block';
|
||||||
|
clipboardMessage.onclick = function () {
|
||||||
|
const textArea = document.createElement('textarea');
|
||||||
|
textArea.value = fullLink;
|
||||||
|
textArea.style.position = 'fixed';
|
||||||
|
textArea.style.left = '-999999px';
|
||||||
|
document.body.appendChild(textArea);
|
||||||
|
textArea.select();
|
||||||
|
try {
|
||||||
|
document.execCommand('copy');
|
||||||
|
clipboardMessage.textContent = '✓ Copied to clipboard!';
|
||||||
|
clipboardMessage.style.color = 'var(--accent-green)';
|
||||||
|
clipboardMessage.style.cursor = 'default';
|
||||||
|
clipboardMessage.onclick = null;
|
||||||
|
} catch (e) {
|
||||||
|
clipboardMessage.textContent = '✗ Copy failed';
|
||||||
|
clipboardMessage.style.color = '#ff6666';
|
||||||
|
}
|
||||||
|
document.body.removeChild(textArea);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`❌ Error: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Reset to initial state
|
||||||
|
resetBtn.addEventListener('click', function () {
|
||||||
|
currentContentData = null;
|
||||||
|
uploadZone.innerHTML = '<p>Click to select file, paste image data, or drag & drop</p>';
|
||||||
|
uploadContainer.style.height = '180px';
|
||||||
|
uploadContainer.style.pointerEvents = '';
|
||||||
|
uploadContainer.style.overflow = '';
|
||||||
|
uploadZone.style.pointerEvents = '';
|
||||||
|
uploadZone.style.alignItems = '';
|
||||||
|
uploadZone.style.justifyContent = '';
|
||||||
|
uploadZone.style.padding = '';
|
||||||
|
fileInput.value = '';
|
||||||
|
durationSlider.value = '5';
|
||||||
|
durationValue.textContent = '5';
|
||||||
|
document.querySelector('label[for="durationSlider"]').style.display = '';
|
||||||
|
durationSlider.style.display = '';
|
||||||
|
uploadBtn.style.display = 'none';
|
||||||
|
resetBtn.style.display = 'none';
|
||||||
|
linkContainer.style.display = 'none';
|
||||||
|
clipboardMessage.style.display = 'none';
|
||||||
|
uploadZone.focus();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Display and scale image or text content maintaining aspect ratio
|
||||||
|
function displayContent(content, isText = false) {
|
||||||
|
currentContentData = content;
|
||||||
|
|
||||||
|
if (isText) {
|
||||||
|
// Display text content - ZOOM ENABLED
|
||||||
|
uploadZone.innerHTML = `<div class="text-content" style="cursor: zoom-in;">${content.replace(/</g, '<').replace(/>/g, '>')}</div>`;
|
||||||
|
uploadContainer.style.height = '500px';
|
||||||
|
uploadContainer.style.overflow = 'hidden';
|
||||||
|
uploadZone.style.pointerEvents = 'auto';
|
||||||
|
uploadZone.style.alignItems = 'stretch';
|
||||||
|
uploadZone.style.justifyContent = 'stretch';
|
||||||
|
uploadZone.style.padding = '0';
|
||||||
|
uploadBtn.style.display = 'block';
|
||||||
|
resetBtn.style.display = 'block';
|
||||||
|
|
||||||
|
// ZOOM FOR TEXT
|
||||||
|
const textContent = uploadZone.querySelector('.text-content');
|
||||||
|
textContent.addEventListener('click', function (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
showZoom(content, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Display image
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = function () {
|
||||||
|
const maxWidth = 620;
|
||||||
|
const maxHeight = 800;
|
||||||
|
const scale = Math.min(maxWidth / img.width, maxHeight / img.height, 1);
|
||||||
|
const displayHeight = Math.floor(img.height * scale);
|
||||||
|
const displayWidth = Math.floor(img.width * scale);
|
||||||
|
|
||||||
|
uploadZone.innerHTML = `<img src="${content}" alt="Uploaded Image" style="width: ${displayWidth}px; height: ${displayHeight}px; object-fit: contain; cursor: zoom-in;">`;
|
||||||
|
uploadContainer.style.height = `${displayHeight + 20}px`;
|
||||||
|
uploadContainer.style.pointerEvents = 'none';
|
||||||
|
uploadZone.style.pointerEvents = 'auto';
|
||||||
|
uploadBtn.style.display = 'block';
|
||||||
|
resetBtn.style.display = 'block';
|
||||||
|
|
||||||
|
const uploadedImg = uploadZone.querySelector('img');
|
||||||
|
uploadedImg.addEventListener('click', function (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
showZoom(content, false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
img.src = content;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open file picker on container click (ONLY IF EMPTY)
|
||||||
|
uploadContainer.addEventListener('click', function (e) {
|
||||||
|
if (uploadContainer.style.pointerEvents !== 'none' && !uploadZone.querySelector('.text-content') && !uploadZone.querySelector('img')) {
|
||||||
|
fileInput.click();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fileInput.addEventListener('change', function (e) {
|
||||||
|
const file = e.target.files[0];
|
||||||
|
if (file) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = function (event) {
|
||||||
|
displayContent(event.target.result);
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle paste from clipboard
|
||||||
|
uploadZone.addEventListener('paste', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const items = e.clipboardData.items;
|
||||||
|
|
||||||
|
for (let item of items) {
|
||||||
|
if (item.type.startsWith('image/')) {
|
||||||
|
const file = item.getAsFile();
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = function (event) {
|
||||||
|
displayContent(event.target.result);
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const text = e.clipboardData.getData('text');
|
||||||
|
if (text) {
|
||||||
|
displayContent(text, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Handle drag and drop
|
||||||
|
uploadZone.addEventListener('drop', handleDrop);
|
||||||
|
uploadContainer.addEventListener('drop', handleDrop);
|
||||||
|
|
||||||
|
function handleDrop(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
const file = e.dataTransfer.files[0];
|
||||||
|
if (file && file.type.startsWith('image/')) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.onload = function (event) {
|
||||||
|
displayContent(event.target.result);
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uploadZone.addEventListener('dragover', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
uploadZone.style.borderColor = 'var(--border-hover)';
|
||||||
|
});
|
||||||
|
|
||||||
|
uploadZone.addEventListener('dragleave', function (e) {
|
||||||
|
uploadZone.style.borderColor = '';
|
||||||
|
});
|
||||||
|
|
||||||
|
uploadContainer.addEventListener('dragover', function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
uploadZone.setAttribute('tabindex', '0');
|
||||||
|
|
||||||
|
window.addEventListener('focus', function () {
|
||||||
|
uploadZone.focus();
|
||||||
|
});
|
||||||
|
|
||||||
|
uploadZone.focus();
|
||||||
|
|
||||||
|
// Improved zoom overlay functions
|
||||||
|
function showZoom(content, isText = false) {
|
||||||
|
if (isText) {
|
||||||
|
zoomOverlay.innerHTML = `
|
||||||
|
<div class="zoom-text-content">${content.replace(/</g, '<').replace(/>/g, '>')}</div>
|
||||||
|
`;
|
||||||
|
} else {
|
||||||
|
zoomOverlay.innerHTML = `<img id="zoomImage" src="${content}" alt="Zoomed Image" style="max-width: 95vw; max-height: 95vh; object-fit: contain; box-shadow: 0 0 50px rgba(51, 204, 255, 0.5);">`;
|
||||||
|
}
|
||||||
|
zoomOverlay.style.display = 'flex';
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideZoom() {
|
||||||
|
zoomOverlay.style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
zoomOverlay.addEventListener('click', hideZoom);
|
||||||
|
|
||||||
|
// ESC TO EXIT ZOOM
|
||||||
|
document.addEventListener('keydown', function (e) {
|
||||||
|
if (e.key === 'Escape' || e.key === 'Esc') {
|
||||||
|
hideZoom();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('resize', function () {
|
||||||
|
if (currentContentData) {
|
||||||
|
displayContent(currentContentData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
BIN
data/html/logo.png
Normal file
BIN
data/html/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 195 KiB |
563
data/html/style.css
Normal file
563
data/html/style.css
Normal file
@@ -0,0 +1,563 @@
|
|||||||
|
/* Color variables from Hyprland config */
|
||||||
|
:root {
|
||||||
|
--bg-primary: #1e1e2e;
|
||||||
|
--bg-secondary: #1a1a1a;
|
||||||
|
--bg-tertiary: #1a1a1a;
|
||||||
|
--active-cyan: #33ccff;
|
||||||
|
--active-green: #00ff99;
|
||||||
|
--inactive-gray: #595959;
|
||||||
|
--text-primary: #cdd6f4;
|
||||||
|
--text-secondary: #a6adc8;
|
||||||
|
--border-color: var(--active-cyan);
|
||||||
|
--border-hover: var(--active-green);
|
||||||
|
--accent-cyan: var(--active-cyan);
|
||||||
|
--accent-green: var(--active-green);
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Main layout container */
|
||||||
|
body {
|
||||||
|
font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace, Arial, sans-serif;
|
||||||
|
min-width: 640px;
|
||||||
|
min-height: 360px;
|
||||||
|
width: 660px;
|
||||||
|
height: 100vh;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 20px;
|
||||||
|
padding-bottom: 140px;
|
||||||
|
background-color: var(--bg-tertiary);
|
||||||
|
color: var(--text-primary);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
box-sizing: border-box;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
color: var(--accent-cyan);
|
||||||
|
text-shadow: 0 0 10px rgba(51, 204, 255, 0.3);
|
||||||
|
text-align: center;
|
||||||
|
margin: 0 0 15px 0;
|
||||||
|
font-size: 1.8em;
|
||||||
|
font-weight: bold;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 .home-link {
|
||||||
|
color: var(--accent-cyan);
|
||||||
|
text-decoration: none;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 .home-link:hover {
|
||||||
|
color: var(--accent-green);
|
||||||
|
text-shadow: 0 0 15px rgba(0, 255, 153, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-container {
|
||||||
|
padding: 0;
|
||||||
|
text-align: center;
|
||||||
|
background-color: transparent;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
cursor: pointer;
|
||||||
|
height: 180px;
|
||||||
|
max-height: 500px;
|
||||||
|
overflow: hidden;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.duration-container {
|
||||||
|
margin-top: 15px;
|
||||||
|
padding: 15px;
|
||||||
|
border: 2px solid var(--border-color);
|
||||||
|
border-radius: 12px;
|
||||||
|
background-color: var(--bg-secondary);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.duration-container .button-row {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
gap: 10px;
|
||||||
|
align-items: center;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.duration-container:hover {
|
||||||
|
border-color: var(--border-hover);
|
||||||
|
box-shadow: 0 4px 15px rgba(0, 255, 153, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.duration-container label {
|
||||||
|
color: var(--text-primary);
|
||||||
|
font-size: 0.9em;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#durationSlider {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
appearance: none;
|
||||||
|
width: 100%;
|
||||||
|
height: 6px;
|
||||||
|
border-radius: 3px;
|
||||||
|
background: var(--bg-primary);
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
outline: none;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
#durationSlider::-webkit-slider-thumb {
|
||||||
|
-webkit-appearance: none;
|
||||||
|
appearance: none;
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--border-color);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
#durationSlider::-webkit-slider-thumb:hover {
|
||||||
|
background: var(--border-hover);
|
||||||
|
transform: scale(1.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#durationSlider::-moz-range-thumb {
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--border-color);
|
||||||
|
cursor: pointer;
|
||||||
|
border: none;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
#durationSlider::-moz-range-thumb:hover {
|
||||||
|
background: var(--border-hover);
|
||||||
|
transform: scale(1.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-btn {
|
||||||
|
background-color: var(--border-color);
|
||||||
|
color: var(--bg-tertiary);
|
||||||
|
border: none;
|
||||||
|
padding: 12px 24px;
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 1em;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
box-shadow: 0 2px 10px rgba(51, 204, 255, 0.3);
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-btn:hover {
|
||||||
|
background-color: var(--border-hover);
|
||||||
|
transform: translateY(-2px);
|
||||||
|
box-shadow: 0 4px 15px rgba(0, 255, 153, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-btn:active {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.reset-btn {
|
||||||
|
background-color: var(--border-color);
|
||||||
|
color: var(--bg-tertiary);
|
||||||
|
border: none;
|
||||||
|
padding: 12px 24px;
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 1em;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
box-shadow: 0 2px 10px rgba(51, 204, 255, 0.3);
|
||||||
|
flex: 0 0 10%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.reset-btn:hover {
|
||||||
|
background-color: var(--border-hover);
|
||||||
|
transform: translateY(-2px);
|
||||||
|
box-shadow: 0 4px 15px rgba(0, 255, 153, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.reset-btn:active {
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-container {
|
||||||
|
text-align: center;
|
||||||
|
padding: 15px;
|
||||||
|
background-color: var(--bg-primary);
|
||||||
|
border: 2px solid var(--border-hover);
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 0 20px rgba(0, 255, 153, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-container p {
|
||||||
|
margin: 0 0 10px 0;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-container a {
|
||||||
|
color: var(--accent-green);
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: bold;
|
||||||
|
word-break: break-all;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link-container a:hover {
|
||||||
|
color: var(--accent-cyan);
|
||||||
|
text-shadow: 0 0 10px rgba(51, 204, 255, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.clipboard-message {
|
||||||
|
margin: 10px 0 0 0;
|
||||||
|
font-size: 0.85em;
|
||||||
|
font-style: italic;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.clipboard-message:hover {
|
||||||
|
text-shadow: 0 0 5px currentColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-area {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
flex: 1;
|
||||||
|
justify-content: center;
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Upload zone - SENZA translateY su hover */
|
||||||
|
.upload-zone {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
padding: 10px;
|
||||||
|
border: 2px dashed var(--border-color);
|
||||||
|
border-radius: 12px;
|
||||||
|
background-color: var(--bg-secondary);
|
||||||
|
color: var(--text-secondary);
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.3s ease, background-color 0.3s ease, box-shadow 0.3s ease;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
text-align: center;
|
||||||
|
outline: none;
|
||||||
|
min-height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
position: relative;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-zone:hover {
|
||||||
|
border-color: var(--border-hover);
|
||||||
|
background-color: var(--bg-primary);
|
||||||
|
color: var(--text-primary);
|
||||||
|
box-shadow: 0 4px 15px rgba(0, 255, 153, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Container per testo - riempie tutto */
|
||||||
|
.upload-zone:has(.text-content) {
|
||||||
|
padding: 0 !important;
|
||||||
|
align-items: stretch !important;
|
||||||
|
justify-content: stretch !important;
|
||||||
|
position: relative !important;
|
||||||
|
height: 100% !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Upload container altezza precisa per testo */
|
||||||
|
.upload-container:has(.text-content) {
|
||||||
|
height: 500px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TEXT CONTENT - NO SPAZIO SOTTO + PERFETTAMENTE CENTRATO */
|
||||||
|
.text-content {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 620px;
|
||||||
|
height: 480px !important;
|
||||||
|
max-height: 480px !important;
|
||||||
|
min-height: 480px !important;
|
||||||
|
overflow-y: scroll !important;
|
||||||
|
overflow-x: hidden !important;
|
||||||
|
text-align: left;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-wrap: break-word;
|
||||||
|
word-break: break-word;
|
||||||
|
color: var(--text-primary);
|
||||||
|
background-color: var(--bg-secondary);
|
||||||
|
font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
|
||||||
|
font-size: 0.9em;
|
||||||
|
line-height: 1.5;
|
||||||
|
padding: 15px;
|
||||||
|
margin: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border-radius: 12px;
|
||||||
|
position: absolute;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
cursor: zoom-in;
|
||||||
|
border: none !important;
|
||||||
|
box-shadow: none !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-content::-webkit-scrollbar {
|
||||||
|
width: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-content::-webkit-scrollbar-track {
|
||||||
|
background: var(--bg-primary);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-content::-webkit-scrollbar-thumb {
|
||||||
|
background: var(--border-color);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-content::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: var(--border-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ZOOM TEXT OVERLAY */
|
||||||
|
.zoom-text-content {
|
||||||
|
max-width: 90vw;
|
||||||
|
max-height: 90vh;
|
||||||
|
overflow-y: auto;
|
||||||
|
overflow-x: hidden;
|
||||||
|
padding: 30px;
|
||||||
|
background-color: var(--bg-secondary);
|
||||||
|
border: 2px solid var(--border-hover);
|
||||||
|
border-radius: 12px;
|
||||||
|
font-family: 'JetBrains Mono', monospace;
|
||||||
|
font-size: 1.2em;
|
||||||
|
line-height: 1.6;
|
||||||
|
color: var(--text-primary);
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-wrap: break-word;
|
||||||
|
box-shadow: 0 0 50px rgba(0, 255, 153, 0.5);
|
||||||
|
scrollbar-width: thin;
|
||||||
|
}
|
||||||
|
|
||||||
|
.zoom-text-content::-webkit-scrollbar {
|
||||||
|
width: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.zoom-text-content::-webkit-scrollbar-track {
|
||||||
|
background: var(--bg-primary);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.zoom-text-content::-webkit-scrollbar-thumb {
|
||||||
|
background: var(--border-color);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.zoom-text-content::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: var(--border-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Zoom overlay */
|
||||||
|
.zoom-overlay {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
background-color: rgba(0, 0, 0, 0.95);
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 9999;
|
||||||
|
cursor: zoom-out;
|
||||||
|
padding: 20px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
.zoom-overlay img {
|
||||||
|
max-width: 95vw;
|
||||||
|
max-height: 95vh;
|
||||||
|
object-fit: contain;
|
||||||
|
box-shadow: 0 0 50px rgba(51, 204, 255, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-zone:focus {
|
||||||
|
outline: none;
|
||||||
|
border-color: var(--border-hover);
|
||||||
|
box-shadow: 0 0 10px rgba(0, 255, 153, 0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-zone:focus-within .text-content {
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload-zone p {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Custom scrollbar styling */
|
||||||
|
::-webkit-scrollbar {
|
||||||
|
width: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-track {
|
||||||
|
background: var(--bg-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb {
|
||||||
|
background: var(--border-color);
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: var(--border-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* View page styles */
|
||||||
|
body.view-page {
|
||||||
|
width: 860px;
|
||||||
|
padding-bottom: 140px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.view-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: flex-start;
|
||||||
|
flex: 1;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.powered-by {
|
||||||
|
position: fixed;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
text-align: center;
|
||||||
|
padding: 15px;
|
||||||
|
background-color: var(--bg-secondary);
|
||||||
|
border-top: 1px solid var(--border-color);
|
||||||
|
font-size: 0.9em;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.powered-by .home-link {
|
||||||
|
color: var(--accent-cyan);
|
||||||
|
text-decoration: none;
|
||||||
|
font-weight: bold;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.powered-by .home-link:hover {
|
||||||
|
color: var(--accent-green);
|
||||||
|
text-shadow: 0 0 10px rgba(0, 255, 153, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer-logo {
|
||||||
|
height: 40px;
|
||||||
|
vertical-align: middle;
|
||||||
|
margin-left: 5px;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.powered-by a:hover .footer-logo {
|
||||||
|
filter: brightness(1.3) drop-shadow(0 0 5px rgba(0, 255, 153, 0.5));
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-area {
|
||||||
|
width: 800px;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 10px;
|
||||||
|
border: 2px dashed var(--border-color);
|
||||||
|
border-radius: 12px;
|
||||||
|
background-color: var(--bg-secondary);
|
||||||
|
min-height: 400px;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-area:hover {
|
||||||
|
border-color: var(--border-hover);
|
||||||
|
box-shadow: 0 4px 15px rgba(0, 255, 153, 0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-area .loading {
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: 1.1em;
|
||||||
|
animation: pulse 1.5s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-area .error {
|
||||||
|
color: #ff6666;
|
||||||
|
font-size: 1.1em;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes pulse {
|
||||||
|
|
||||||
|
0%,
|
||||||
|
100% {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
50% {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-content-view {
|
||||||
|
width: 760px;
|
||||||
|
max-height: 560px;
|
||||||
|
overflow-y: auto;
|
||||||
|
overflow-x: hidden;
|
||||||
|
text-align: left;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-wrap: break-word;
|
||||||
|
word-break: break-word;
|
||||||
|
color: var(--text-primary);
|
||||||
|
background-color: var(--bg-primary);
|
||||||
|
font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
|
||||||
|
font-size: 0.9em;
|
||||||
|
line-height: 1.5;
|
||||||
|
padding: 15px;
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: zoom-in;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-content-view::-webkit-scrollbar {
|
||||||
|
width: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-content-view::-webkit-scrollbar-track {
|
||||||
|
background: var(--bg-secondary);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-content-view::-webkit-scrollbar-thumb {
|
||||||
|
background: var(--border-color);
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.text-content-view::-webkit-scrollbar-thumb:hover {
|
||||||
|
background: var(--border-hover);
|
||||||
|
}
|
||||||
123
data/html/view.html
Normal file
123
data/html/view.html
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Black Hole Share - View</title>
|
||||||
|
<link rel="stylesheet" href="/style.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body class="view-page">
|
||||||
|
<h1><a href="/" class="home-link">Black Hole Share</a></h1>
|
||||||
|
|
||||||
|
<div class="view-container">
|
||||||
|
<div id="contentArea" class="content-area">
|
||||||
|
<p class="loading">Loading...</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<footer class="powered-by">
|
||||||
|
<span>Powered by: <img src="/logo.png" alt="ICSBox" class="footer-logo"></span>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
<!-- Zoom overlay -->
|
||||||
|
<div id="zoomOverlay" class="zoom-overlay" style="display: none;"></div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const contentArea = document.getElementById('contentArea');
|
||||||
|
const zoomOverlay = document.getElementById('zoomOverlay');
|
||||||
|
|
||||||
|
// Get asset ID from URL path
|
||||||
|
const pathParts = window.location.pathname.split('/');
|
||||||
|
const assetId = pathParts[pathParts.length - 1];
|
||||||
|
|
||||||
|
async function loadContent() {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/content/${assetId}`);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
if (response.status === 404) {
|
||||||
|
contentArea.innerHTML = '<p class="error">Content not found or expired</p>';
|
||||||
|
} else {
|
||||||
|
contentArea.innerHTML = '<p class="error">Error loading content</p>';
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const contentType = response.headers.get('content-type');
|
||||||
|
|
||||||
|
if (contentType.startsWith('image/')) {
|
||||||
|
// Display image
|
||||||
|
const blob = await response.blob();
|
||||||
|
const imageUrl = URL.createObjectURL(blob);
|
||||||
|
|
||||||
|
const img = new Image();
|
||||||
|
img.onload = function () {
|
||||||
|
const maxWidth = 780;
|
||||||
|
const maxHeight = 760;
|
||||||
|
const scale = Math.min(maxWidth / img.width, maxHeight / img.height, 1);
|
||||||
|
const displayHeight = Math.floor(img.height * scale);
|
||||||
|
const displayWidth = Math.floor(img.width * scale);
|
||||||
|
|
||||||
|
contentArea.innerHTML = `<img src="${imageUrl}" alt="Shared Content"
|
||||||
|
style="width: ${displayWidth}px; height: ${displayHeight}px; object-fit: contain; cursor: zoom-in;">`;
|
||||||
|
|
||||||
|
const displayedImg = contentArea.querySelector('img');
|
||||||
|
displayedImg.addEventListener('click', function (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
showZoom(imageUrl, false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
img.src = imageUrl;
|
||||||
|
|
||||||
|
} else if (contentType.startsWith('text/')) {
|
||||||
|
// Display text
|
||||||
|
const text = await response.text();
|
||||||
|
contentArea.innerHTML = `<div class="text-content-view" style="cursor: zoom-in;">${text.replace(/</g, '<').replace(/>/g, '>')}</div>`;
|
||||||
|
|
||||||
|
const textContent = contentArea.querySelector('.text-content-view');
|
||||||
|
textContent.addEventListener('click', function (e) {
|
||||||
|
e.stopPropagation();
|
||||||
|
showZoom(text, true);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
contentArea.innerHTML = '<p class="error">Unsupported content type</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error loading content:', error);
|
||||||
|
contentArea.innerHTML = '<p class="error">Failed to load content</p>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showZoom(content, isText = false) {
|
||||||
|
if (isText) {
|
||||||
|
zoomOverlay.innerHTML = `
|
||||||
|
<div class="zoom-text-content">${content.replace(/</g, '<').replace(/>/g, '>')}</div>
|
||||||
|
`;
|
||||||
|
} else {
|
||||||
|
zoomOverlay.innerHTML = `<img id="zoomImage" src="${content}" alt="Zoomed Content"
|
||||||
|
style="max-width: 95vw; max-height: 95vh; object-fit: contain; box-shadow: 0 0 50px rgba(51, 204, 255, 0.5);">`;
|
||||||
|
}
|
||||||
|
zoomOverlay.style.display = 'flex';
|
||||||
|
}
|
||||||
|
|
||||||
|
function hideZoom() {
|
||||||
|
zoomOverlay.style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
zoomOverlay.addEventListener('click', hideZoom);
|
||||||
|
|
||||||
|
document.addEventListener('keydown', function (e) {
|
||||||
|
if (e.key === 'Escape' || e.key === 'Esc') {
|
||||||
|
hideZoom();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Load content on page load
|
||||||
|
loadContent();
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
15
docker-compose.yaml
Normal file
15
docker-compose.yaml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
services:
|
||||||
|
bhs:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: black_hole_share
|
||||||
|
volumes:
|
||||||
|
- ./data:/data
|
||||||
|
- /etc/localtime:/etc/localtime:ro
|
||||||
|
environment:
|
||||||
|
- TZ="Europe/Rome"
|
||||||
|
tty: true
|
||||||
|
stdin_open: true
|
||||||
|
ports:
|
||||||
|
- "8080:80"
|
||||||
50
src/api.rs
Normal file
50
src/api.rs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
use actix_web::{HttpRequest, HttpResponse, get, post, web};
|
||||||
|
use base64::{Engine, engine::general_purpose};
|
||||||
|
use serde::Deserialize;
|
||||||
|
use serde_json::json;
|
||||||
|
|
||||||
|
use crate::{DATA_STORAGE, logs::log_to_file};
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
pub struct UploadRequest {
|
||||||
|
duration: u32,
|
||||||
|
content_type: String,
|
||||||
|
content: String, // text or base64 string
|
||||||
|
}
|
||||||
|
|
||||||
|
#[post("/api/upload")]
|
||||||
|
async fn api_upload(req: web::Json<UploadRequest>) -> Result<HttpResponse, actix_web::Error> {
|
||||||
|
// Convert to bytes
|
||||||
|
let content_bytes = if req.content_type == "text/plain" {
|
||||||
|
req.content.as_bytes().to_vec() // UTF-8 bytes
|
||||||
|
} else {
|
||||||
|
// Decode base64 → bytes
|
||||||
|
general_purpose::STANDARD.decode(&req.content).unwrap()
|
||||||
|
};
|
||||||
|
let asset = crate::data_mgt::Asset::new(req.duration, req.content_type.clone(), content_bytes);
|
||||||
|
|
||||||
|
let id = asset
|
||||||
|
.save()
|
||||||
|
.map_err(|e| actix_web::error::ErrorInternalServerError(format!("Failed to save asset: {}", e)))?;
|
||||||
|
|
||||||
|
let response_body = json!({ "link": format!("/bhs/{}", id) });
|
||||||
|
Ok(HttpResponse::Ok().json(response_body))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/api/content/{id}")]
|
||||||
|
async fn api_get_asset(req: HttpRequest, path: web::Path<String>) -> Result<HttpResponse, actix_web::Error> {
|
||||||
|
let now = std::time::Instant::now();
|
||||||
|
|
||||||
|
let id = path.into_inner();
|
||||||
|
let asset_path = format!("{}{}", DATA_STORAGE, id);
|
||||||
|
let data = std::fs::read(&asset_path).map_err(|_| actix_web::error::ErrorNotFound("Asset not found"))?;
|
||||||
|
let asset = serde_json::from_slice::<crate::data_mgt::Asset>(&data)
|
||||||
|
.map_err(|_| actix_web::error::ErrorInternalServerError("Failed to parse asset data"))?;
|
||||||
|
|
||||||
|
if asset.is_expired() {
|
||||||
|
return Err(actix_web::error::ErrorNotFound("Asset has expired"));
|
||||||
|
}
|
||||||
|
|
||||||
|
log_to_file(&req, now);
|
||||||
|
Ok(HttpResponse::Ok().content_type(asset.mime()).body(asset.content()))
|
||||||
|
}
|
||||||
76
src/data_mgt.rs
Normal file
76
src/data_mgt.rs
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
use anyhow::Result;
|
||||||
|
use chrono::{Duration, Utc};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::DATA_STORAGE;
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||||
|
pub struct Asset {
|
||||||
|
id: String,
|
||||||
|
share_duration: u32,
|
||||||
|
created_at: i64,
|
||||||
|
expires_at: i64,
|
||||||
|
mime: String,
|
||||||
|
content: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Asset {
|
||||||
|
pub fn new(share_duration: u32, mime: String, content: Vec<u8>) -> Self {
|
||||||
|
let id = uuid::Uuid::new_v4().to_string();
|
||||||
|
let created_at = Utc::now().timestamp_millis();
|
||||||
|
let expires_at = created_at + Duration::minutes(share_duration as i64).num_milliseconds();
|
||||||
|
Asset {
|
||||||
|
id,
|
||||||
|
share_duration,
|
||||||
|
created_at,
|
||||||
|
expires_at,
|
||||||
|
mime,
|
||||||
|
content,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn is_expired(&self) -> bool {
|
||||||
|
Utc::now().timestamp_millis() > self.expires_at
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn id(&self) -> &str {
|
||||||
|
&self.id
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn mime(&self) -> &str {
|
||||||
|
&self.mime
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn content(&self) -> Vec<u8> {
|
||||||
|
self.content.clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_bytes(&self) -> Result<Vec<u8>> {
|
||||||
|
let bytes = serde_json::to_vec(self)?;
|
||||||
|
Ok(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn save(&self) -> Result<String> {
|
||||||
|
let id = self.id.clone();
|
||||||
|
let path = format!("{}{}", DATA_STORAGE, self.id);
|
||||||
|
std::fs::create_dir_all(DATA_STORAGE)?;
|
||||||
|
std::fs::write(&path, self.to_bytes()?)?;
|
||||||
|
Ok(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn clear_assets() -> Result<()> {
|
||||||
|
let entries = std::fs::read_dir(DATA_STORAGE)?;
|
||||||
|
for entry in entries {
|
||||||
|
let entry = entry?;
|
||||||
|
let path = entry.path();
|
||||||
|
if path.is_file() {
|
||||||
|
let data = std::fs::read(&path)?;
|
||||||
|
let asset = serde_json::from_slice::<Asset>(&data)?;
|
||||||
|
if asset.is_expired() {
|
||||||
|
println!("Removing expired asset: {}", asset.id());
|
||||||
|
std::fs::remove_file(&path)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
47
src/logs.rs
Normal file
47
src/logs.rs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
use std::{
|
||||||
|
fs::{self, OpenOptions},
|
||||||
|
io::Write,
|
||||||
|
time::Instant,
|
||||||
|
};
|
||||||
|
|
||||||
|
use actix_web::HttpRequest;
|
||||||
|
|
||||||
|
use crate::LOG_DIR;
|
||||||
|
|
||||||
|
pub fn log_to_file(req: &HttpRequest, start: Instant) {
|
||||||
|
let delta = start.elapsed().as_nanos();
|
||||||
|
println!("Request processed in {} ns", delta);
|
||||||
|
let duration_ms = delta as f64 / 1000_000.0;
|
||||||
|
let _ = fs::create_dir_all(LOG_DIR);
|
||||||
|
|
||||||
|
let log_path = LOG_DIR.to_string() + "access.log";
|
||||||
|
|
||||||
|
let Ok(mut file) = OpenOptions::new().create(true).append(true).open(log_path) else {
|
||||||
|
eprintln!("failed to open log file");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
let ts = chrono::Local::now().to_rfc3339();
|
||||||
|
|
||||||
|
let method = req.method();
|
||||||
|
let uri = req.uri();
|
||||||
|
let path = uri.path();
|
||||||
|
let query = uri.query().unwrap_or("-");
|
||||||
|
|
||||||
|
let connection_info = req.connection_info();
|
||||||
|
let scheme = connection_info.scheme();
|
||||||
|
let ip = connection_info.peer_addr().unwrap_or("-");
|
||||||
|
let real_ip = connection_info.realip_remote_addr().unwrap_or("-");
|
||||||
|
|
||||||
|
let ua = req
|
||||||
|
.headers()
|
||||||
|
.get("user-agent")
|
||||||
|
.and_then(|v| v.to_str().ok())
|
||||||
|
.unwrap_or("-");
|
||||||
|
|
||||||
|
let line = format!(
|
||||||
|
"{ts} scheme={scheme} ip={ip} real_ip={real_ip} method={method} path={path} qs={query} dur_ms={duration_ms} ua=\"{ua}\"\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
let _ = file.write_all(line.as_bytes());
|
||||||
|
}
|
||||||
81
src/main.rs
Normal file
81
src/main.rs
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
mod api;
|
||||||
|
mod data_mgt;
|
||||||
|
mod logs;
|
||||||
|
use actix_files::NamedFile;
|
||||||
|
|
||||||
|
use actix_web::{
|
||||||
|
App, HttpRequest, HttpResponse, HttpServer, get, route,
|
||||||
|
web::{self},
|
||||||
|
};
|
||||||
|
use serde_json::Value;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
pub static BIND_ADDR: &str = "0.0.0.0";
|
||||||
|
pub static BIND_PORT: u16 = 80;
|
||||||
|
pub static STATIC_PAGES: &[&str] = &["index.html", "style.css", "view.html", "logo.png"];
|
||||||
|
pub static HTML_DIR: &str = "html/";
|
||||||
|
pub static LOG_DIR: &str = "logs/";
|
||||||
|
pub static DATA_STORAGE: &str = "storage/";
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
api::{api_get_asset, api_upload},
|
||||||
|
logs::log_to_file,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[get("/")]
|
||||||
|
async fn index(reg: HttpRequest) -> actix_web::Result<NamedFile> {
|
||||||
|
let now = std::time::Instant::now();
|
||||||
|
let path: PathBuf = PathBuf::from(HTML_DIR.to_string() + "index.html");
|
||||||
|
log_to_file(®, now);
|
||||||
|
Ok(NamedFile::open(path)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/bhs/{id}")]
|
||||||
|
async fn view_asset(req: HttpRequest) -> actix_web::Result<NamedFile> {
|
||||||
|
let now = std::time::Instant::now();
|
||||||
|
let path: PathBuf = PathBuf::from(HTML_DIR.to_string() + "view.html");
|
||||||
|
log_to_file(&req, now);
|
||||||
|
Ok(NamedFile::open(path)?)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[route("/{tail:.*}", method = "GET", method = "POST")]
|
||||||
|
async fn catch_all(req: HttpRequest, _payload: Option<web::Json<Value>>) -> actix_web::Result<HttpResponse> {
|
||||||
|
let now = std::time::Instant::now();
|
||||||
|
|
||||||
|
let response = match req.uri().path() {
|
||||||
|
path if STATIC_PAGES.contains(&&path[1..]) => {
|
||||||
|
let file_path = HTML_DIR.to_string() + path;
|
||||||
|
Ok(NamedFile::open(file_path)?.into_response(&req))
|
||||||
|
}
|
||||||
|
_ => Ok(HttpResponse::NotFound().body("Not Found")),
|
||||||
|
};
|
||||||
|
|
||||||
|
log_to_file(&req, now);
|
||||||
|
response
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
|
println!("Starting server at http://{}:{}/", BIND_ADDR, BIND_PORT);
|
||||||
|
tokio::spawn(async {
|
||||||
|
let mut interval = tokio::time::interval(tokio::time::Duration::from_secs(60));
|
||||||
|
loop {
|
||||||
|
interval.tick().await;
|
||||||
|
if let Err(e) = data_mgt::clear_assets().await {
|
||||||
|
eprintln!("Error clearing assets: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
HttpServer::new(|| {
|
||||||
|
App::new()
|
||||||
|
.app_data(web::JsonConfig::default().limit(1024 * 1024 * 3))
|
||||||
|
.service(index)
|
||||||
|
.service(view_asset)
|
||||||
|
.service(api_get_asset)
|
||||||
|
.service(api_upload)
|
||||||
|
.service(catch_all)
|
||||||
|
})
|
||||||
|
.bind((BIND_ADDR, BIND_PORT))?
|
||||||
|
.run()
|
||||||
|
.await
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user