Added debug mode
This commit is contained in:
parent
d601f4bfab
commit
5476a9bb06
6 changed files with 1274 additions and 43 deletions
|
@ -1,7 +1,7 @@
|
|||
import fs from "fs";
|
||||
import request from "request";
|
||||
import Masto from "mastodon";
|
||||
import config from "../config";
|
||||
import { mastodonToken, mastondonApi, isDebug } from "../config";
|
||||
|
||||
/**
|
||||
* Fonction permettant de formater une réponse API
|
||||
|
@ -95,10 +95,11 @@ const _formatMessage = (values) => {
|
|||
|
||||
/**
|
||||
* Fonction publiant un message (et média si attaché) sur Mastdon
|
||||
* @param {Object} playing
|
||||
* @param {Function} cb
|
||||
* @param {Object} playing
|
||||
* @param {Object} logger
|
||||
* @param {Function} cb
|
||||
*/
|
||||
const _publishMessage = (playing, cb) => {
|
||||
const _publishMessage = (playing, logger, cb) => {
|
||||
const callback = (err, res) => {
|
||||
if (err) {
|
||||
cb(err);
|
||||
|
@ -113,13 +114,15 @@ const _publishMessage = (playing, cb) => {
|
|||
|
||||
// Instanciation de Mastodon
|
||||
const M = new Masto({
|
||||
access_token: config.mastodonToken,
|
||||
api_url: config.mastondonApi,
|
||||
access_token: mastodonToken,
|
||||
api_url: mastondonApi,
|
||||
});
|
||||
|
||||
if (cover) {
|
||||
_getMedia(cover, (err, dest) => {
|
||||
if (err) {
|
||||
if (isDebug) {
|
||||
logger.info({ cover, status });
|
||||
} else if (err) {
|
||||
M.post("statuses", { status }, callback);
|
||||
} else {
|
||||
M.post("media", { file: fs.createReadStream(dest) })
|
||||
|
@ -132,6 +135,8 @@ const _publishMessage = (playing, cb) => {
|
|||
});
|
||||
}
|
||||
});
|
||||
} else if (isDebug) {
|
||||
logger.info(status);
|
||||
} else {
|
||||
M.post("statuses", { status }, callback);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue