From 05fef9d273d0bb1ec8972ceb9ae2fd3c7780a307 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 16 Jul 2024 17:28:32 -0500 Subject: [PATCH 1/3] add api key --- API/youtubeAPI.js | 37 ++++++++++++++++++++++++------------- CHANGELOG.md | 4 ++++ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/API/youtubeAPI.js b/API/youtubeAPI.js index 6842ee4..70f5e2d 100644 --- a/API/youtubeAPI.js +++ b/API/youtubeAPI.js @@ -2,19 +2,30 @@ var google = require('@googleapis/youtube'); var OAuth2 = google.auth.OAuth2; async function youtubeAPI(tokens, resolveName, id, args) { - var oauth2Client = new OAuth2( - GOOGLE_CLIENT_ID, - GOOGLE_CLIENT_SECRET - ); - - oauth2Client.setCredentials({ - access_token: tokens.googleaccesstoken, - }); - - var youtube = google.youtube({ - version: 'v3', - auth:oauth2Client - }); + + if (tokens.googleaccesstoken) { + const oauth2Client = new OAuth2( + GOOGLE_CLIENT_ID, + GOOGLE_CLIENT_SECRET + ); + + oauth2Client.setCredentials({ + access_token: tokens.googleaccesstoken, + }); + + youtube = google.youtube({ + version: 'v3', + auth: oauth2Client + }); + } + else if (tokens.googleapikey) { + youtube = google.youtube({ + version: 'v3', + auth: tokens.googleapikey + }); + } else { + throw new Error('No authentication method provided'); + } try { const pages = args['pages'] - 1; diff --git a/CHANGELOG.md b/CHANGELOG.md index 856e929..4844c78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] +### Added +- Google API token as an alternative way to authorize [#179](https://github.com/ncsa/standalone-smm-smile/issues/179) + ## [0.3.4] - 2024-06-27 ### Added - Randomly gather YouTube video using random search string [#169](https://github.com/ncsa/standalone-smm-smile/issues/169) From 691bb79add6bbfe78a8fb547154b3be3a78a87b5 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Wed, 17 Jul 2024 10:12:15 -0500 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4844c78..e1ebc07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- Google API token as an alternative way to authorize [#179](https://github.com/ncsa/standalone-smm-smile/issues/179) +- Google API key as an alternative way to authorize [#179](https://github.com/ncsa/standalone-smm-smile/issues/179) ## [0.3.4] - 2024-06-27 ### Added From 9fef22e04db05dbd34ad3bcf74326c9039fa3c3b Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Wed, 17 Jul 2024 11:00:30 -0500 Subject: [PATCH 3/3] release new version that allow apikeys --- CHANGELOG.md | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1ebc07..b2f1a0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [0.3.5] - 2024-07-17 ### Added - Google API key as an alternative way to authorize [#179](https://github.com/ncsa/standalone-smm-smile/issues/179) diff --git a/package-lock.json b/package-lock.json index 6789281..a3c9024 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "smile_graphql", - "version": "0.3.4", + "version": "0.3.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "smile_graphql", - "version": "0.3.4", + "version": "0.3.5", "dependencies": { "@googleapis/youtube": "^15.0.0", "append-query": "^2.0.1", diff --git a/package.json b/package.json index 6509a8c..626c086 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "smile_graphql", - "version": "0.3.4", + "version": "0.3.5", "private": true, "scripts": { "start": "forever ./bin/www",