29 lines
754 B
JavaScript
29 lines
754 B
JavaScript
|
import express from "express";
|
||
|
import { ensureLoggedIn } from "connect-ensure-login";
|
||
|
|
||
|
import Mastodon from "mastodon";
|
||
|
import { sendResponse } from "../../../libs/format";
|
||
|
|
||
|
// eslint-disable-next-line new-cap
|
||
|
const router = express.Router();
|
||
|
|
||
|
router.route("/").post(ensureLoggedIn("/connexion"), async (req, res, next) => {
|
||
|
try {
|
||
|
const { url, token } = req.body;
|
||
|
|
||
|
const M = new Mastodon({
|
||
|
access_token: token,
|
||
|
api_url: url,
|
||
|
});
|
||
|
|
||
|
const data = await M.post("statuses", {
|
||
|
status: "Test d'intégration de Mastodon sur mon compte #musictopus 👌",
|
||
|
});
|
||
|
return sendResponse(req, res, data);
|
||
|
} catch (err) {
|
||
|
return next(err);
|
||
|
}
|
||
|
});
|
||
|
|
||
|
export default router;
|