Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Tracker DB v4 endpoints #616

Merged
merged 10 commits into from Jan 5, 2021

GH-2172 migrate tracker descriptions to whotracks.me

  • Loading branch information
christophertino committed Dec 14, 2020
commit a950fe90427644f3161aa91597dc80023a8be11f
@@ -33,6 +33,7 @@ class GlobalTracker extends React.Component {
description: '',
showMoreInfo: false,
showTrackerLearnMore: false,
wtmID: null,
};

// click bindings
@@ -43,10 +44,10 @@ class GlobalTracker extends React.Component {
/**
* Implement handler for clicking on the tracker title
* which shows/hides tracker description. On show it retrieves
* description from https://apps.ghostery.com and sets it in state.
* description from whotracks.me and sets it in state.
*/
toggleDescription() {
const { tracker, language } = this.props;
const { tracker } = this.props;
const { description } = this.state;
this.setState(prevState => ({ showMoreInfo: !prevState.showMoreInfo }));

@@ -56,14 +57,14 @@ class GlobalTracker extends React.Component {

this.setState({ description: t('tracker_description_getting') });

sendMessageInPromise('getTrackerDescription', {
url: `${globals.APPS_BASE_URL}/${language}/apps/${
encodeURIComponent(tracker.name.replace(/\s+/g, '_').toLowerCase())}?format=json`,
sendMessageInPromise('getTrackerInfo', {
url: `${globals.WTM_BASE_URL}/data/trackers/ghostery/${tracker.id}.json`,
}).then((data) => {
if (data) {
const truncate = (data.length > 200) ? `${data.substr(0, 199)}...` : data;
if (data && data.description) {
const truncate = (data.description.length > 200) ? `${data.description.substr(0, 199)}...` : data.description;
this.setState({ description: truncate });
this.setState({ showTrackerLearnMore: true });
this.setState({ wtmID: data.id });
} else {
this.setState({ description: t('tracker_description_none_found') });
}
@@ -99,8 +100,13 @@ class GlobalTracker extends React.Component {
* @return {ReactComponent} ReactComponent instance
*/
render() {
const { tracker, language } = this.props;
const { showMoreInfo, description, showTrackerLearnMore } = this.state;
const { tracker } = this.props;
const {
showMoreInfo,
description,
showTrackerLearnMore,
wtmID
} = this.state;
return (
<div className="global-blocking-trk">
<div className="row align-middle trk-header">
@@ -119,7 +125,7 @@ class GlobalTracker extends React.Component {
{
showTrackerLearnMore && (
<div className={(!showTrackerLearnMore ? 'hide' : '')}>
<a target="_blank" rel="noopener noreferrer" title={tracker.name} href={`${globals.APPS_BASE_URL}/${language}/apps/${encodeURIComponent(tracker.name.replace(/\s+/g, '_').toLowerCase())}`}>
<a target="_blank" rel="noopener noreferrer" title={tracker.name} href={`${globals.WTM_BASE_URL}/trackers/${encodeURIComponent(wtmID).toLowerCase()}.html`}>
{ t('tracker_description_learn_more') }
</a>
</div>
@@ -35,6 +35,7 @@ class Tracker extends React.Component {
showTrackerLearnMore: false,
trackerClasses: '',
warningImageTitle: '',
wtmID: null,
};

// click bindings
@@ -139,27 +140,27 @@ class Tracker extends React.Component {
/**
* Implement handler for clicking on the tracker title
* which shows/hides tracker description. On show it retrieves
* description from https://apps.ghostery.com and sets it in state.
* description from whotracks.me and sets it in state.
*/
toggleDescription() {
const { tracker, language } = this.props;
const { tracker } = this.props;
const { description } = this.state;
this.setState(prevState => ({ showMoreInfo: !prevState.showMoreInfo }));

const { description } = this.state;
if (description) {
return;
}

this.setState({ description: t('tracker_description_getting') });

sendMessageInPromise('getTrackerDescription', {
url: `${globals.APPS_BASE_URL}/${language}/apps/${
encodeURIComponent(tracker.name.replace(/\s+/g, '_').toLowerCase())}?format=json`,
sendMessageInPromise('getTrackerInfo', {
url: `${globals.WTM_BASE_URL}/data/trackers/ghostery/${tracker.id}.json`,
}).then((data) => {
if (data) {
const truncate = (data.length > 200) ? `${data.substr(0, 199)}...` : data;
if (data && data.description) {
const truncate = (data.description.length > 200) ? `${data.description.substr(0, 199)}...` : data.description;
this.setState({ description: truncate });
this.setState({ showTrackerLearnMore: true });
this.setState({ wtmID: data.id });
} else {
this.setState({ description: t('tracker_description_none_found') });
}
@@ -335,6 +336,7 @@ class Tracker extends React.Component {
warningImageTitle,
showMoreInfo,
showTrackerLearnMore,
wtmID,
} = this.state;

let sources;
@@ -400,7 +402,7 @@ class Tracker extends React.Component {
<div className="trk-description">
{description}
<div className={(!showTrackerLearnMore ? 'hide' : '')}>
<a target="_blank" rel="noopener noreferrer" title={tracker.name} href={`${globals.APPS_BASE_URL}/${language}/apps/${encodeURIComponent(tracker.name.replace(/\s+/g, '_').toLowerCase())}`}>
<a target="_blank" rel="noopener noreferrer" title={tracker.name} href={`${globals.WTM_BASE_URL}/trackers/${encodeURIComponent(wtmID).toLowerCase()}.html`}>
{t('tracker_description_learn_more')}
</a>
</div>
@@ -3,10 +3,11 @@
"author": "Ghostery",
"name": "__MSG_name__",
"short_name": "Ghostery",
"version": "8.5.4",
"version_name": "8.5.4",
"version": "8.5.5",
"version_name": "8.5.5",
"default_locale": "en",
"description": "__MSG_short_description__",
"debug": true,
"icons": {
"16": "app/images/icon16.png",
"48": "app/images/icon48.png",
@@ -111,4 +112,4 @@
"web_accessible_resources": [
"app/images/*"
]
}
}
@@ -759,10 +759,11 @@ function onMessageHandler(request, sender, callback) {
}
return true;
}
if (name === 'getTrackerDescription') {
if (name === 'getTrackerInfo') {
utils.getJson(message.url).then((result) => {
const description = (result) ? ((result.company_in_their_own_words) ? result.company_in_their_own_words : ((result.company_description) ? result.company_description : '')) : '';
callback(description);
callback(result);
}).catch(() => {
callback(false);
});
return true;
}
@@ -58,6 +58,7 @@ class Globals {
this.CMP_BASE_URL = `https://${this.DEBUG ? 'staging-cmp-cdn' : 'cmp-cdn'}.ghostery.com`;
this.CDN_BASE_URL = `https://${this.DEBUG ? 'staging-cdn' : 'cdn'}.ghostery.com`;
this.APPS_BASE_URL = `https://${this.DEBUG ? 'staging-apps' : 'apps'}.ghostery.com`;
this.WTM_BASE_URL = 'https://www.whotracks.me';
this.GCACHE_BASE_URL = `https://${this.DEBUG ? 'staging-gcache' : 'gcache'}.ghostery.com`;
this.AUTH_SERVER = `https://consumerapi.${this.GHOSTERY_ROOT_DOMAIN}`;
this.ACCOUNT_SERVER = `https://accountapi.${this.GHOSTERY_ROOT_DOMAIN}`;
ProTip! Use n and p to navigate between commits in a pull request.