From 95d9f5a01a58671be008ac2b2592ad1c8121706b Mon Sep 17 00:00:00 2001 From: Jorgen Evens Date: Fri, 27 Dec 2019 23:10:28 +0100 Subject: [PATCH] [google] add support for Google Avatar --- README.md | 1 + app.hosted.yaml | Bin 281 -> 339 bytes src/lib/env.js | 4 +++- src/networks/google/strategies.js | 20 +++++++++++++------- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4966229..1e1995b 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ The app is configured using environment variables which you either add to your ` | 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"` | +| 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 diff --git a/app.hosted.yaml b/app.hosted.yaml index 3eafbaa9ca1290cc10fd77922497c2b459ee0f29..0351d744539dc488a4d50c969b67d16796d87517 100644 GIT binary patch literal 339 zcmV-Z0j&N2M@dveQdv+`0Oql#iVbp~M{}2!dlgoyw6PfXcNIPxnW;TT#53^-0RKvu z8+zP3@-FZwu5xU)O$OIX@**_~F*Xhyq>B)oi1ycWYd)10Qeqx)oU0?&`Wz2<#%N(8 za}Fj@TQTX1YmGzu64xyR@s{lWvM)jvT zoL}NY8Sa@qrHCL{absgTl{XPnm+4C_pmD}UlbkH4jNy^>8sP1LMq@m|0ElW~3*5M} z-@S0u5)A#tTErxP0buFdtd8ubMzLNo?d)i9XhiPInR*Wl&XD;TAhJ(x1&wF8?wkxK zcQXsx!MyjBx`(M&qmj8v(I!0E!wVp%v-i|utWO9&nR&HD(oQjD>IM3#swO}LoGnRW l2U`6)oOO8R5kK&jpbuvhQUd~Hem`&o!SiI`+rg1b`w8K(o!0;W literal 281 zcmV+!0p|VyM@dveQdv+`05^H!?Dq zgbT}EzPxa^FncfN^0#qS8v}7dMDj95jx}{$oKJ<~H*92jcCW8J>w*I67wgDm@Avc5 zrkzcBlmK!mx*~0kW!{X>oP*f#UzG=Uc`+IRF~|?uJ}hxg7vCSiY-rZylX?SC%84t~ z|8&K`ymZF7o4+c2J%tO@<%6YTu%Xwqw=?@^7!1d`u54^qCc_x^7`(C0-yH|cI;s&A ffub-W)(hlxE+6mK1#yiCGlV`!FB1#n;VcDdkUEJT diff --git a/src/lib/env.js b/src/lib/env.js index 158aae5..2cdba68 100644 --- a/src/lib/env.js +++ b/src/lib/env.js @@ -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) }; diff --git a/src/networks/google/strategies.js b/src/networks/google/strategies.js index 35dd25e..d878e63 100644 --- a/src/networks/google/strategies.js +++ b/src/networks/google/strategies.js @@ -1,19 +1,25 @@ const fetch = require('lib/fetch'); const _get = require('lodash/get'); +const { GOOGLE_API_KEY } = require('lib/env'); -async function picasaweb(username) { - username = encodeURIComponent(username); - - const res = await fetch(`https://picasaweb.google.com/data/entry/api/user/${username}?alt=json`); +const key = encodeURIComponent(GOOGLE_API_KEY || ''); - if (!res.ok) +async function peopleApi(username, { req }) { + if (!GOOGLE_API_KEY) return null; + const { size = 100 } = req.query || {}; + + username = encodeURIComponent(username); + + const res = await fetch(`https://people.googleapis.com/v1/people/${username}?personFields=photos&key=${key}`); const body = await res.json(); - return _get(body, 'entry.gphoto$thumbnail.$t'); + const url = _get(body, 'photos.0.url'); + + return url.replace(/=s\d+/, `=s${size}`); } module.exports = [ - picasaweb + peopleApi ];