mirror of
https://github.com/Oreolek/pancakes-or-waffles.git
synced 2024-05-21 18:28:24 +03:00
Mastodon upload API
This commit is contained in:
parent
151e6b0bbb
commit
695a750e7e
31
bin/upload-mastodon.js
Executable file
31
bin/upload-mastodon.js
Executable file
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env node
|
||||
/*eslint no-console:0 */
|
||||
|
||||
require('dotenv').config();
|
||||
|
||||
const path = require('path');
|
||||
const Masto = require('mastodon');
|
||||
const fs = require('fs');
|
||||
const reporter = require('./tools/reporter.js');
|
||||
const config = require('../.pancakerc');
|
||||
|
||||
if(process.env.MC_MASTO_TOKEN){
|
||||
var M = new Masto({
|
||||
access_token: process.env.MC_MASTO_TOKEN,
|
||||
timeout_ms: 120*1000,
|
||||
api_url: process.env.MC_MASTO_API,
|
||||
})
|
||||
var media = path.join(config.paths.build,config.filenames.base+'.jpg');
|
||||
var id;
|
||||
M.post('media', {
|
||||
file: fs.createReadStream(media)
|
||||
}).then(resp => {
|
||||
id = resp.data.id;
|
||||
M.post('statuses', {
|
||||
status: '',
|
||||
media_ids: [id]
|
||||
})
|
||||
})
|
||||
} else {
|
||||
reporter.error('Missing env variables');
|
||||
}
|
|
@ -11,10 +11,11 @@
|
|||
"dotenv": "^5.0.0",
|
||||
"express": "^4.16.2",
|
||||
"js-yaml": "^3.10.0",
|
||||
"mastodon": "^1.2.2",
|
||||
"mocha": "^5.0.0",
|
||||
"number2text": "^1.1.0",
|
||||
"pluralize": "^7.0.0",
|
||||
"puppeteer": "^1.0.0",
|
||||
"puppeteer": "^1.4.0",
|
||||
"query-string": "^5.0.1",
|
||||
"request": "^2.83.0",
|
||||
"seedrandom": "^2.4.2",
|
||||
|
@ -23,7 +24,7 @@
|
|||
"twit": "^2.2.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^8.4.0"
|
||||
"node": "^10.0.0"
|
||||
},
|
||||
"homepage": "https://twitter.com/pancakesorwaffl",
|
||||
"keywords": [
|
||||
|
@ -44,6 +45,7 @@
|
|||
"install": "node ./bin/webpack-node-modules.js && npm run sign",
|
||||
"localpost": "node ./bin/screenshot.js && node ./bin/upload.js",
|
||||
"shitpost": "node ./bin/screenshot.js && node ./bin/upload-twitter.js",
|
||||
"mastopost": "node ./bin/screenshot.js && node ./bin/upload-mastodon.js",
|
||||
"watch": "open https://localhost:9191 && node ./bin/start-server.js",
|
||||
"test": "concurrently \"node ./bin/run-tests.js\" \"npm run localpost\""
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue