Skip to content

Commit

Permalink
Merge pull request #181 from ncsa/release/0.4.2
Browse files Browse the repository at this point in the history
Release/0.4.2
  • Loading branch information
longshuicy committed Jul 17, 2024
2 parents 4792150 + ea55f1d commit 49af6e0
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ 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).

## [0.4.1] - 2026-06-27
## [0.4.2] - 2024-07-17
### Added
- Provide google api key to authorize YouTube Data API [#179](https://github.com/ncsa/standalone-smm-smile/issues/179)

## [0.4.1] - 2024-06-27
### Added
- Randomly collect youtube video [#169](https://github.com/ncsa/standalone-smm-smile/issues/169)
- Random collect youtube documentation
Expand Down
4 changes: 2 additions & 2 deletions www/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion www/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "smile_server",
"version": "0.4.1",
"version": "0.4.2",
"description": "",
"main": "app.js",
"dependencies": {
Expand Down
30 changes: 30 additions & 0 deletions www/public/bootstrap/js/customized/query_auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,33 @@ $("#twitter-pin").on('keyup', function (e) {
$(".twitter-auth").find('a').on('click', function () {
$("#twitter-callback").modal('show');
});


/****************************** Youtube ******************************/
$("#submitYoutubeApiKey").on('click', function () {
console.log('clicked');
$.ajax({
type: 'post',
url: 'login/google/apikey',
data: {
"apiKey": $("#youtubeApiKey").val(),
},
success: function (data) {
if ('ERROR' in data) {
$("#error").val(JSON.stringify(data));
$("#warning").modal('show');
}
else {
location.reload(true);
}
},
error: function (jqXHR, exception) {
$("#error").val(jqXHR.responseText);
$("#warning").modal('show');
}
});
});

$("#youtubeApiKeyLink").on('click', function () {
$("#youtube-apikey-modal").modal('show');
});
10 changes: 9 additions & 1 deletion www/routes/auth/google_auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ router.get('/login/google/callback', checkIfLoggedIn, (req, res) => {
});
});


router.post('/login/google/apikey', checkIfLoggedIn, function (req, res, next) {
if (req.body.apiKey) {
setCredential(req, 'google_api_key', req.body.apiKey);
res.status(200).send({ message: 'API Key set' });
}
else {
res.status(400).send({ ERROR: 'API Key not provided' });
}
});

module.exports = router;
5 changes: 4 additions & 1 deletion www/routes/search/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ router.post('/query-dryrun', checkIfLoggedIn, function (req, res) {
'Content-Type': 'application/json',
'redditaccesstoken': obj['rd_access_token'],
'googleaccesstoken': obj['google_access_token'],
'googleapikey': obj['google_api_key'],
'twtaccesstokenkey': obj['twt_access_token_key'],
'twtaccesstokensecret': obj['twt_access_token_secret'],
'twtbearertoken': obj['twt_v2_access_token']
Expand Down Expand Up @@ -84,6 +85,7 @@ router.post('/query', checkIfLoggedIn, function (req, res) {
'Content-Type': 'application/json',
'redditaccesstoken': obj['rd_access_token'],
'googleaccesstoken': obj['google_access_token'],
'googleapikey': obj['google_api_key'],
'twtaccesstokenkey': obj['twt_access_token_key'],
'twtaccesstokensecret': obj['twt_access_token_secret'],
'twtbearertoken': obj['twt_v2_access_token']
Expand Down Expand Up @@ -418,6 +420,7 @@ function removeInvalidToken(req, platform) {
removeCredential(req, 'rd_access_token');
} else if (platform === 'youtube') {
removeCredential(req, 'google_access_token');
removeCredential(req, 'google_api_key');
}
}

Expand Down Expand Up @@ -455,7 +458,7 @@ function checkAuthorized(req) {
if (obj && 'twt_access_token_key' in obj && 'twt_access_token_secret' in obj) response['twitter'] = true;
if (obj && 'twt_v2_access_token' in obj) response['twitterV2'] = true;
if (obj && 'rd_access_token' in obj) response['reddit'] = true;
if (obj && 'google_access_token' in obj) response['youtube'] = true;
if (obj && ('google_access_token' in obj || 'google_api_key' in obj)) response['youtube'] = true;
resolve(response);
});
}
Expand Down
2 changes: 1 addition & 1 deletion www/views/components/footer.pug
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
footer(class="footer-bs")
div(class="row")
p © #{new Date().getFullYear()} National Center for Supercomputing Applications, University of Illinois at Urbana-Champaign, All rights reserved | version 0.4.1
p © #{new Date().getFullYear()} National Center for Supercomputing Applications, University of Illinois at Urbana-Champaign, All rights reserved | version 0.4.2
45 changes: 44 additions & 1 deletion www/views/search/auth.pug
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,51 @@ div(id="auth-panel")
img(src='bootstrap/img/logo/youtube-sm-logo.png', width="30px",height="30px")
| Authorize with your Youtube account
img(src="bootstrap/img/logo/checkbox.png", class="export-success", width="30px", style="display:none;")
div(style="display: flex; justify-content: end; align-items: center; margin-top: 10px; color:#ffffff;font-size: 16px;")
span If you have a YouTube API key, please 
a(href="#", id="youtubeApiKeyLink", style="text-decoration: underline; color:#ffffff") click here
else
a(class="btn btn-primary btn-block auth-button", href="login/google" disabled)
img(src='bootstrap/img/logo/youtube-sm-logo.png', width="30px",height="30px")
| Youtube Temporarily Not Accessible
button(id="auth-next", style="", class="pull-right") next
button(id="auth-next", style="margin-top: 2em;", class="pull-right") next

// youtube api key modal
div(id="youtube-apikey-modal" class="modal fade" role="dialog" data-backdrop="static" data-keyboard="false")
div(class="modal-dialog")
div(class="modal-content")
div(class="modal-header")
button(class="close", data-dismiss="modal") ×
h2(class="modal-title", id="modal-title", style="text-align:left;vertical-align:middle;") Provide your Google API Key
div(class="modal-body form")
div(class="modal-message")
div(class="form-group")
p Please provide your API key to access the service. This is designed to help you use the
| maximum quota of the service and to ensure the service is available for you. The API key
| will be stored in 
a(href="https://redis.io/" target="_blank") Redis
| , which is an in-memory cache store, under the user's account
| for only 30 minutes to ensure the security of your credentials.
p To get an API key:
ol
li Open the 
a(href="https://console.cloud.google.com/apis/credentials" target="_blank") Credentials page
| in the API Console.
li Click 
strong Create credentials
| --> 
strong API key
li Apply restrictions as needed before using the key in production.
a(href="https://developers.google.com/youtube/registering_an_application" target="_blank") For more information...
div(class="form-group")
label(class="control-label col-md-2 col-md-2 col-xs-12") API key
div(class="col-md-10 col-md-10 col-xs-12")
input(class="form-control" id="youtubeApiKey", placeholder="Your API Key")
div(class="modal-footer")
button(class="btn btn-yes", id="submitYoutubeApiKey") Submit

script.
$("#youtube-apikey-modal").on('hidden.bs.modal', function () {
$('#apiKey').tagsinput('removeAll');
});

0 comments on commit 49af6e0

Please sign in to comment.