fix spinner, ffmpegdownscale/convert not using correct file name

This commit is contained in:
waveringana 2023-11-29 12:42:03 -05:00
parent 3ed7b0b5c7
commit 02734f1d9d
5 changed files with 157 additions and 173 deletions

View file

@ -49,7 +49,7 @@ export const checkSharexAuth: Middleware = (req, res, next) => {
export const createEmbedData: Middleware = async (req, res, next) => {
const files = req.files as Express.Multer.File[];
for (const file in files) {
const nameAndExtension = extension(files[file].originalname);
const nameAndExtension = extension(files[file].filename);
const isMedia = videoExtensions.includes(nameAndExtension[1]) || imageExtensions.includes(nameAndExtension[1]);
const oembed: oembedObj = {
@ -66,7 +66,7 @@ export const createEmbedData: Middleware = async (req, res, next) => {
if (isMedia) {
let ffProbeData;
try { ffProbeData = await ffProbe(
`uploads/${files[file].originalname}`,
`uploads/${files[file].filename}`,
nameAndExtension[0],
nameAndExtension[1],
); } catch (error) {
@ -97,19 +97,19 @@ export const convertTo720p: Middleware = (req, res, next) => {
const files = req.files as Express.Multer.File[];
console.log("convert to 720p running");
for (const file in files) {
const nameAndExtension = extension(files[file].originalname);
const nameAndExtension = extension(files[file].filename);
//Skip if not a video
if (
!videoExtensions.includes(nameAndExtension[1]) &&
nameAndExtension[1] !== ".gif"
) {
console.log(`${files[file].originalname} is not a video file`);
console.log(`${files[file].filename} is not a video file`);
console.log(nameAndExtension[1]);
continue;
}
console.log(`Creating 720p for ${files[file].originalname}`);
console.log(`Creating 720p for ${files[file].filename}`);
ffmpegDownscale(
`uploads/${nameAndExtension[0]}${nameAndExtension[1]}`,

View file

@ -22,29 +22,24 @@
}
.spinner {
/* Positioning and Sizing */
width: 100px;
width: 300px;
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 {
/* Keyframes for the spinner animation */
@keyframes spin {
0% {
transform: rotate(0deg);
}
@ -52,11 +47,11 @@
100% {
transform: rotate(360deg);
}
}
}
/* Spinner Animation */
.spinner::before {
content: '';
/* Spinner Animation */
.spinner::before {
content: "";
box-sizing: border-box;
position: absolute;
top: 50%;
@ -73,7 +68,7 @@
border-top-color: #007bff;
/* Spinner Color */
animation: spin 1s linear infinite;
}
}
#search {
padding: 6px 12px;
@ -84,14 +79,13 @@
color: rgb(247, 248, 248);
appearance: none;
transition: border 0.15s ease 0s;
:focus{
:focus {
outline: none;
box-shadow: none;
border-color: rgb(100, 153, 255);
}
}
.nav a {
display: block;
color: inherit;
@ -99,7 +93,7 @@
}
.nav a:hover {
border-bottom: 1px solid #DB7676;
border-bottom: 1px solid #db7676;
}
.nav button {
@ -107,7 +101,7 @@
}
.nav button:hover {
border-bottom: 1px solid #DB7676;
border-bottom: 1px solid #db7676;
cursor: pointer;
}
@ -125,7 +119,7 @@
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-user'%3E%3Cpath d='M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2'%3E%3C/path%3E%3Ccircle cx='12' cy='7' r='4'%3E%3C/circle%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: center left;
color: #73AD21;
color: #73ad21;
}
/* background image by Cole Bemis <https://feathericons.com> */
@ -192,13 +186,13 @@ label {
transform: translateY(0%) translateX(70%);
z-index: 1;
border-radius: 25px;
border: 2px solid #73AD21;
border: 2px solid #73ad21;
padding: 5px;
background-color: #eee;
}
.video .overlay a {
color: #73AD21;
color: #73ad21;
font-size: 12px;
font-weight: 400;
line-height: 20px;
@ -213,26 +207,26 @@ label {
height: 100%;
background: rgba(0, 0, 0, 0.8);
z-index: 9999;
}
}
.modal img {
.modal img {
max-width: 100%;
max-height: 100%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
.modal video {
.modal video {
max-width: 100%;
max-height: 100%;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
.main {
.main {
padding-top: 10px;
}
}

View file

@ -1,7 +1,7 @@
/* eslint-disable no-undef */
/* eslint-env browser: true */
let files;
let newMediaList;
function copyURI(evt) {
evt.preventDefault();
@ -221,6 +221,10 @@ searchInput.addEventListener("input", () => {
});
});
function p(num) {
return `${(num * 100).toFixed(2)}%`;
}
function checkFileAvailability(filePath) {
const checkFile = () => {
console.log(`Checking if ${filePath} is processed...`);
@ -238,14 +242,14 @@ function checkFileAvailability(filePath) {
}
})
.then((jsonData) => {
// Handle your JSON data here
console.log(jsonData);
document.getElementById(`spinner-${filePath}`).innerText = `Optimizing Video for Sharing: ${p(jsonData.progress)} done`;
})
.catch((error) => console.error("Error:", error));
};
checkFile();
const interval = setInterval(checkFile, 5000);
const interval = setInterval(checkFile, 1000);
}
function createVideoElement(filePath) {
@ -259,20 +263,9 @@ function createVideoElement(filePath) {
document.getElementById(`spinner-${filePath}`).style.display = "none";
}
async function updateMediaList() {
try {
const response = await fetch("/media-list");
if (!response.ok) {
throw new Error("Network response was not ok");
}
const data = await response.text();
document.getElementById("embedder-list").innerHTML = data;
function updateMediaList() {
htmx.ajax("GET", "/media-list", {target: "#embedder-list", swap: "innerHTML"});
htmx.process(document.body);
} catch (error) {
console.error("There was a problem with the fetch operation:", error);
}
}
function refreshMediaList(files) {

View file

@ -13,7 +13,6 @@
<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>
@ -72,16 +71,8 @@
<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>

View file

@ -7,6 +7,12 @@ const videoExtensions = ['.mp4', '.mov', '.avi', '.flv', '.mkv', '.wmv', '.webm'
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.svg', '.tiff', '.webp'];
%>
<script>
newMediaList = JSON.parse('<%- JSON.stringify(files) %>');
console.log("executed")
refreshMediaList(newMediaList);
</script>
<!-- _fileList.ejs -->
<% files.forEach(function(file) { %>
<li id="<%= file.path %>" class="show">