Skip to content

Commit

Permalink
Merge pull request #12 from JorgenEvens/feature/google-support
Browse files Browse the repository at this point in the history
[google] add support for Google Avatar
  • Loading branch information
JorgenEvens authored Dec 27, 2019
2 parents 9306f37 + 9920503 commit 402e015
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ The app is configured using environment variables which you either add to your `
| **Network Configuration** | | |
| NETWORKS | The social networks available to this deployment, if no value is set all are enabled. | `undefined` |
| VKONTAKTE\_KEY | A [Vkontakte service key](https://vk.com/dev/access_token?f=3.%20Service%20Token) to perform API requests with. | `undefined` |
| VKONTAKTE\_API_VERSION | The API version to use for Vkontakte | `"5.101"` |
| VKONTAKTE\_API\_VERSION | The API version to use for Vkontakte | `"5.101"` |
| GOOGLE\_API\_KEY | The [API Key](https://console.cloud.google.com/apis/credentials) to a Google Cloud Platform project that has access to the People API. | `undefined` |

## Contributing

Expand Down
Binary file modified app.hosted.yaml
Binary file not shown.
4 changes: 3 additions & 1 deletion src/lib/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ module.exports = {
LIMIT_REFERER: load_env('LIMIT_REFERER', null),

VKONTAKTE_KEY: load_env('VKONTAKTE_KEY', null),
VKONTAKTE_API_VERSION: load_env('VKONTAKTE_API_VERSION', '5.101')
VKONTAKTE_API_VERSION: load_env('VKONTAKTE_API_VERSION', '5.101'),

GOOGLE_API_KEY: load_env('GOOGLE_API_KEY', null)
};
20 changes: 16 additions & 4 deletions src/networks/google/strategies.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
const fetch = require('lib/fetch');
const _get = require('lodash/get');
const { GOOGLE_API_KEY } = require('lib/env');

const key = encodeURIComponent(GOOGLE_API_KEY || '');

async function peopleApi(username, { req }) {
if (!GOOGLE_API_KEY)
return null;

const { size = 100 } = req.query || {};

async function picasaweb(username) {
username = encodeURIComponent(username);

const res = await fetch(`https://picasaweb.google.com/data/entry/api/user/${username}?alt=json`);
const res = await fetch(`https://people.googleapis.com/v1/people/${username}?personFields=photos&key=${key}`);

if (!res.ok)
return null;

const body = await res.json();
const url = _get(body, 'photos.0.url');

if (!url)
return null;

return _get(body, 'entry.gphoto$thumbnail.$t');
return url.replace(/=s\d+/, `=s${size}`);
}

module.exports = [
picasaweb
peopleApi
];

0 comments on commit 402e015

Please sign in to comment.