Skip to content

Commit

Permalink
Merge pull request #13 from polarityio/add-throttling
Browse files Browse the repository at this point in the history
Add throttling
  • Loading branch information
sarus authored Oct 18, 2021
2 parents 440f7d2 + 47fedc3 commit ed21b77
Show file tree
Hide file tree
Showing 9 changed files with 1,442 additions and 533 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ This option allows you to specify a regex used to ignore IPv4 Addresses. Any IP

If checked, the Overlay Window will receive the URL\'s screenshot from the Polarity server rather than directly from the urlscan website. If your screenshot images are not properly displaying try enabling this option as it can resolve issues in some environments with unsupported web proxy configurations on the client.

### Max Concurrent Requests

Maximum number of concurrent requests. Integration must be restarted after changing this option. Defaults to 20.

### Minimum Time Between Lookups

Minimum amount of time in milliseconds between lookups. Integration must be restarted after changing this option. Defaults to 100.

## Installation Instructions

Installation instructions for integrations are provided on the [PolarityIO GitHub Page](https://polarityio.github.io/).
Expand Down
101 changes: 89 additions & 12 deletions components/us-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,112 @@ polarity.export = PolarityComponent.extend({
details: Ember.computed.alias('block.data.details'),
entity: Ember.computed.alias('block.entity'),
message: '',
errorMessage: null,
isRunning: false,
submitAsPublic: false,
tags: '',
init() {
this._super(...arguments);

if (!this.get('block._state')) {
this.set('block._state', {});
this.set('block._state.loadingQuota', false);
this.set('block._state.viewQuota', false);
this.set('block._state.isSubmitting', false);
}
},
actions: {
showQuota: function () {
this.toggleProperty(`block._state.viewQuota`);
if (!this.get('details.quota')) {
this.fetchQuota();
}
},
getQuota: function () {
this.fetchQuota();
},
retryLookup: function () {
this.set('running', true);

this.set('block._state.errorMessage', '');
const payload = {
action: 'RETRY_LOOKUP',
entity: this.get('block.entity')
};

this.sendIntegrationMessage(payload)
.then((result) => {
if (result.data.summary) this.set('summary', result.summary);
this.set('block.data', result.data);
})
.catch((err) => {
this.set('block._state.errorMessage', JSON.stringify(err, null, 4));
})
.finally(() => {
this.set('running', false);
});
},
submitUrl: function () {
const outerThis = this;

this.set('message', '');
this.set('errorMessage', '');
this.set('isRunning', true);
this.set('block._state.errorMessage', '');
this.set('block._state.isSubmitting', true);

this.sendIntegrationMessage({
data: { entity: this.entity, tags: this.tags, submitAsPublic: this.submitAsPublic }
})
const payload = {
action: 'SUBMIT_URL',
data: {
entity: this.entity,
tags: this.tags,
submitAsPublic: this.submitAsPublic
}
};

this.sendIntegrationMessage(payload)
.then((newDetails) => {
console.info(newDetails);
outerThis.set('message', newDetails.message || 'Success!');
outerThis.set('details', newDetails);
})
.catch((err) => {
outerThis.set(
'errorMessage',
`Failed to Submit: ${err.detail || err.message || err.title || err.description || 'Unknown Reason'}`
);
console.error(err);
outerThis.set('details', {
canSubmitUrl: true
});
if (typeof err.meta === 'string') {
this.set('block._state.errorMessage', err.meta);
} else if (
typeof err.meta === 'object' &&
typeof err.meta.errorMessage === 'string' &&
typeof err.meta.description === 'string'
) {
this.set('block._state.errorMessage', `${err.meta.errorMessage}\n\n${err.meta.description}`);
} else if (
typeof err.meta === 'object' &&
typeof err.meta.detail === 'string'
) {
this.set('block._state.errorMessage', err.meta.detail);
} else {
this.set('block._state.errorMessage', JSON.stringify(err.meta));
}
})
.finally(() => {
this.set('isRunning', false);
this.set('block._state.isSubmitting', false);
outerThis.get('block').notifyPropertyChange('data');
});
}
},
fetchQuota() {
this.set(`block._state.loadingQuota`, true);
const payload = {
action: 'GET_QUOTA',
entity: this.get('block.entity')
};
this.sendIntegrationMessage(payload)
.then((result) => {
this.set(`details.quota`, result.quota);
})
.catch((error) => {})
.finally(() => {
this.set(`block._state.loadingQuota`, false);
});
}
});
22 changes: 21 additions & 1 deletion config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,31 @@ module.exports = {
key: 'downloadScreenshot',
name: 'Proxy Screenshots through Polarity Server',
description:
'If checked, the Overlay Window will receive the URL\'s screenshot from the Polarity server rather than directly from the urlscan website. If your screenshot images are not properly displaying try enabling this option as it can resolve issues in some environments with unsupported web proxy configurations on the client.',
"If checked, the Overlay Window will receive the URL's screenshot from the Polarity server rather than directly from the urlscan website. If your screenshot images are not properly displaying try enabling this option as it can resolve issues in some environments with unsupported web proxy configurations on the client.",
default: false,
type: 'boolean',
userCanEdit: false,
adminOnly: true
},
{
key: 'maxConcurrent',
name: 'Max Concurrent Requests',
description:
'Maximum number of concurrent requests. Integration must be restarted after changing this option. Defaults to 20.',
default: 20,
type: 'number',
userCanEdit: false,
adminOnly: true
},
{
key: 'minTime',
name: 'Minimum Time Between Lookups',
description:
'Minimum amount of time in milliseconds between lookups. Integration must be restarted after changing this option. Defaults to 100.',
default: 100,
type: 'number',
userCanEdit: false,
adminOnly: true
}
]
};
Loading

0 comments on commit ed21b77

Please sign in to comment.