htmx is so cool
This commit is contained in:
parent
e04ef78a42
commit
3ed7b0b5c7
11 changed files with 557 additions and 400 deletions
|
@ -1,75 +1,87 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Embedder</title>
|
||||
<link rel="stylesheet" href="/css/base.css">
|
||||
<link rel="stylesheet" href="/css/index.css">
|
||||
<link rel="stylesheet" href="/css/app.css">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
||||
<link rel="manifest" href="/site.webmanifest">
|
||||
<script src="https://unpkg.com/htmx.org@1.9.8"></script>
|
||||
</head>
|
||||
<body>
|
||||
<section class="embedderapp">
|
||||
<header class="header">
|
||||
<h1>Embedder</h1>
|
||||
<nav class="nav">
|
||||
<ul class="left-ul">
|
||||
<li class="user"><%= user.name || user.username %></li>
|
||||
<li>
|
||||
<form action="/logout" method="post">
|
||||
<button class="logout" type="submit"></button>
|
||||
</form>
|
||||
</li>
|
||||
<% if (user.name == "admin" || user.username == "admin") { %>
|
||||
<li>
|
||||
<button class="adduser" onclick="location.href='/adduser';"></a></button>
|
||||
</li>
|
||||
<% } %>
|
||||
</ul>
|
||||
<input type="text" id="search" name="search" placeholder="Search" value=""/>
|
||||
</nav>
|
||||
</header>
|
||||
<form action="/" method="post" encType="multipart/form-data">
|
||||
<div id="dropArea">
|
||||
<p class="dragregion">Upload a file, copy paste, or drag n' drop into the dashed region</p>
|
||||
<div id="gallery"></div>
|
||||
<p class="dragregion"><input class="" type="file" id="fileupload" name="fileupload"><input type="button" value="Upload" id="submit" onclick="uploadFile()"></p>
|
||||
<br>
|
||||
<br>
|
||||
<p class="dragregion">
|
||||
Select file expiration date:
|
||||
<select name="expire" id="expire">
|
||||
<option value="0.00069">1 minute</option>
|
||||
<option value="0.00347">5 minutes</option>
|
||||
<option value="0.0417">1 hour</option>
|
||||
<option value="0.25">6 hours</option>
|
||||
<option value="1">1 day</option>
|
||||
<option value="7">7 days</option>
|
||||
<option value="14">14 days</option>
|
||||
<option value="30">30 days</option>
|
||||
<option selected value="">never</option>
|
||||
</select>
|
||||
</p>
|
||||
<p class="dragregion">Click the file to copy the url</p>
|
||||
</div>
|
||||
</form>
|
||||
<section class="main">
|
||||
<ul class="embedder-list">
|
||||
<% if (files && files.length > 0) { %>
|
||||
<%- include('partials/_fileList.ejs',) %>
|
||||
<% } %>
|
||||
</ul>
|
||||
</section>
|
||||
</section>
|
||||
<footer class="info">
|
||||
<p><a href="https://l.nekomimi.pet/project">Created by Wavering Ana</a></p>
|
||||
<p><a href="https://github.com/WaveringAna/Embedder">Github</a></p>
|
||||
</footer>
|
||||
<script src="/js/index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Embedder</title>
|
||||
<link rel="stylesheet" href="/css/base.css">
|
||||
<link rel="stylesheet" href="/css/index.css">
|
||||
<link rel="stylesheet" href="/css/app.css">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
||||
<link rel="manifest" href="/site.webmanifest">
|
||||
<script src="https://unpkg.com/htmx.org@1.9.8"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<section class="embedderapp">
|
||||
<header class="header">
|
||||
<h1>Embedder</h1>
|
||||
<nav class="nav">
|
||||
<ul class="left-ul">
|
||||
<li class="user"><%= user.name || user.username %></li>
|
||||
<li>
|
||||
<form action="/logout" method="post">
|
||||
<button class="logout" type="submit"></button>
|
||||
</form>
|
||||
</li>
|
||||
<% if (user.name == "admin" || user.username == "admin") { %>
|
||||
<li>
|
||||
<button class="adduser" onclick="location.href='/adduser';"></a></button>
|
||||
</li>
|
||||
<% } %>
|
||||
</ul>
|
||||
<input type="text" id="search" name="search" placeholder="Search" value="" />
|
||||
</nav>
|
||||
</header>
|
||||
<form hx-post="/" encType="multipart/form-data" hx-target="#embedder-list" hx-swap="innerHTML">
|
||||
<div id="dropArea">
|
||||
<p class="dragregion">Upload a file, copy paste, or drag n' drop into the dashed region</p>
|
||||
<div id="gallery"></div>
|
||||
<p class="dragregion"><input class="" type="file" id="fileupload" name="fileupload"><input type="button" value="Upload" id="submit" onclick="uploadFile()"></p>
|
||||
<br>
|
||||
<br>
|
||||
<p class="dragregion">
|
||||
Select file expiration date:
|
||||
<select name="expire" id="expire">
|
||||
<option value="0.00069">1 minute</option>
|
||||
<option value="0.00347">5 minutes</option>
|
||||
<option value="0.0417">1 hour</option>
|
||||
<option value="0.25">6 hours</option>
|
||||
<option value="1">1 day</option>
|
||||
<option value="7">7 days</option>
|
||||
<option value="14">14 days</option>
|
||||
<option value="30">30 days</option>
|
||||
<option selected value="">never</option>
|
||||
</select>
|
||||
</p>
|
||||
<p class="dragregion">Click the file to copy the url</p>
|
||||
</div>
|
||||
</form>
|
||||
<section class="main">
|
||||
<ul id="embedder-list" class="embedder-list" hx-get="/media-list" hx-trigger="load"></ul>
|
||||
</section>
|
||||
</section>
|
||||
<footer class="info">
|
||||
<p><a href="https://l.nekomimi.pet/project">Created by Wavering Ana</a></p>
|
||||
<p><a href="https://github.com/WaveringAna/Embedder">Github</a></p>
|
||||
</footer>
|
||||
<script src="/js/index.js"></script>
|
||||
<script>
|
||||
document.body.addEventListener('htmx:afterSettle', function(event) {
|
||||
var swappedElement = event.target;
|
||||
|
||||
if (swappedElement.id === 'embedder-list' || swappedElement.closest('#embedder-list')) {
|
||||
console.log('htmx:afterSwap', swappedElement.id);
|
||||
files = JSON.parse('<%- JSON.stringify(files) %>');
|
||||
refreshMediaList(files);
|
||||
console.log(files);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -7,170 +7,61 @@ const videoExtensions = ['.mp4', '.mov', '.avi', '.flv', '.mkv', '.wmv', '.webm'
|
|||
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.svg', '.tiff', '.webp'];
|
||||
%>
|
||||
|
||||
<script>
|
||||
let files = JSON.parse('<%- JSON.stringify(files) %>');
|
||||
const videoExtensions = ['.mp4', '.mov', '.avi', '.flv', '.mkv', '.wmv', '.webm'];
|
||||
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.svg', '.tiff', '.webp'];
|
||||
|
||||
function extension(string) {
|
||||
console.log(string)
|
||||
const file = string.split("/").pop();
|
||||
return [
|
||||
file.substr(0, file.lastIndexOf(".")),
|
||||
file.substr(file.lastIndexOf("."), file.length).toLowerCase(),
|
||||
];
|
||||
}
|
||||
|
||||
console.log(files)
|
||||
files.forEach(file => {
|
||||
if (videoExtensions.includes(extension(file.path)[1])) {
|
||||
console.log(`Fetching /uploads/720p-${file.path}.processing`)
|
||||
fetch(`/uploads/720p-${file.path}.processing`)
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
// Video is still processing
|
||||
console.log(`File /uploads/720p-${file.path}.processing exists, starting check...`)
|
||||
checkFileAvailability(file.path);
|
||||
} else {
|
||||
// Video done processing, display it immediately
|
||||
console.log(`File /uploads/720p-${file.path}.processing no longer exists, displaying...`)
|
||||
createVideoElement(file.path);
|
||||
}
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
}
|
||||
});
|
||||
|
||||
function checkFileAvailability(filePath) {
|
||||
const interval = setInterval(() => {
|
||||
fetch(`/uploads/720p-${filePath}.processing`)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
clearInterval(interval);
|
||||
createVideoElement(filePath);
|
||||
}
|
||||
})
|
||||
.catch(error => console.error('Error:', error));
|
||||
}, 5000); // Check every 5 seconds
|
||||
}
|
||||
|
||||
function createVideoElement(filePath) {
|
||||
const videoContainer = document.getElementById(`video-${filePath}`);
|
||||
videoContainer.innerHTML = `
|
||||
<video class="image" autoplay loop muted playsinline loading="lazy">
|
||||
<source src="/uploads/720p-${filePath}" loading="lazy">
|
||||
</video>
|
||||
`;
|
||||
videoContainer.style.display = 'block';
|
||||
document.getElementById(`spinner-${filePath}`).style.display = 'none';
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.spinner {
|
||||
/* Positioning and Sizing */
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
position: relative;
|
||||
margin: 50px auto; /* Centering the spinner */
|
||||
|
||||
/* Text Styling */
|
||||
color: #555;
|
||||
text-align: center;
|
||||
font-family: Arial, sans-serif;
|
||||
font-size: 14px;
|
||||
padding-top: 80px; /* Adjust as needed for text position */
|
||||
|
||||
/* Adding a background to the spinner for better visibility */
|
||||
background-color: rgba(255, 255, 255, 0.8);
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
/* Keyframes for the spinner animation */
|
||||
@keyframes spin {
|
||||
0% { transform: rotate(0deg); }
|
||||
100% { transform: rotate(360deg); }
|
||||
}
|
||||
|
||||
/* Spinner Animation */
|
||||
.spinner::before {
|
||||
content: '';
|
||||
box-sizing: border-box;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
width: 40px; /* Spinner Size */
|
||||
height: 40px;
|
||||
margin-top: -20px; /* Half of height */
|
||||
margin-left: -20px; /* Half of width */
|
||||
border-radius: 50%;
|
||||
border: 2px solid transparent;
|
||||
border-top-color: #007bff; /* Spinner Color */
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
<!-- _fileList.ejs -->
|
||||
<% files.forEach(function(file) { %>
|
||||
<li id="<%= file.path %>" class="show">
|
||||
<form action="<%= file.url %>" method="post">
|
||||
<div class="view">
|
||||
<% if (videoExtensions.includes(extension(file.path))) { %>
|
||||
<!-- Show spinner initially -->
|
||||
<div id="spinner-<%= file.path %>" class="spinner">Optimizing Video for Sharing...</div>
|
||||
<div class="view">
|
||||
<% if (videoExtensions.includes(extension(file.path))) { %>
|
||||
<!-- Show spinner initially -->
|
||||
<div id="spinner-<%= file.path %>" class="spinner">Optimizing Video for Sharing...</div>
|
||||
|
||||
<!-- Hidden video container to be displayed later -->
|
||||
<div class="video">
|
||||
<video id="video-<%= file.path %>" class="image" autoplay loop muted playsinline loading="lazy" style="display: none;">
|
||||
<source src="/uploads/720p-<%= file.path %>" loading="lazy">
|
||||
</video>
|
||||
<div class="overlay">
|
||||
<% if(user.username == "admin" && file.username != "admin") { %>
|
||||
<small class="username"><%= file.username %></small>
|
||||
<br>
|
||||
<% } %>
|
||||
<a href="/gifv/<%=file.path %>" onclick="copyA(event)">Copy as GIFv</a>
|
||||
</div>
|
||||
</div>
|
||||
<% } else if (extension(file.path) == ".gif") { %>
|
||||
<div class="video">
|
||||
<img class="image" src="/uploads/720p-<%=file.path %>" width="100%" onclick="copyURI(event);" loading="lazy">
|
||||
<div class="overlay">
|
||||
<% if(user.username == "admin" && file.username != "admin") { %>
|
||||
<small class="username"><%= file.username %></small>
|
||||
<br>
|
||||
<% } %>
|
||||
<a href="/gifv/<%=file.path %>" onclick="copyA(event)">Copy as GIFv</a>
|
||||
</div>
|
||||
</div>
|
||||
<% } else if (imageExtensions.includes(extension(file.path))) { %>
|
||||
<div class="video">
|
||||
<img class="image" src="/uploads/<%=file.path %>" width="100%" onclick="copyURI(event)" loading="lazy">
|
||||
<!-- Hidden video container to be displayed later -->
|
||||
<div class="video">
|
||||
<video id="video-<%= file.path %>" class="image" autoplay loop muted playsinline loading="lazy" style="display: none;">
|
||||
<source src="/uploads/720p-<%= file.path %>" loading="lazy">
|
||||
</video>
|
||||
<div class="overlay">
|
||||
<% if(user.username == "admin" && file.username != "admin") { %>
|
||||
<div class="overlay">
|
||||
<small class="username"><%= file.username %></small>
|
||||
</div>
|
||||
<small class="username"><%= file.username %></small>
|
||||
<br>
|
||||
<% } %>
|
||||
<a href="/gifv/<%=file.path %>" onclick="copyA(event)">Copy as GIFv</a>
|
||||
</div>
|
||||
<% } else {%>
|
||||
<!-- non-media file -->
|
||||
<div class="nonmedia" onclick="copyPath('/uploads/<%=file.path%>')">
|
||||
<p><%=extension(file.path)%> file</p>
|
||||
</div>
|
||||
<% } else if (extension(file.path) == ".gif") { %>
|
||||
<div class="video">
|
||||
<img class="image" src="/uploads/720p-<%=file.path %>" width="100%" onclick="copyURI(event);" loading="lazy">
|
||||
<div class="overlay">
|
||||
<% if(user.username == "admin" && file.username != "admin") { %>
|
||||
<div class="overlay">
|
||||
<small class="username"><%= file.username %></small>
|
||||
</div>
|
||||
<small class="username"><%= file.username %></small>
|
||||
<br>
|
||||
<% } %>
|
||||
<a href="/gifv/<%=file.path %>" onclick="copyA(event)">Copy as GIFv</a>
|
||||
</div>
|
||||
</div>
|
||||
<% } else if (imageExtensions.includes(extension(file.path))) { %>
|
||||
<div class="video">
|
||||
<img class="image" src="/uploads/<%=file.path %>" width="100%" onclick="copyURI(event)" loading="lazy">
|
||||
<% if(user.username == "admin" && file.username != "admin") { %>
|
||||
<div class="overlay">
|
||||
<small class="username"><%= file.username %></small>
|
||||
</div>
|
||||
<% } %>
|
||||
<label><%= file.path %></label>
|
||||
<button class="destroy" form="delete-<%= file.path %>"></button>
|
||||
<button type="button" class="fullsize" onclick="openFullSize('/uploads/<%=file.path%>')"></button>
|
||||
</div>
|
||||
</form>
|
||||
<form name="delete-<%= file.path %>" id="delete-<%= file.path %>" action="<%= file.url %>/delete" method="post">
|
||||
</form>
|
||||
<% } else {%>
|
||||
<!-- non-media file -->
|
||||
<div class="nonmedia" onclick="copyPath('/uploads/<%=file.path%>')">
|
||||
<p><%=extension(file.path)%> file</p>
|
||||
<% if(user.username == "admin" && file.username != "admin") { %>
|
||||
<div class="overlay">
|
||||
<small class="username"><%= file.username %></small>
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
<% } %>
|
||||
<label><%= file.path %></label>
|
||||
<button class="destroy" hx-get="<%=file.url%>/delete" hx-trigger="click" hx-target="#embedder-list" hx-swap="innerHTML"></button>
|
||||
<button type="button" class="fullsize" onclick="openFullSize('/uploads/<%=file.path%>')"></button>
|
||||
</div>
|
||||
</li>
|
||||
<% }); %>
|
Loading…
Add table
Add a link
Reference in a new issue