[polari] utils: Use paste.gnome.org as paste service
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [polari] utils: Use paste.gnome.org as paste service
- Date: Fri, 2 Oct 2015 14:58:03 +0000 (UTC)
commit de091df17e0ccef62a50c31ce3e891ff1c01d817
Author: Florian Müllner <fmuellner gnome org>
Date: Fri Oct 2 14:48:34 2015 +0200
utils: Use paste.gnome.org as paste service
We only use the most basic functionality for uploading text to an
external paste service, so any paste service does the job for us
and fpaste is as good as any other from a technical point of view.
However politically it is problematic to use a service that is
provided by a specific distro, so pick a more neutral option with
the newly set up paste.gnome.org.
https://bugzilla.gnome.org/show_bug.cgi?id=726053
src/pasteManager.js | 2 +-
src/utils.js | 50 +++++++-------------------------------------------
2 files changed, 8 insertions(+), 44 deletions(-)
---
diff --git a/src/pasteManager.js b/src/pasteManager.js
index 8c87a92..08c7947 100644
--- a/src/pasteManager.js
+++ b/src/pasteManager.js
@@ -84,7 +84,7 @@ const PasteManager = new Lang.Class({
}
let nick = room.channel.connection.self_contact.alias;
- Utils.fpaste(text, nick, Lang.bind(this,
+ Utils.gpaste(text, nick, Lang.bind(this,
function(url) {
if (!url) {
notification.close();
diff --git a/src/utils.js b/src/utils.js
index 76149e4..eb912c9 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -25,7 +25,7 @@ const Soup = imports.gi.Soup;
const Signals = imports.signals;
-const FPASTE_BASEURL = 'http://paste.fedoraproject.org/'
+const GPASTE_BASEURL = 'https://paste.gnome.org/'
// http://daringfireball.net/2010/07/improved_regex_for_matching_urls
const _balancedParens = '\\((?:[^\\s()<>]+|(?:\\(?:[^\\s()<>]+\\)))*\\)';
@@ -93,51 +93,15 @@ function findUrls(str) {
return res;
}
-function fpaste(text, user, callback) {
- let getUrl = function(session, id) {
- let longUrl = FPASTE_BASEURL + id;
- session.queue_message(Soup.Message.new('POST', longUrl + '/json'),
- function(session, message) {
- if (message.status_code != Soup.KnownStatusCode.OK) {
- callback(null);
- return;
- }
-
- // workaround: the response contains the pasted data
- // unescaped (e.g. newlines), which is not legal json;
- // just grab the property we're interested in
- let lines = message.response_body.data.split('\n');
- let shortUrl = null;
- for (let i = 0; i < lines.length; i++) {
- if (lines[i].indexOf('short_url') > -1) {
- shortUrl = lines[i];
- break;
- }
- }
-
- let info = {};
- try {
- if (shortUrl)
- info = JSON.parse('{ %s }'.format(shortUrl));
- } catch(e) {
- log(e.message);
- }
- if (info.short_url)
- callback(info.short_url);
- else
- callback(longUrl);
- });
- };
+function gpaste(text, user, callback) {
let params = {
- paste_data: text,
- paste_lang: 'text',
- paste_user: user,
- api_submit: '1',
- mode: 'json'
+ data: text,
+ language: 'text'
};
let session = new Soup.Session();
- let message = Soup.form_request_new_from_hash('POST', FPASTE_BASEURL, params);
+ let createUrl = GPASTE_BASEURL + 'api/json/create';
+ let message = Soup.form_request_new_from_hash('POST', createUrl, params);
session.queue_message(message,
function(session, message) {
if (message.status_code != Soup.KnownStatusCode.OK) {
@@ -152,7 +116,7 @@ function fpaste(text, user, callback) {
log(e.message);
}
if (info.result && info.result.id)
- getUrl(session, info.result.id);
+ callback(GPASTE_BASEURL + info.result.id);
else
callback(null);
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]