Remove sse helpres
All checks were successful
Bump deps (only minor versions) / ci (push) Successful in 17s

This commit is contained in:
0d0 2025-02-25 16:50:10 +01:00
parent 1b76d4de4b
commit cf3733530b
4 changed files with 30 additions and 23 deletions

View file

@ -17,12 +17,3 @@ export const isURLValid = (url: string) => {
return true; return true;
} }
export const mimeTypeMap = formatMime; export const mimeTypeMap = formatMime;
export const sseBufferMap = new Map()
export const sseHelper = (key: string, log: string) => {
if (!sseBufferMap.has(key)) {
sseBufferMap.set(key, [])
}
const buffer = sseBufferMap.get(key)
buffer.push(log)
sseBufferMap.set(key, buffer)
}

View file

@ -63,11 +63,11 @@ export function streamYouTube(link: string, format: string): ReadableStream<Uint
try { try {
controller.close() controller.close()
} catch (ex) { } catch (ex) {
process.kill() logger.error(ex)
} }
}); });
process.stdout.on('error', (err) => { process.stdout.on('error', (err) => {
console.error('Stream error:', err); logger.error('Stream error:', err);
controller.error(err); controller.error(err);
}); });
} }

View file

@ -12,6 +12,8 @@
let disabled = $state(true); let disabled = $state(true);
let metadata = $state(false); let metadata = $state(false);
let downloading = $state(false); let downloading = $state(false);
let logs = $state('');
let logId = undefined;
const formats = Object.keys(supportedFormats).map((f) => { const formats = Object.keys(supportedFormats).map((f) => {
return { value: f, label: f.toUpperCase() }; return { value: f, label: f.toUpperCase() };
@ -25,15 +27,24 @@
document.cookie = 'downloading=0' document.cookie = 'downloading=0'
}); });
const readLogs = () => {
logId = setInterval(() => {
logs += "We're downloading <br>"
}, 2000)
}
const onClick = () => { const onClick = () => {
let checkIterations = 0;
link = ''; link = '';
downloading = true; downloading = true;
document.cookie = 'downloading=1' document.cookie = 'downloading=1'
readLogs()
const id = setInterval(() => { const id = setInterval(() => {
if (document.cookie.includes('downloading=0')) { if (document.cookie.includes('downloading=0') || checkIterations > 3) {
downloading = false && clearInterval(id); downloading = false && clearInterval(id) && clearInterval(logId);
} }
checkIterations++;
}, 1000); }, 1000);
}; };
@ -81,8 +92,10 @@
id="wrapper" id="wrapper"
class="relative mx-auto rounded-lg bg-black p-6 text-[#00ff7f] shadow-lg sm:max-w-sm sm:border-4 sm:border-[#00ff7f] md:mt-10 md:max-w-md lg:max-w-lg 2xl:max-w-2xl" class="relative mx-auto rounded-lg bg-black p-6 text-[#00ff7f] shadow-lg sm:max-w-sm sm:border-4 sm:border-[#00ff7f] md:mt-10 md:max-w-md lg:max-w-lg 2xl:max-w-2xl"
> >
<div id="loader" class={[{ downloading }]}>
<div id="loader" class={["backdrop-blur-xs bg-black/20 absolute inset-0 z-10 flex items-center justify-center", { downloading }]}>
<Loader /> <Loader />
{@html logs}
</div> </div>
<!-- Info Icon --> <!-- Info Icon -->
@ -169,7 +182,7 @@
<!-- Metadata --> <!-- Metadata -->
<div> <div>
<label for="metadata" class="mb-2 block text-[#00e5ff]"> Set filename (SLOW)</label> <label for="metadata" class="mb-2 block text-[#00e5ff]">Set filename (SLOW)</label>
<input <input
type="checkbox" type="checkbox"
id="metadata" id="metadata"
@ -182,6 +195,7 @@
<a <a
id="btn-download" id="btn-download"
{href} {href}
rel="external"
onclick={onClick} onclick={onClick}
class="{disabled class="{disabled
? 'disabled' ? 'disabled'
@ -239,7 +253,9 @@
display: none; display: none;
} }
#loader.downloading { #loader.downloading {
display: block; display: grid;
justify-items: center;
align-items: center;
} }
.not-available { .not-available {
text-decoration-line: line-through; text-decoration-line: line-through;

View file

@ -27,13 +27,14 @@ const validateRequest = (url: URL) => {
throw error(400, 'format not valid'); throw error(400, 'format not valid');
} }
logger.debug(`Request is valid`);
return { return {
link, format, source, metadata link, format, source, metadata
} }
} }
export const GET: RequestHandler = async ({ url }) => { export const GET: RequestHandler = async ({ url }) => {
const { format, source, metadata, link } = validateRequest(url); const { format, source, metadata, link } = validateRequest(url);
logger.debug(`Request is valid`);
let filename = `you-clicked-no-metadata-so-i-cant-put-a-correct-name.${format}`; let filename = `you-clicked-no-metadata-so-i-cant-put-a-correct-name.${format}`;
if (!!metadata) { if (!!metadata) {
@ -45,14 +46,13 @@ export const GET: RequestHandler = async ({ url }) => {
const safeTitle = `${uploader} - ${title}`; const safeTitle = `${uploader} - ${title}`;
filename = `${safeTitle}.${format}`; filename = `${safeTitle}.${format}`;
} catch (err) { } catch (err) {
console.error(err) logger.error(err)
console.error('Error fetching metadata:'); logger.error('Error fetching metadata:');
throw error(500, 'Failed to fetch video metadata'); throw error(500, 'Failed to fetch video metadata');
} }
} }
try { try {
// Stream video/audio // Stream video/audio
return new Response(streamYouTube(link, format), { return new Response(streamYouTube(link, format), {
headers: { headers: {
@ -63,8 +63,8 @@ export const GET: RequestHandler = async ({ url }) => {
}); });
} catch (err) { } catch (err) {
console.error(err) logger.error(err)
console.error('Filed to stream file'); logger.error('Filed to stream file');
throw error(500, 'Failed to stream file'); throw error(500, 'Failed to stream file');
} }
}; };