[polari] utils: Specify expire parameter for paste.gnome.org
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] utils: Specify expire parameter for paste.gnome.org
- Date: Mon, 10 Apr 2017 22:40:15 +0000 (UTC)
commit 2ebbe402d1ff843e531d9edc888994fe4c80833c
Author: Florian Müllner <fmuellner gnome org>
Date: Mon Apr 3 23:34:05 2017 +0200
utils: Specify expire parameter for paste.gnome.org
To deal with spammers, the default expire period on paste.gnome.org
had to be reduced significantly. The previously used value of one
day turned out to work quite well for Polari, so pick the expire
parameter that comes closest to that and include it in the paste
parameters.
https://bugzilla.gnome.org/show_bug.cgi?id=780888
src/utils.js | 42 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/src/utils.js b/src/utils.js
index afa86b2..1fd4606 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -86,6 +86,8 @@ const _urlRegexp = new RegExp(
const _channelRegexp = new RegExp('(^| )#([\\w\\+\\.-]+)','g');
+let _gpasteExpire = undefined;
+
let _inFlatpakSandbox = undefined;
function isFlatpakSandbox() {
@@ -202,13 +204,53 @@ function updateTerms(terms, str) {
return changed;
}
+function _getGpasteExpire(callback) {
+ let session = new Soup.Session();
+ let paramUrl = GPASTE_BASEURL + 'api/json/parameter/expire';
+ let message = Soup.form_request_new_from_hash('GET', paramUrl, {});
+ session.queue_message(message, (s, message) => {
+ if (message.status_code != Soup.KnownStatusCode.OK) {
+ callback(false);
+ return;
+ }
+
+ let info = {};
+ try {
+ info = JSON.parse(message.response_body.data);
+ } catch(e) {
+ log(e.message);
+ }
+
+ let values = info.result ? info.result.values : undefined;
+ if (!values)
+ callback(false);
+
+ let day = 24 * 60 * 60;
+ _gpasteExpire = values.reduce((acc, val) => {
+ return Math.abs(day - acc) < Math.abs(day - val) ? acc : val;
+ }, 0).toString();
+ callback(true);
+ });
+}
+
function gpaste(text, title, callback) {
+ if (_gpasteExpire == undefined) {
+ _getGpasteExpire(success => {
+ if (success)
+ gpaste(text, title, callback);
+ else
+ callback(null);
+ });
+ return;
+ }
+
if (title.length > MAX_PASTE_TITLE_LENGTH)
title = title.substr(0, MAX_PASTE_TITLE_LENGTH - 1) + '…';
let params = {
title: title,
data: text,
+ expire: _gpasteExpire,
language: 'text'
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]