Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
304cf65
commit 502319e
Showing
9 changed files
with
61 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
NODE_ENV=development | ||
CLOUDINARY_CLOUD_NAME= | ||
FACEBOOK_ACCESS_TOKEN= |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import VideoProvider from '../VideoProvider'; | ||
import fetch from 'node-fetch'; | ||
|
||
const { FACEBOOK_ACCESS_TOKEN } = process.env; | ||
|
||
// https://www.facebook.com/backintimetheparty/videos/1588846901182916/ | ||
|
||
export default class Facebook extends VideoProvider { | ||
static get regex() { | ||
return [ | ||
// - //www.facebook.com/backintimetheparty/videos/1588846901182916/ | ||
/https?\:\/\/www\.facebook\.com\/[\w]+\/videos\/([0-9]+)/, | ||
|
||
// - //www.facebook.com/backintimetheparty/videos/description/1588846901182916/ | ||
/https?\:\/\/www\.facebook\.com\/[\w]+\/videos[\w/-]+\/([0-9]+)/, | ||
]; | ||
} | ||
|
||
getThumbnail_asUrl() { | ||
// unfortunately the FACEBOOK_ACCESS_TOKEN is temporally and there is no way to get a quality thumbnail without a valid token. | ||
if (FACEBOOK_ACCESS_TOKEN) { | ||
return fetch(`https://graph.facebook.com/${this.getId()}?access_token=${FACEBOOK_ACCESS_TOKEN}&fields=title,description,updated_time,id,thumbnails`) | ||
.then(response => response.json()) | ||
.then(json => json.thumbnails.data.filter(t => t.is_preferred)[0].uri) | ||
} | ||
|
||
return new Promise(resolve => resolve(`https://graph.facebook.com/${this.getId()}/picture`)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Facebook from './Facebook'; | ||
|
||
describe('Facebook', () => { | ||
it('"regex" must be correct.', () => { | ||
expect(Facebook.getVideoId('https://www.facebook.com/backintimetheparty/videos/1588846901182916/')).toBe('1588846901182916'); | ||
expect(Facebook.getVideoId('https://www.facebook.com/backintimetheparty/videos/description/1588846901182916/')).toBe('1588846901182916'); | ||
}); | ||
|
||
it('all methods must work.', () => { | ||
const url = 'https://www.facebook.com/backintimetheparty/videos/1588846901182916/'; | ||
const video = new Facebook(url); | ||
|
||
// static methods | ||
expect(Facebook.check(url)).toBe(true); | ||
|
||
// instance methods | ||
expect(video.getId()).toBe('1588846901182916'); | ||
expect(video.providerName).toBe('facebook'); | ||
expect(video.url).toBe(url); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters