Skip to content

Commit

Permalink
chore: remove static methods
Browse files Browse the repository at this point in the history
  • Loading branch information
marcomontalbano committed Jun 16, 2024
1 parent bd922b2 commit 29ed2e4
Show file tree
Hide file tree
Showing 35 changed files with 246 additions and 306 deletions.
5 changes: 1 addition & 4 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"complexity": {
"noThisInStatic": "off"
}
"recommended": true
}
}
}
1 change: 1 addition & 0 deletions netlify/functions/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { create } from './videoWrapper';
import type VideoProvider from './videoWrapper/VideoProvider';

export type ImageService = {
Expand Down
21 changes: 5 additions & 16 deletions netlify/functions/videoWrapper/Providers/Asciinema.test.ts
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 1 addition & 1 deletion netlify/functions/videoWrapper/Providers/Asciinema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)/,
Expand Down
21 changes: 5 additions & 16 deletions netlify/functions/videoWrapper/Providers/CleanShotCloud.test.ts
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 1 addition & 1 deletion netlify/functions/videoWrapper/Providers/CleanShotCloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)/,
Expand Down
28 changes: 14 additions & 14 deletions netlify/functions/videoWrapper/Providers/Dailymotion.test.ts
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 1 addition & 1 deletion netlify/functions/videoWrapper/Providers/Dailymotion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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\_\-]+)/,
Expand Down
30 changes: 9 additions & 21 deletions netlify/functions/videoWrapper/Providers/Facebook.test.ts
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 1 addition & 1 deletion netlify/functions/videoWrapper/Providers/Facebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)/,
Expand Down
38 changes: 14 additions & 24 deletions netlify/functions/videoWrapper/Providers/GoogleDrive.test.ts
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 1 addition & 1 deletion netlify/functions/videoWrapper/Providers/GoogleDrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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\_\-]+)/,
Expand Down
21 changes: 5 additions & 16 deletions netlify/functions/videoWrapper/Providers/Imgur.test.ts
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 1 addition & 1 deletion netlify/functions/videoWrapper/Providers/Imgur.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)/,
Expand Down
24 changes: 5 additions & 19 deletions netlify/functions/videoWrapper/Providers/Loom.test.ts
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 1 addition & 1 deletion netlify/functions/videoWrapper/Providers/Loom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]+)/,
Expand Down
24 changes: 5 additions & 19 deletions netlify/functions/videoWrapper/Providers/OneDrive.test.ts
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 1 addition & 1 deletion netlify/functions/videoWrapper/Providers/OneDrive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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-]+)/,
Expand Down
21 changes: 5 additions & 16 deletions netlify/functions/videoWrapper/Providers/PeerTube.test.ts
Original file line number Diff line number Diff line change
@@ -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();
Loading

0 comments on commit 29ed2e4

Please sign in to comment.