2022-07-07 18:23:44 +02:00
|
|
|
var express = require('express');
|
|
|
|
var router = express.Router();
|
2022-07-07 19:03:04 +02:00
|
|
|
const Masto = require('mastodon');
|
2022-07-07 18:23:44 +02:00
|
|
|
|
|
|
|
/* GET users listing. */
|
|
|
|
router.get('/', function(req, res, next) {
|
2022-07-07 19:03:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports.toot = async ({accessToken, status, visibility, file}) => {
|
|
|
|
const masto = new Masto({/* w w w . d em o 2s . c o m */
|
|
|
|
access_token: accessToken,
|
|
|
|
api_url: process.env.INSTANCE_MASTODON+'/api/v1/',
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!file) {
|
|
|
|
return masto.post('statuses', {
|
|
|
|
status,
|
|
|
|
visibility,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const response = await masto.post('media', {
|
|
|
|
file: {
|
|
|
|
value: file,
|
|
|
|
options: {
|
|
|
|
filename: 'test.png',
|
|
|
|
contentType: 'image/png',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return masto.post('statuses', {
|
|
|
|
status,
|
|
|
|
visibility,
|
|
|
|
media_ids: [response.data.id],
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
res.send('message posted');
|
|
|
|
|
2022-07-07 18:23:44 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = router;
|