-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add YouTube video fetching and embedding support
- Loading branch information
1 parent
677b54e
commit 81ba6e7
Showing
12 changed files
with
265 additions
and
5 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 |
---|---|---|
|
@@ -52,3 +52,6 @@ MINIO_ENDPOINT= | |
MINIO_BUCKET_NAME= | ||
MINIO_PORT= | ||
MINIO_URL= | ||
|
||
#YOUTUBE | ||
YOUTUBE_API_KEY= |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core'; | ||
import {juggler} from '@loopback/repository'; | ||
import {config} from '../config'; | ||
|
||
const youtubeConfig = { | ||
name: 'youtube', | ||
connector: 'rest', | ||
baseUrl: 'https://www.googleapis.com/youtube/v3', | ||
crud: false, | ||
options: { | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
strictSSL: true, | ||
}, | ||
operations: [ | ||
{ | ||
template: { | ||
method: 'GET', | ||
url: '/videos', | ||
query: { | ||
part: '{part=snippet}', | ||
id: '{id}', | ||
key: '{key=' + config.YOUTUBE_API_KEY + '}', | ||
}, | ||
}, | ||
functions: { | ||
getVideos: ['part', 'id'], | ||
}, | ||
}, | ||
{ | ||
template: { | ||
method: 'GET', | ||
url: '/search', | ||
query: { | ||
part: '{part=snippet}', | ||
q: '{q}', | ||
type: '{type=video}', | ||
key: '{key=' + config.YOUTUBE_API_KEY + '}', | ||
}, | ||
}, | ||
functions: { | ||
search: ['part', 'q', 'type'], | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
@lifeCycleObserver('datasource') | ||
export class YouTubeDataSource | ||
extends juggler.DataSource | ||
implements LifeCycleObserver | ||
{ | ||
static dataSourceName = 'youtube'; | ||
static readonly defaultConfig = youtubeConfig; | ||
|
||
constructor( | ||
@inject('datasources.config.youtube', {optional: true}) | ||
dsConfig: object = youtubeConfig, | ||
) { | ||
super(dsConfig); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -3,4 +3,5 @@ export enum PlatformType { | |
TWITTER = 'twitter', | ||
REDDIT = 'reddit', | ||
FACEBOOK = 'facebook', | ||
YOUTUBE = 'youtube', | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './facebook.service'; | ||
export * from './reddit.service'; | ||
export * from './twitter.service'; | ||
export * from './youtube.service'; | ||
export * from './social-media.service'; |
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,24 @@ | ||
import {inject, Provider} from '@loopback/core'; | ||
import {getService} from '@loopback/service-proxy'; | ||
import {YouTubeDataSource} from '../../datasources'; | ||
|
||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
export interface Youtube { | ||
getVideos(part: string, id: string): Promise<any>; | ||
search(part: string, q: string, type: string): Promise<any>; | ||
// this is where you define the Node.js methods that will be | ||
// mapped to REST/SOAP/gRPC operations as stated in the datasource | ||
// json file. | ||
} | ||
|
||
export class YouTubeProvider implements Provider<Youtube> { | ||
constructor( | ||
// youtube must match the name property in the datasource json file | ||
@inject('datasources.youtube') | ||
protected dataSource: YouTubeDataSource = new YouTubeDataSource(), | ||
) {} | ||
|
||
value(): Promise<Youtube> { | ||
return getService(this.dataSource); | ||
} | ||
} |
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