diff --git a/biome.json b/biome.json index c5eb038..26df6c6 100644 --- a/biome.json +++ b/biome.json @@ -13,10 +13,7 @@ "linter": { "enabled": true, "rules": { - "recommended": true, - "complexity": { - "noThisInStatic": "off" - } + "recommended": true } } } diff --git a/netlify/functions/types.ts b/netlify/functions/types.ts index 78cbb3f..73e6262 100644 --- a/netlify/functions/types.ts +++ b/netlify/functions/types.ts @@ -1,3 +1,4 @@ +import type { create } from './videoWrapper'; import type VideoProvider from './videoWrapper/VideoProvider'; export type ImageService = { diff --git a/netlify/functions/videoWrapper/Providers/Asciinema.test.ts b/netlify/functions/videoWrapper/Providers/Asciinema.test.ts index 3482177..86812e5 100644 --- a/netlify/functions/videoWrapper/Providers/Asciinema.test.ts +++ b/netlify/functions/videoWrapper/Providers/Asciinema.test.ts @@ -1,23 +1,12 @@ import { test } from 'uvu'; -import { equal } from 'uvu/assert'; import Asciinema from './Asciinema.js'; +import { createTest } from './test.helpers.js'; -test('"regex" must be correct.', () => { - equal(Asciinema.getVideoId('https://asciinema.org/a/335480'), '335480'); -}); - -test('all methods must work.', () => { - const url = 'https://asciinema.org/a/335480'; - const video = new Asciinema(url); - - // static methods - equal(Asciinema.check(url), true); - - // instance methods - equal(video.getId(), '335480'); - equal(video.providerName, 'asciinema'); - equal(video.url, url); +createTest(Asciinema, 'https://asciinema.org/a/335480', { + id: '335480', + isValid: true, + providerName: 'asciinema', }); test.run(); diff --git a/netlify/functions/videoWrapper/Providers/Asciinema.ts b/netlify/functions/videoWrapper/Providers/Asciinema.ts index 42cea2e..6636dac 100644 --- a/netlify/functions/videoWrapper/Providers/Asciinema.ts +++ b/netlify/functions/videoWrapper/Providers/Asciinema.ts @@ -7,7 +7,7 @@ export default class Asciinema extends VideoProvider { return 'asciinema'; } - static get regex() { + get regex() { return [ // - //asciinema.org/a/335480 /https?\:\/\/asciinema\.org\/a\/([0-9]+)/, diff --git a/netlify/functions/videoWrapper/Providers/CleanShotCloud.test.ts b/netlify/functions/videoWrapper/Providers/CleanShotCloud.test.ts index 25876c6..ec81b57 100644 --- a/netlify/functions/videoWrapper/Providers/CleanShotCloud.test.ts +++ b/netlify/functions/videoWrapper/Providers/CleanShotCloud.test.ts @@ -1,23 +1,12 @@ import { test } from 'uvu'; -import { equal } from 'uvu/assert'; import CleanShotCloud from './CleanShotCloud.js'; +import { createTest } from './test.helpers.js'; -test('"regex" must be correct.', () => { - equal(CleanShotCloud.getVideoId('https://cln.sh/YRePNX'), 'YRePNX'); -}); - -test('all methods must work.', () => { - const url = 'https://cln.sh/YRePNX'; - const video = new CleanShotCloud(url); - - // static methods - equal(CleanShotCloud.check(url), true); - - // instance methods - equal(video.getId(), 'YRePNX'); - equal(video.providerName, 'cleanshot-cloud'); - equal(video.url, url); +createTest(CleanShotCloud, 'https://cln.sh/YRePNX', { + isValid: true, + id: 'YRePNX', + providerName: 'cleanshot-cloud', }); test.run(); diff --git a/netlify/functions/videoWrapper/Providers/CleanShotCloud.ts b/netlify/functions/videoWrapper/Providers/CleanShotCloud.ts index 68144e3..ba79542 100644 --- a/netlify/functions/videoWrapper/Providers/CleanShotCloud.ts +++ b/netlify/functions/videoWrapper/Providers/CleanShotCloud.ts @@ -8,7 +8,7 @@ export default class CleanShotCloud extends VideoProvider { return 'cleanshot-cloud'; } - static get regex() { + get regex() { return [ // - //cln.sh/YRePNX /https?\:\/\/cln\.sh\/([a-zA-Z0-9]+)/, diff --git a/netlify/functions/videoWrapper/Providers/Dailymotion.test.ts b/netlify/functions/videoWrapper/Providers/Dailymotion.test.ts index d2c89d5..287798e 100644 --- a/netlify/functions/videoWrapper/Providers/Dailymotion.test.ts +++ b/netlify/functions/videoWrapper/Providers/Dailymotion.test.ts @@ -1,24 +1,24 @@ import { test } from 'uvu'; -import { equal } from 'uvu/assert'; import Dailymotion from './Dailymotion.js'; +import { createTest } from './test.helpers.js'; -test('"regex" must be correct.', () => { - equal(Dailymotion.getVideoId('https://www.dailymotion.com/video/x3ke49'), 'x3ke49'); - equal(Dailymotion.getVideoId('https://dai.ly/xxl8su'), 'xxl8su'); +createTest(Dailymotion, 'https://www.dailymotion.com/video/x3ke49', { + isValid: true, + id: 'x3ke49', + providerName: 'dailymotion', }); -test('all methods must work.', () => { - const url = 'https://www.dailymotion.com/video/x3ke49'; - const video = new Dailymotion(url); - - // static methods - equal(Dailymotion.check(url), true); +createTest(Dailymotion, 'https://dai.ly/xxl8su', { + isValid: true, + id: 'xxl8su', + providerName: 'dailymotion', +}); - // instance methods - equal(video.getId(), 'x3ke49'); - equal(video.providerName, 'dailymotion'); - equal(video.url, url); +createTest(Dailymotion, 'https://example.com/1234', { + isValid: false, + id: null, + providerName: 'dailymotion', }); test.run(); diff --git a/netlify/functions/videoWrapper/Providers/Dailymotion.ts b/netlify/functions/videoWrapper/Providers/Dailymotion.ts index a885d4b..05e1620 100644 --- a/netlify/functions/videoWrapper/Providers/Dailymotion.ts +++ b/netlify/functions/videoWrapper/Providers/Dailymotion.ts @@ -7,7 +7,7 @@ export default class Dailymotion extends VideoProvider { return 'dailymotion'; } - static get regex() { + get regex() { return [ // - //www.dailymotion.com/video/x3ke49 /https?\:\/\/www\.dailymotion\.com\/video\/([a-zA-Z0-9\_\-]+)/, diff --git a/netlify/functions/videoWrapper/Providers/Facebook.test.ts b/netlify/functions/videoWrapper/Providers/Facebook.test.ts index 24366b4..5df446e 100644 --- a/netlify/functions/videoWrapper/Providers/Facebook.test.ts +++ b/netlify/functions/videoWrapper/Providers/Facebook.test.ts @@ -1,30 +1,18 @@ import { test } from 'uvu'; -import { equal } from 'uvu/assert'; import Facebook from './Facebook.js'; +import { createTest } from './test.helpers.js'; -test('"regex" must be correct.', () => { - equal( - Facebook.getVideoId('https://www.facebook.com/backintimetheparty/videos/1588846901182916/'), - '1588846901182916', - ); - equal( - Facebook.getVideoId('https://www.facebook.com/backintimetheparty/videos/description/1588846901182916/'), - '1588846901182916', - ); +createTest(Facebook, 'https://www.facebook.com/backintimetheparty/videos/1588846901182916/', { + isValid: true, + id: '1588846901182916', + providerName: 'facebook', }); -test('all methods must work.', () => { - const url = 'https://www.facebook.com/backintimetheparty/videos/1588846901182916/'; - const video = new Facebook(url); - - // static methods - equal(Facebook.check(url), true); - - // instance methods - equal(video.getId(), '1588846901182916'); - equal(video.providerName, 'facebook'); - equal(video.url, url); +createTest(Facebook, 'https://www.facebook.com/backintimetheparty/videos/description/1588846901182916/', { + isValid: true, + id: '1588846901182916', + providerName: 'facebook', }); test.run(); diff --git a/netlify/functions/videoWrapper/Providers/Facebook.ts b/netlify/functions/videoWrapper/Providers/Facebook.ts index 9a61dc3..35f9fcb 100644 --- a/netlify/functions/videoWrapper/Providers/Facebook.ts +++ b/netlify/functions/videoWrapper/Providers/Facebook.ts @@ -9,7 +9,7 @@ export default class Facebook extends VideoProvider { return 'facebook'; } - static get regex() { + get regex() { return [ // - //www.facebook.com/backintimetheparty/videos/1588846901182916/ /https?\:\/\/www\.facebook\.com\/[\w]+\/videos\/([0-9]+)/, diff --git a/netlify/functions/videoWrapper/Providers/GoogleDrive.test.ts b/netlify/functions/videoWrapper/Providers/GoogleDrive.test.ts index 6f2d0d9..d6c99a7 100644 --- a/netlify/functions/videoWrapper/Providers/GoogleDrive.test.ts +++ b/netlify/functions/videoWrapper/Providers/GoogleDrive.test.ts @@ -1,34 +1,24 @@ import { test } from 'uvu'; -import { equal } from 'uvu/assert'; import GoogleDrive from './GoogleDrive.js'; +import { createTest } from './test.helpers.js'; -test('"regex" must be correct.', () => { - equal( - GoogleDrive.getVideoId('https://drive.google.com/file/d/5p_qEW432qT5_EWQjwTo-Q5FaEjjsWUvc/view'), - '5p_qEW432qT5_EWQjwTo-Q5FaEjjsWUvc', - ); - equal( - GoogleDrive.getVideoId('https://drive.google.com/open?id=5p_qEW432qT5_EWQjwTo-Q5FaEjjsWUvc'), - '5p_qEW432qT5_EWQjwTo-Q5FaEjjsWUvc', - ); - equal( - GoogleDrive.getVideoId('https://docs.google.com/presentation/d/5p_qEW432qT5_EWQjwTo-Q5FaEjjsWUvc/edit?usp=sharing'), - '5p_qEW432qT5_EWQjwTo-Q5FaEjjsWUvc', - ); +createTest(GoogleDrive, 'https://drive.google.com/file/d/5p_qEW432qT5_EWQjwTo-Q5FaEjjsWUvc/view', { + isValid: true, + id: '5p_qEW432qT5_EWQjwTo-Q5FaEjjsWUvc', + providerName: 'google-drive', }); -test('all methods must work.', () => { - const url = 'https://drive.google.com/file/d/5p_qEW432qT5_EWQjwTo-Q5FaEjjsWUvc/view'; - const video = new GoogleDrive(url); - - // static methods - equal(GoogleDrive.check(url), true); +createTest(GoogleDrive, 'https://drive.google.com/open?id=5p_qEW432qT5_EWQjwTo-Q5FaEjjsWUvc', { + isValid: true, + id: '5p_qEW432qT5_EWQjwTo-Q5FaEjjsWUvc', + providerName: 'google-drive', +}); - // instance methods - equal(video.getId(), '5p_qEW432qT5_EWQjwTo-Q5FaEjjsWUvc'); - equal(video.providerName, 'google-drive'); - equal(video.url, url); +createTest(GoogleDrive, 'https://docs.google.com/presentation/d/5p_qEW432qT5_EWQjwTo-Q5FaEjjsWUvc/edit?usp=sharing', { + isValid: true, + id: '5p_qEW432qT5_EWQjwTo-Q5FaEjjsWUvc', + providerName: 'google-drive', }); test.run(); diff --git a/netlify/functions/videoWrapper/Providers/GoogleDrive.ts b/netlify/functions/videoWrapper/Providers/GoogleDrive.ts index db51049..aa2b212 100644 --- a/netlify/functions/videoWrapper/Providers/GoogleDrive.ts +++ b/netlify/functions/videoWrapper/Providers/GoogleDrive.ts @@ -5,7 +5,7 @@ export default class GoogleDrive extends VideoProvider { return 'google-drive'; } - static get regex() { + get regex() { return [ // - //drive.google.com/open?id=1eC4FKIvGeFQX93VBy5Sil2UkbmLiGXky /https?\:\/\/drive\.google\.com\/open\?id=([a-zA-Z0-9\_\-]+)/, diff --git a/netlify/functions/videoWrapper/Providers/Imgur.test.ts b/netlify/functions/videoWrapper/Providers/Imgur.test.ts index d72c8b1..eb0738a 100644 --- a/netlify/functions/videoWrapper/Providers/Imgur.test.ts +++ b/netlify/functions/videoWrapper/Providers/Imgur.test.ts @@ -1,23 +1,12 @@ import { test } from 'uvu'; -import { equal } from 'uvu/assert'; import Imgur from './Imgur.js'; +import { createTest } from './test.helpers.js'; -test('"regex" must be correct.', () => { - equal(Imgur.getVideoId('https://imgur.com/VT1vCoz'), 'VT1vCoz'); -}); - -test('all methods must work.', () => { - const url = 'https://imgur.com/VT1vCoz'; - const video = new Imgur(url); - - // static methods - equal(Imgur.check(url), true); - - // instance methods - equal(video.getId(), 'VT1vCoz'); - equal(video.providerName, 'imgur'); - equal(video.url, url); +createTest(Imgur, 'https://imgur.com/VT1vCoz', { + isValid: true, + id: 'VT1vCoz', + providerName: 'imgur', }); test.run(); diff --git a/netlify/functions/videoWrapper/Providers/Imgur.ts b/netlify/functions/videoWrapper/Providers/Imgur.ts index b68d9b8..9c3ccce 100644 --- a/netlify/functions/videoWrapper/Providers/Imgur.ts +++ b/netlify/functions/videoWrapper/Providers/Imgur.ts @@ -7,7 +7,7 @@ export default class Imgur extends VideoProvider { return 'imgur'; } - static get regex() { + get regex() { return [ // - //imgur.com/VT1vCoz /https?\:\/\/imgur\.com\/([0-9A-Za-z]+)/, diff --git a/netlify/functions/videoWrapper/Providers/Loom.test.ts b/netlify/functions/videoWrapper/Providers/Loom.test.ts index da508ba..1c8d29f 100644 --- a/netlify/functions/videoWrapper/Providers/Loom.test.ts +++ b/netlify/functions/videoWrapper/Providers/Loom.test.ts @@ -1,26 +1,12 @@ import { test } from 'uvu'; -import { equal } from 'uvu/assert'; import Loom from './Loom.js'; +import { createTest } from './test.helpers.js'; -test('"regex" must be correct.', () => { - equal( - Loom.getVideoId('https://www.loom.com/share/3d0b326f650749bbb1fa13895dcd6563'), - '3d0b326f650749bbb1fa13895dcd6563', - ); -}); - -test('all methods must work.', () => { - const url = 'https://www.loom.com/share/3d0b326f650749bbb1fa13895dcd6563'; - const video = new Loom(url); - - // static methods - equal(Loom.check(url), true); - - // instance methods - equal(video.getId(), '3d0b326f650749bbb1fa13895dcd6563'); - equal(video.providerName, 'loom'); - equal(video.url, url); +createTest(Loom, 'https://www.loom.com/share/3d0b326f650749bbb1fa13895dcd6563', { + isValid: true, + id: '3d0b326f650749bbb1fa13895dcd6563', + providerName: 'loom', }); test.run(); diff --git a/netlify/functions/videoWrapper/Providers/Loom.ts b/netlify/functions/videoWrapper/Providers/Loom.ts index b051eca..63152e7 100644 --- a/netlify/functions/videoWrapper/Providers/Loom.ts +++ b/netlify/functions/videoWrapper/Providers/Loom.ts @@ -7,7 +7,7 @@ export default class Loom extends VideoProvider { return 'loom'; } - static get regex() { + get regex() { return [ // - //www.loom.com/share/3d0b326f650749bbb1fa13895dcd6563 /https?\:\/\/www\.loom\.com\/share\/([a-z0-9]+)/, diff --git a/netlify/functions/videoWrapper/Providers/OneDrive.test.ts b/netlify/functions/videoWrapper/Providers/OneDrive.test.ts index de3b8fb..883fc1e 100644 --- a/netlify/functions/videoWrapper/Providers/OneDrive.test.ts +++ b/netlify/functions/videoWrapper/Providers/OneDrive.test.ts @@ -1,26 +1,12 @@ import { test } from 'uvu'; -import { equal } from 'uvu/assert'; import OneDrive from './OneDrive.js'; +import { createTest } from './test.helpers.js'; -test('"regex" must be correct.', () => { - equal( - OneDrive.getVideoId('https://1drv.ms/v/s!An21T-lhvYKSkFpqKTb4YeZpKfzC?e=iXCxja'), - 'An21T-lhvYKSkFpqKTb4YeZpKfzC', - ); -}); - -test('all methods must work.', () => { - const url = 'https://1drv.ms/v/s!An21T-lhvYKSkFpqKTb4YeZpKfzC?e=iXCxja'; - const video = new OneDrive(url); - - // static methods - equal(OneDrive.check(url), true); - - // instance methods - equal(video.getId(), 'An21T-lhvYKSkFpqKTb4YeZpKfzC'); - equal(video.providerName, 'onedrive'); - equal(video.url, url); +createTest(OneDrive, 'https://1drv.ms/v/s!An21T-lhvYKSkFpqKTb4YeZpKfzC?e=iXCxja', { + isValid: true, + id: 'An21T-lhvYKSkFpqKTb4YeZpKfzC', + providerName: 'onedrive', }); test.run(); diff --git a/netlify/functions/videoWrapper/Providers/OneDrive.ts b/netlify/functions/videoWrapper/Providers/OneDrive.ts index 0635edf..bd0e5e5 100644 --- a/netlify/functions/videoWrapper/Providers/OneDrive.ts +++ b/netlify/functions/videoWrapper/Providers/OneDrive.ts @@ -7,7 +7,7 @@ export default class OneDrive extends VideoProvider { return 'onedrive'; } - static get regex() { + get regex() { return [ // - //1drv.ms/v/s!An21T-lhvYKSkFpqKTb4YeZpKfzC?e=iXCxja /https?\:\/\/1drv\.ms\/[\w]{1}\/s!([a-zA-Z0-9-]+)/, diff --git a/netlify/functions/videoWrapper/Providers/PeerTube.test.ts b/netlify/functions/videoWrapper/Providers/PeerTube.test.ts index a35bfc2..2d02443 100644 --- a/netlify/functions/videoWrapper/Providers/PeerTube.test.ts +++ b/netlify/functions/videoWrapper/Providers/PeerTube.test.ts @@ -1,23 +1,12 @@ import { test } from 'uvu'; -import { equal } from 'uvu/assert'; import PeerTube from './PeerTube.js'; +import { createTest } from './test.helpers.js'; -test('"regex" must be correct.', () => { - equal(PeerTube.getVideoId('https://framatube.org/w/kkGMgK9ZtnKfYAgnEtQxbv?start=1s'), 'kkGMgK9ZtnKfYAgnEtQxbv'); -}); - -test('all methods must work.', () => { - const url = 'https://framatube.org/w/kkGMgK9ZtnKfYAgnEtQxbv?start=1s'; - const video = new PeerTube(url); - - // static methods - equal(PeerTube.check(url), true); - - // instance methods - equal(video.getId(), 'kkGMgK9ZtnKfYAgnEtQxbv'); - equal(video.providerName, 'peertube'); - equal(video.url, url); +createTest(PeerTube, 'https://framatube.org/w/kkGMgK9ZtnKfYAgnEtQxbv?start=1s', { + isValid: true, + id: 'kkGMgK9ZtnKfYAgnEtQxbv', + providerName: 'peertube', }); test.run(); diff --git a/netlify/functions/videoWrapper/Providers/PeerTube.ts b/netlify/functions/videoWrapper/Providers/PeerTube.ts index a1796cd..b2ae8ec 100644 --- a/netlify/functions/videoWrapper/Providers/PeerTube.ts +++ b/netlify/functions/videoWrapper/Providers/PeerTube.ts @@ -8,7 +8,7 @@ export default class PeerTube extends VideoProvider { return 'peertube'; } - static get regex() { + get regex() { return [ // //framatube.org/w/kkGMgK9ZtnKfYAgnEtQxbv?start=1s /\/w\/([a-zA-Z0-9]+)/, // not so strong :( diff --git a/netlify/functions/videoWrapper/Providers/Streamable.test.ts b/netlify/functions/videoWrapper/Providers/Streamable.test.ts index bc95f16..88dcbf3 100644 --- a/netlify/functions/videoWrapper/Providers/Streamable.test.ts +++ b/netlify/functions/videoWrapper/Providers/Streamable.test.ts @@ -1,23 +1,12 @@ import { test } from 'uvu'; -import { equal } from 'uvu/assert'; import Streamable from './Streamable.js'; +import { createTest } from './test.helpers.js'; -test('"regex" must be correct.', () => { - equal(Streamable.getVideoId('https://streamable.com/1nvj5i'), '1nvj5i'); -}); - -test('all methods must work.', () => { - const url = 'https://streamable.com/1nvj5i'; - const video = new Streamable(url); - - // static methods - equal(Streamable.check(url), true); - - // instance methods - equal(video.getId(), '1nvj5i'); - equal(video.providerName, 'streamable'); - equal(video.url, url); +createTest(Streamable, 'https://streamable.com/1nvj5i', { + isValid: true, + id: '1nvj5i', + providerName: 'streamable', }); test.run(); diff --git a/netlify/functions/videoWrapper/Providers/Streamable.ts b/netlify/functions/videoWrapper/Providers/Streamable.ts index 61f843c..c9c443c 100644 --- a/netlify/functions/videoWrapper/Providers/Streamable.ts +++ b/netlify/functions/videoWrapper/Providers/Streamable.ts @@ -7,7 +7,7 @@ export default class Streamable extends VideoProvider { return 'streamable'; } - static get regex() { + get regex() { return [ // - //streamable.com/1nvj5i /https?\:\/\/streamable\.com\/([a-z0-9]+)/, diff --git a/netlify/functions/videoWrapper/Providers/TikTok.test.ts b/netlify/functions/videoWrapper/Providers/TikTok.test.ts index 877d350..1fb7a2f 100644 --- a/netlify/functions/videoWrapper/Providers/TikTok.test.ts +++ b/netlify/functions/videoWrapper/Providers/TikTok.test.ts @@ -1,31 +1,24 @@ import { test } from 'uvu'; -import { equal } from 'uvu/assert'; import TikTok from './TikTok.js'; +import { createTest } from './test.helpers.js'; -test('"regex" must be correct.', () => { - equal( - TikTok.getVideoId('https://www.tiktok.com/@tiktok/video/6584647400055377158?is_copy_url=1&is_from_webapp=v1'), - '6584647400055377158', - ); - equal( - TikTok.getVideoId('https://www.tiktok.com/@tiktok_it.1/video/6584731204698770693?is_copy_url=1&is_from_webapp=v1'), - '6584731204698770693', - ); - equal(TikTok.getVideoId('https://www.tiktok.com/@tiktok/video/6584647400055377158'), '6584647400055377158'); +createTest(TikTok, 'https://www.tiktok.com/@tiktok/video/6584647400055377158?is_copy_url=1&is_from_webapp=v1', { + isValid: true, + id: '6584647400055377158', + providerName: 'tiktok', }); -test('all methods must work.', () => { - const url = 'https://www.tiktok.com/@tiktok/video/6584647400055377158?is_copy_url=1&is_from_webapp=v1'; - const video = new TikTok(url); - - // static methods - equal(TikTok.check(url), true); +createTest(TikTok, 'https://www.tiktok.com/@tiktok_it.1/video/6584731204698770693?is_copy_url=1&is_from_webapp=v1', { + isValid: true, + id: '6584731204698770693', + providerName: 'tiktok', +}); - // instance methods - equal(video.getId(), '6584647400055377158'); - equal(video.providerName, 'tiktok'); - equal(video.url, url); +createTest(TikTok, 'https://www.tiktok.com/@tiktok/video/6584647400055377158', { + isValid: true, + id: '6584647400055377158', + providerName: 'tiktok', }); test.run(); diff --git a/netlify/functions/videoWrapper/Providers/TikTok.ts b/netlify/functions/videoWrapper/Providers/TikTok.ts index 3e1035c..815c1f5 100644 --- a/netlify/functions/videoWrapper/Providers/TikTok.ts +++ b/netlify/functions/videoWrapper/Providers/TikTok.ts @@ -7,7 +7,7 @@ export default class TikTok extends VideoProvider { return 'tiktok'; } - static get regex() { + get regex() { return [ // - //www.tiktok.com/@tiktok/video/6584647400055377158?is_copy_url=1&is_from_webapp=v1 /https?\:\/\/www\.tiktok\.com\/@[\w\W]+\/video\/([a-z0-9]+)/, diff --git a/netlify/functions/videoWrapper/Providers/Video.test.ts b/netlify/functions/videoWrapper/Providers/Video.test.ts index 1561e15..cfc87b2 100644 --- a/netlify/functions/videoWrapper/Providers/Video.test.ts +++ b/netlify/functions/videoWrapper/Providers/Video.test.ts @@ -1,24 +1,18 @@ import { test } from 'uvu'; -import { equal } from 'uvu/assert'; import Video from './Video.js'; +import { createTest } from './test.helpers.js'; -test('"regex" must be correct.', () => { - equal(Video.getVideoId('https://i.imgur.com/vhjwXMB.mp4'), 'f48ef897bfabed6334368c76e716f871'); - equal(Video.check('https://asciinema.org/a/335480'), false); +createTest(Video, 'https://i.imgur.com/vhjwXMB.mp4', { + isValid: true, + id: 'f48ef897bfabed6334368c76e716f871', + providerName: 'video', }); -test('all methods must work.', () => { - const url = 'https://i.imgur.com/vhjwXMB.mp4'; - const video = new Video(url); - - // static methods - equal(Video.check(url), true); - - // instance methods - equal(video.getId(), 'f48ef897bfabed6334368c76e716f871'); - equal(video.providerName, 'video'); - equal(video.url, url); +createTest(Video, 'https://asciinema.org/a/335480', { + isValid: false, + id: null, + providerName: 'video', }); test.run(); diff --git a/netlify/functions/videoWrapper/Providers/Video.ts b/netlify/functions/videoWrapper/Providers/Video.ts index 27deb13..b9b10c9 100644 --- a/netlify/functions/videoWrapper/Providers/Video.ts +++ b/netlify/functions/videoWrapper/Providers/Video.ts @@ -8,12 +8,12 @@ export default class Video extends VideoProvider { return 'video'; } - static get regex() { + get regex() { return videoRegEx; } - static getVideoId(url = '') { - return super.getVideoId(url) ? crypto.createHash('md5').update(url).digest('hex') : undefined; + getVideoId() { + return super.getVideoId() ? crypto.createHash('md5').update(this.url).digest('hex') : null; } getThumbnail_asVideoUrl() { diff --git a/netlify/functions/videoWrapper/Providers/Vimeo.test.ts b/netlify/functions/videoWrapper/Providers/Vimeo.test.ts index 172ef05..3a238d3 100644 --- a/netlify/functions/videoWrapper/Providers/Vimeo.test.ts +++ b/netlify/functions/videoWrapper/Providers/Vimeo.test.ts @@ -1,24 +1,18 @@ import { test } from 'uvu'; -import { equal } from 'uvu/assert'; import Vimeo from './Vimeo.js'; +import { createTest } from './test.helpers.js'; -test('"regex" must be correct.', () => { - equal(Vimeo.getVideoId('https://vimeo.com/263856289'), '263856289'); - equal(Vimeo.getVideoId('https://vimeo.com/channels/staffpicks/287019927'), '287019927'); +createTest(Vimeo, 'https://vimeo.com/263856289', { + isValid: true, + id: '263856289', + providerName: 'vimeo', }); -test('all methods must work.', () => { - const url = 'https://vimeo.com/channels/staffpicks/287019927'; - const video = new Vimeo(url); - - // static methods - equal(Vimeo.check(url), true); - - // instance methods - equal(video.getId(), '287019927'); - equal(video.providerName, 'vimeo'); - equal(video.url, url); +createTest(Vimeo, 'https://vimeo.com/channels/staffpicks/287019927', { + isValid: true, + id: '287019927', + providerName: 'vimeo', }); test.run(); diff --git a/netlify/functions/videoWrapper/Providers/Vimeo.ts b/netlify/functions/videoWrapper/Providers/Vimeo.ts index 19a3fd9..367347f 100644 --- a/netlify/functions/videoWrapper/Providers/Vimeo.ts +++ b/netlify/functions/videoWrapper/Providers/Vimeo.ts @@ -7,7 +7,7 @@ export default class Vimeo extends VideoProvider { return 'vimeo'; } - static get regex() { + get regex() { return [ // - //vimeo.com/263856289 /https?\:\/\/vimeo\.com\/([0-9]+)/, diff --git a/netlify/functions/videoWrapper/Providers/Wistia.test.ts b/netlify/functions/videoWrapper/Providers/Wistia.test.ts index abfe1c0..a68b49a 100644 --- a/netlify/functions/videoWrapper/Providers/Wistia.test.ts +++ b/netlify/functions/videoWrapper/Providers/Wistia.test.ts @@ -1,34 +1,54 @@ import { test } from 'uvu'; -import { equal } from 'uvu/assert'; import Wistia from './Wistia.js'; +import { createTest } from './test.helpers.js'; -test('"regex" must be correct.', () => { - equal(Wistia.getVideoId('https://home.wistia.com/medias/e4a27b971d'), 'e4a27b971d'); - equal(Wistia.getVideoId('https://wistia.com/medias/e4a27b971d'), 'e4a27b971d'); - equal(Wistia.getVideoId('https://home.wistia.com/embed/iframe/e4a27b971d'), 'e4a27b971d'); - equal(Wistia.getVideoId('https://john.wistia.com/embed/iframe/e4a27b971d'), 'e4a27b971d'); - equal(Wistia.getVideoId('https://john.wistia.com/embed/playlists/e4a27b971d'), 'e4a27b971d'); - equal(Wistia.getVideoId('https://john.wi.st/embed/playlists/e4a27b971d'), 'e4a27b971d'); - equal(Wistia.getVideoId('https://home.wi.st/medias/e4a27b971d'), 'e4a27b971d'); - equal(Wistia.getVideoId('https://home.wi.st/medias/e4a27b971d'), 'e4a27b971d'); - equal( - Wistia.getVideoId('https://wistia.com/series/one-ten-one-hundred?wchannelid=z2vptfjlxk&wvideoid=donagpxtdr'), - 'donagpxtdr', - ); -}); - -test('all methods must work.', () => { - const url = 'https://home.wistia.com/medias/e4a27b971d'; - const video = new Wistia(url); - - // static methods - equal(Wistia.check(url), true); - - // instance methods - equal(video.getId(), 'e4a27b971d'); - equal(video.providerName, 'wistia'); - equal(video.url, url); +createTest(Wistia, 'https://home.wistia.com/medias/e4a27b971d', { + isValid: true, + id: 'e4a27b971d', + providerName: 'wistia', +}); + +createTest(Wistia, 'https://wistia.com/medias/e4a27b971d', { + isValid: true, + id: 'e4a27b971d', + providerName: 'wistia', +}); + +createTest(Wistia, 'https://home.wistia.com/embed/iframe/e4a27b971d', { + isValid: true, + id: 'e4a27b971d', + providerName: 'wistia', +}); + +createTest(Wistia, 'https://john.wistia.com/embed/iframe/e4a27b971d', { + isValid: true, + id: 'e4a27b971d', + providerName: 'wistia', +}); + +createTest(Wistia, 'https://john.wistia.com/embed/playlists/e4a27b971d', { + isValid: true, + id: 'e4a27b971d', + providerName: 'wistia', +}); + +createTest(Wistia, 'https://john.wi.st/embed/playlists/e4a27b971d', { + isValid: true, + id: 'e4a27b971d', + providerName: 'wistia', +}); + +createTest(Wistia, 'https://home.wi.st/medias/e4a27b971d', { + isValid: true, + id: 'e4a27b971d', + providerName: 'wistia', +}); + +createTest(Wistia, 'https://wistia.com/series/one-ten-one-hundred?wchannelid=z2vptfjlxk&wvideoid=donagpxtdr', { + isValid: true, + id: 'donagpxtdr', + providerName: 'wistia', }); test.run(); diff --git a/netlify/functions/videoWrapper/Providers/Wistia.ts b/netlify/functions/videoWrapper/Providers/Wistia.ts index fcd8fb4..1b5b946 100644 --- a/netlify/functions/videoWrapper/Providers/Wistia.ts +++ b/netlify/functions/videoWrapper/Providers/Wistia.ts @@ -7,7 +7,7 @@ export default class Wistia extends VideoProvider { return 'wistia'; } - static get regex() { + get regex() { return [ // - //home.wistia.com/medias/e4a27b971d /https?:\/\/(?:[^.]+\.)?(?:wistia\.com|wi\.st)\/medias\/([a-zA-Z0-9\_\-]+)/, diff --git a/netlify/functions/videoWrapper/Providers/Youtube.test.ts b/netlify/functions/videoWrapper/Providers/Youtube.test.ts index 7224d22..b5470b3 100644 --- a/netlify/functions/videoWrapper/Providers/Youtube.test.ts +++ b/netlify/functions/videoWrapper/Providers/Youtube.test.ts @@ -1,30 +1,54 @@ import { test } from 'uvu'; -import { equal } from 'uvu/assert'; import Youtube from './Youtube.js'; +import { createTest } from './test.helpers.js'; -test('"regex" must be correct.', () => { - equal(Youtube.getVideoId('https://www.youtube.com/watch?v=oRdzL2DX0yU'), 'oRdzL2DX0yU'); - equal(Youtube.getVideoId('https://m.youtube.com/watch?v=oRdzL2DX0yU'), 'oRdzL2DX0yU'); - equal(Youtube.getVideoId('https://youtu.be/oRdzL2DX0yU'), 'oRdzL2DX0yU'); - equal(Youtube.getVideoId('https://www.youtube.com/embed/oRdzL2DX0yU'), 'oRdzL2DX0yU'); - equal(Youtube.getVideoId('https://youtube.com/embed/oRdzL2DX0yU'), 'oRdzL2DX0yU'); - equal(Youtube.getVideoId('https://gaming.youtube.com/watch?v=CLdvw87teRc'), 'CLdvw87teRc'); - equal(Youtube.getVideoId('https://gaming.youtube.com/watch?v=CLdvw87teRc&feature=share'), 'CLdvw87teRc'); - equal(Youtube.getVideoId('https://music.youtube.com/watch?v=i3MKTm-49uI&feature=share'), 'i3MKTm-49uI'); +createTest(Youtube, 'https://www.youtube.com/watch?v=oRdzL2DX0yU', { + isValid: true, + id: 'oRdzL2DX0yU', + providerName: 'youtube', }); -test('all methods must work.', () => { - const url = 'https://www.youtube.com/watch?v=oRdzL2DX0yU'; - const video = new Youtube(url); +createTest(Youtube, 'https://m.youtube.com/watch?v=oRdzL2DX0yU', { + isValid: true, + id: 'oRdzL2DX0yU', + providerName: 'youtube', +}); + +createTest(Youtube, 'https://youtu.be/oRdzL2DX0yU', { + isValid: true, + id: 'oRdzL2DX0yU', + providerName: 'youtube', +}); + +createTest(Youtube, 'https://www.youtube.com/embed/oRdzL2DX0yU', { + isValid: true, + id: 'oRdzL2DX0yU', + providerName: 'youtube', +}); - // static methods - equal(Youtube.check(url), true); +createTest(Youtube, 'https://youtube.com/embed/oRdzL2DX0yU', { + isValid: true, + id: 'oRdzL2DX0yU', + providerName: 'youtube', +}); + +createTest(Youtube, 'https://gaming.youtube.com/watch?v=CLdvw87teRc', { + isValid: true, + id: 'CLdvw87teRc', + providerName: 'youtube', +}); + +createTest(Youtube, 'https://gaming.youtube.com/watch?v=CLdvw87teRc&feature=share', { + isValid: true, + id: 'CLdvw87teRc', + providerName: 'youtube', +}); - // instance methods - equal(video.getId(), 'oRdzL2DX0yU'); - equal(video.providerName, 'youtube'); - equal(video.url, url); +createTest(Youtube, 'https://music.youtube.com/watch?v=i3MKTm-49uI&feature=share', { + isValid: true, + id: 'i3MKTm-49uI', + providerName: 'youtube', }); test.run(); diff --git a/netlify/functions/videoWrapper/Providers/Youtube.ts b/netlify/functions/videoWrapper/Providers/Youtube.ts index 77ab8c5..7c73966 100644 --- a/netlify/functions/videoWrapper/Providers/Youtube.ts +++ b/netlify/functions/videoWrapper/Providers/Youtube.ts @@ -7,7 +7,7 @@ export default class Youtube extends VideoProvider { return 'youtube'; } - static get regex() { + get regex() { return [ // - //www.youtube.com/watch?v=oRdzL2DX0yU /https?\:\/\/www\.youtube\.com\/watch\?v\=([a-zA-Z0-9\_\-]+)/, diff --git a/netlify/functions/videoWrapper/Providers/test.helpers.ts b/netlify/functions/videoWrapper/Providers/test.helpers.ts new file mode 100644 index 0000000..e9cbb44 --- /dev/null +++ b/netlify/functions/videoWrapper/Providers/test.helpers.ts @@ -0,0 +1,21 @@ +import { test } from 'uvu'; +import { equal } from 'uvu/assert'; +import type VideoProvider from '../VideoProvider'; + +export function createTest( + Video: typeof VideoProvider, + url: string, + expectations: { isValid: boolean; id: string | null; providerName: string }, +) { + test(`expectations for the url: ${url}`, () => { + const video = new Video(url); + + // static methods + equal(video.check(), expectations.isValid, 'Expected "check()" to be deeply equal:'); + + // instance methods + equal(video.getId(), expectations.id, 'Expected "id" to be deeply equal:'); + equal(video.providerName, expectations.providerName, 'Expected "providerName" to be deeply equal:'); + equal(video.url, url, 'Expected "url" to be deeply equal:'); + }); +} diff --git a/netlify/functions/videoWrapper/VideoProvider.ts b/netlify/functions/videoWrapper/VideoProvider.ts index 30cad38..b116e86 100644 --- a/netlify/functions/videoWrapper/VideoProvider.ts +++ b/netlify/functions/videoWrapper/VideoProvider.ts @@ -4,7 +4,7 @@ export default class VideoProvider { url: string; options: Options; - static get regex(): RegExp[] { + get regex(): RegExp[] { return []; } @@ -12,23 +12,24 @@ export default class VideoProvider { return undefined; } - static check(url) { - return !!this.getVideoId(url); + check() { + return !!this.getVideoId(); } - static getVideoId(url = ''): string | undefined { + getVideoId(): string | null { const id = this.regex .map((rx) => { - const [, id] = url.match(rx) || []; + const [, id] = this.url.match(rx) || []; return id; }) .filter((id) => id)[0]; if (typeof id === 'string') { + // @ts-expect-error TODO: need to fix this return id.replaceAll('/', '--'); } - return id; + return id ?? null; } needsCloudinary() { @@ -40,7 +41,7 @@ export default class VideoProvider { } getId() { - return this.constructor.getVideoId(this.url); + return this.getVideoId(); } getThumbnail_asVideoUrl(): Promise { @@ -66,9 +67,9 @@ export default class VideoProvider { } constructor(url: string, options: Options = {}) { - if (!this.constructor.check(url)) { - throw new Error(`Invalid url for ${this.providerName} provider.`); - } + // if (!this.check()) { + // throw new Error(`Invalid url for ${this.providerName} provider.`); + // } this.url = url; this.options = options; diff --git a/netlify/functions/videoWrapper/index.ts b/netlify/functions/videoWrapper/index.ts index 9efb4a7..1f14b57 100644 --- a/netlify/functions/videoWrapper/index.ts +++ b/netlify/functions/videoWrapper/index.ts @@ -23,7 +23,7 @@ function getVideoProviders() { export async function create(url: string, options?: Options) { const videoProviders = await getVideoProviders(); const videoProvider = videoProviders.filter((vp) => { - return vp.default.check(url); + return new vp.default(url).check(); }); if (videoProvider.length === 0) {