45 lines
912 B
JavaScript
45 lines
912 B
JavaScript
var express = require('express');
|
|
var router = express.Router();
|
|
const Masto = require('mastodon');
|
|
|
|
/* GET users listing. */
|
|
router.get('/', function(req, res, next) {
|
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
module.exports = router;
|