Commit 2604f75e authored by Alexandre Girard's avatar Alexandre Girard
Browse files

add send-to-twitter button pushing image to @_wemawema twitter account -...

add send-to-twitter button pushing image to @_wemawema twitter account - defunct send-to-mastodon feature
parent 6f69cbcf
Pipeline #24880 passed with stages
in 1 minute and 8 seconds
......@@ -178,6 +178,8 @@
<a class="button hidden" href="#" id="download-svg">Download</a>
<a class="button" href="#" id="reset">Reset to default</a>
<a class="button" href="#" id="settings">Show advanced settings</a>
<a class="button" href="#" id="send-to-twitter">Send to Twitter</a>
<a class="button hidden" href="#" id="send-to-mastodon">Send to Mastodon</a>
</div>
<div id="svg" class="hidden">
</div>
......
......@@ -166,6 +166,60 @@ var customImg;
}
});
// send to
document.querySelector('#send-to-twitter').addEventListener('click', function() {
var w = document.getElementById('wemake');
var wx = document.getElementById('wemake-x');
var wy = document.getElementById('wemake-y');
var ws = document.getElementById('wemake-size');
var wc = document.getElementById('wemake-color');
var p = document.getElementById('porn');
var px = document.getElementById('porn-x');
var py = document.getElementById('porn-y');
var ps = document.getElementById('porn-size');
var pc = document.getElementById('porn-color');
var co = document.getElementById('color');
var gli = document.getElementById('add-glitter');
var bgt = document.getElementById('bg-type');
var rc = document.getElementById('rect-color');
var bgr = document.getElementById('bgr-color');
var egr = document.getElementById('egr-color');
var or = document.getElementById('gr-orientation');
var bgi = document.getElementById('bg-img');
var cor = document.getElementById('corners');
var url = new URL(window.location);
url.searchParams.set('w', w.value);
url.searchParams.set('wx', wx.value);
url.searchParams.set('wy', wy.value);
url.searchParams.set('ws', ws.value);
url.searchParams.set('wc', wc.value);
url.searchParams.set('p', p.value);
url.searchParams.set('px', px.value);
url.searchParams.set('py', py.value);
url.searchParams.set('ps', ps.value);
url.searchParams.set('pc', pc.value);
url.searchParams.set('co', co.value);
url.searchParams.set('gli', gli.checked);
url.searchParams.set('bgt', bgt.value);
url.searchParams.set('rc', rc.value);
url.searchParams.set('bgr', bgr.value);
url.searchParams.set('egr', egr.value);
url.searchParams.set('or', or.value);
url.searchParams.set('bgi', bgi.value);
url.searchParams.set('cor', cor.value);
url.searchParams.set('sendToTwitter', true);
var http = new XMLHttpRequest();
http.open("GET", url.toString(), true);
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
alert(http.responseText);
}
}
http.send(null);
});
// Switch text colors
document.querySelector('#switch-colors').addEventListener('click', function(e) {
e.preventDefault();
......
......@@ -10,7 +10,10 @@
"license": "AGPLv3",
"dependencies": {
"body-parser": "^1.18.2",
"canvas": "^1.6.7",
"mastodon": "^1.2.1",
"mastodon-api": "^1.3.0",
"request-form": "^1.0.2"
"request-form": "^1.0.2",
"twit": "^2.2.9"
}
}
const http = require('http');
const parse = require('request-form');
const Twit = require('twit')
const Mastodon = require('mastodon');
// “The more a thing tends to be permanent, the more it tends to be lifeless.”
// ― Alan W. Watts
const mastodonUrl = 'https://mastodon.tetaneutral.net';
const mastodonAccessToken = '48d086a093a4b849d228bfe4478d1703fa2b1969a2e19fce4b90eb81e69d4184';
var T = new Twit({
consumer_key: 'l63P4esB2Qq1dPbEQV3MKxQof',
consumer_secret: 'Xrb6q9XxhRYoLmhmEUUceERdiMGnxkCgq3HwUni83FFMFTGgiB',
access_token: '916752092529913862-XtYflSoJOO4MDz6QnccCIni7c0iROsM',
access_token_secret: 'iUorCLGC5oprBcs9cgJ25sxh1kDUHLY2kB2bpQofW22zw',
});
const M = new Mastodon({
access_token: mastodonAccessToken,
api_url: mastodonUrl + '/api/v1/',
})
var url = require('url');
var Canvas = require('canvas')
var fs = require('fs');
var net = require('net');
var Request = require('request');
var FormData = require('form-data');
const requestHandler = (request, response) => {
var queryData = url.parse(request.url, true).query;
......@@ -31,6 +54,9 @@ const requestHandler = (request, response) => {
var or = (queryData.or !== undefined) ? queryData.or : 'lr';
var cor = (queryData.cor !== undefined) ? queryData.cor : '20';
var sendToTwitter = queryData.sendToTwitter !== undefined;
var sendToMastodon = queryData.sendToMastodon !== undefined;
parse(request, {})
.then(data => {
if (data.text !== undefined) {
......@@ -109,6 +135,62 @@ const requestHandler = (request, response) => {
// Create image
var img = new Buffer(data, 'base64');
// Send to Twitter
if(sendToTwitter) {
const content = {media_data: canvas.toBuffer().toString('base64')};
T.post( 'media/upload', content, (err, data, resp) => {
const media_id_str = data.media_id_string;
const params = {media_id: media_id_str};
T.post('media/metadata/create', params, (err, data, response) => {
if (!err) {
const status = { status: '', media_ids: [media_id_str] };
T.post('statuses/update', status);
}
})
})
}
// Send to Mastodon
if(sendToMastodon) {
const outPath = __dirname + '/wemawema.png',
out = fs.createWriteStream(outPath),
stream = canvas.pngStream();
stream.on('data', (chunk) => out.write(chunk));
stream.on('end', () => {
// M.post('media', { file: fs.createReadStream(outPath) }).then(resp => {
// M.post('statuses', { status: '11:23', media_ids: [resp.data.id] })
// });
// // Alternative method, with content-length
// var r = Request.post({
// url: mastodonUrl + '/api/v1/media',
// headers: {
// 'content-length': img.length,
// 'content-type': 'multipart/form-data',
// 'Authorization': 'Bearer ' + mastodonAccessToken,
// },
// }, (err, resp, body) => {
// M.post('statuses', { status: '11:23', media_ids: [body.id] });
// });
// var form = r.form();
// form.append('file', fs.createReadStream(outPath));
});
}
// Send image
response.writeHead(200, {
'Content-Type': 'image/png',
......
......@@ -118,6 +118,10 @@ beeper@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/beeper/-/beeper-1.1.1.tgz#e6d5ea8c5dad001304a70b22638447f69cb2f809"
bluebird@^3.1.5:
version "3.5.1"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9"
body-parser@^1.18.2:
version "1.18.2"
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.18.2.tgz#87678a19d84b47d859b83199bd59bce222b10454"
......@@ -172,6 +176,14 @@ callsites@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/callsites/-/callsites-0.2.0.tgz#afab96262910a7f33c19a5775825c69f34e350ca"
canvas@^1.6.7:
version "1.6.7"
resolved "https://registry.yarnpkg.com/canvas/-/canvas-1.6.7.tgz#2d8a04b453ec5d6510727cfc697e236dc4ae85dc"
dependencies:
nan "^2.4.0"
parse-css-font "^2.0.2"
units-css "^0.4.0"
caseless@~0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc"
......@@ -248,6 +260,36 @@ cryptiles@3.x.x:
dependencies:
boom "5.x.x"
css-font-size-keywords@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/css-font-size-keywords/-/css-font-size-keywords-1.0.0.tgz#854875ace9aca6a8d2ee0d345a44aae9bb6db6cb"
css-font-stretch-keywords@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/css-font-stretch-keywords/-/css-font-stretch-keywords-1.0.1.tgz#50cee9b9ba031fb5c952d4723139f1e107b54b10"
css-font-style-keywords@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/css-font-style-keywords/-/css-font-style-keywords-1.0.1.tgz#5c3532813f63b4a1de954d13cea86ab4333409e4"
css-font-weight-keywords@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/css-font-weight-keywords/-/css-font-weight-keywords-1.0.0.tgz#9bc04671ac85bc724b574ef5d3ac96b0d604fd97"
css-global-keywords@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/css-global-keywords/-/css-global-keywords-1.0.1.tgz#72a9aea72796d019b1d2a3252de4e5aaa37e4a69"
css-list-helpers@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/css-list-helpers/-/css-list-helpers-1.0.1.tgz#fff57192202db83240c41686f919e449a7024f7d"
dependencies:
tcomb "^2.5.0"
css-system-font-keywords@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/css-system-font-keywords/-/css-system-font-keywords-1.0.0.tgz#85c6f086aba4eb32c571a3086affc434b84823ed"
d@1:
version "1.0.0"
resolved "https://registry.yarnpkg.com/d/-/d-1.0.0.tgz#754bb5bfe55451da69a58b94d45f4c5b0462d58f"
......@@ -782,6 +824,10 @@ isarray@^1.0.0, isarray@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"
isnumeric@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/isnumeric/-/isnumeric-0.2.0.tgz#a2347ba360de19e33d0ffd590fddf7755cbf2e64"
isstream@~0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a"
......@@ -940,6 +986,14 @@ mastodon-api@^1.3.0:
readline "^1.3.0"
request "^2.81.0"
mastodon@^1.2.1:
version "1.2.1"
resolved "https://registry.yarnpkg.com/mastodon/-/mastodon-1.2.1.tgz#b071ee8842a00be934436d855f3e40b544e75d17"
dependencies:
bluebird "^3.1.5"
mime "^1.3.4"
request "^2.68.0"
media-typer@0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
......@@ -992,6 +1046,10 @@ mute-stream@0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.5.tgz#8fbfabb0a98a253d3184331f9e8deb7372fac6c0"
nan@^2.4.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.7.0.tgz#d95bf721ec877e08db276ed3fc6eb78f9083ad46"
natural-compare@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
......@@ -1047,6 +1105,20 @@ os-homedir@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3"
parse-css-font@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/parse-css-font/-/parse-css-font-2.0.2.tgz#7b60b060705a25a9b90b7f0ed493e5823248a652"
dependencies:
css-font-size-keywords "^1.0.0"
css-font-stretch-keywords "^1.0.1"
css-font-style-keywords "^1.0.1"
css-font-weight-keywords "^1.0.0"
css-global-keywords "^1.0.1"
css-list-helpers "^1.0.1"
css-system-font-keywords "^1.0.0"
tcomb "^2.5.0"
unquote "^1.1.0"
path-is-absolute@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
......@@ -1166,7 +1238,7 @@ request-text@^1.0.1:
dependencies:
inflate-body "^1.0.1"
request@^2.81.0:
request@^2.68.0, request@^2.81.0:
version "2.83.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.83.0.tgz#ca0b65da02ed62935887808e6f510381034e3356"
dependencies:
......@@ -1349,6 +1421,10 @@ table@^3.7.8:
slice-ansi "0.0.4"
string-width "^2.0.0"
tcomb@^2.5.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/tcomb/-/tcomb-2.7.0.tgz#10d62958041669a5d53567b9a4ee8cde22b1c2b0"
text-table@~0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
......@@ -1388,6 +1464,14 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0:
version "0.14.5"
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"
twit@^2.2.9:
version "2.2.9"
resolved "https://registry.yarnpkg.com/twit/-/twit-2.2.9.tgz#6710574f81641daa03796a1b4b8e7b78d3d75676"
dependencies:
bluebird "^3.1.5"
mime "^1.3.4"
request "^2.68.0"
type-check@~0.3.2:
version "0.3.2"
resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72"
......@@ -1405,10 +1489,21 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
units-css@^0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/units-css/-/units-css-0.4.0.tgz#d6228653a51983d7c16ff28f8b9dc3b1ffed3a07"
dependencies:
isnumeric "^0.2.0"
viewport-dimensions "^0.2.0"
unpipe@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
unquote@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/unquote/-/unquote-1.1.0.tgz#98e1fc608b6b854c75afb1b95afc099ba69d942f"
user-home@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/user-home/-/user-home-2.0.0.tgz#9c70bfd8169bc1dcbf48604e0f04b8b49cde9e9f"
......@@ -1431,6 +1526,10 @@ verror@1.10.0:
core-util-is "1.0.2"
extsprintf "^1.2.0"
viewport-dimensions@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/viewport-dimensions/-/viewport-dimensions-0.2.0.tgz#de740747db5387fd1725f5175e91bac76afdf36c"
vinyl@^0.5.0:
version "0.5.3"
resolved "https://registry.yarnpkg.com/vinyl/-/vinyl-0.5.3.tgz#b0455b38fc5e0cf30d4325132e461970c2091cde"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment