mirror of
https://github.com/nfonteyne/octane-website.git
synced 2026-09-03 23:24:48 +02:00
first commit
This commit is contained in:
commit
244cdbedd7
44 changed files with 3386 additions and 0 deletions
3
src/lib/asyncHandler.js
Normal file
3
src/lib/asyncHandler.js
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = function asyncHandler(fn) {
|
||||
return (req, res, next) => Promise.resolve(fn(req, res, next)).catch(next);
|
||||
};
|
||||
28
src/lib/youtube.js
Normal file
28
src/lib/youtube.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
const YOUTUBE_HOSTS = new Set(['youtube.com', 'www.youtube.com', 'youtu.be', 'm.youtube.com']);
|
||||
|
||||
function extractVideoId(url) {
|
||||
let parsed;
|
||||
try {
|
||||
parsed = new URL(url);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
if (!YOUTUBE_HOSTS.has(parsed.hostname)) return null;
|
||||
|
||||
if (parsed.hostname === 'youtu.be') {
|
||||
return parsed.pathname.slice(1) || null;
|
||||
}
|
||||
if (parsed.pathname === '/watch') {
|
||||
return parsed.searchParams.get('v');
|
||||
}
|
||||
if (parsed.pathname.startsWith('/embed/')) {
|
||||
return parsed.pathname.split('/embed/')[1] || null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function isValidYoutubeUrl(url) {
|
||||
return extractVideoId(url) !== null;
|
||||
}
|
||||
|
||||
module.exports = { extractVideoId, isValidYoutubeUrl };
|
||||
Loading…
Add table
Add a link
Reference in a new issue