add direct post to homepage

This commit is contained in:
Tykayn 2022-07-11 17:04:46 +02:00 committed by tykayn
parent 273a77a243
commit 142e5da2f4
5 changed files with 128 additions and 10 deletions

View File

@ -13,4 +13,8 @@ a {
border-left: 3px solid #ccc;
padding-left: 1em;
}
select{
padding:1rem;
margin: 1em 0;
}

View File

@ -11,12 +11,44 @@ const accounts_to_select = [
label: "modominem",
value: "modominem"
},
{
label: "qzine",
value: "qzine"
},
{
label: "curator",
value: "curator"
},
{
label: "kurator",
value: "kurator"
},
{
label: "voix du nucléaire",
value: "voixdunucleaire"
},
{
label: "The greatest Meme",
value: "meme"
},
{
label: "cil de gometz",
value: "cil_gometz"
},
]
const default_times = ['08:02:00', '08:42:00', '09:10:00', '09:15:00', '10:22:00', '12:22:00']
const database_masto = "mastodon_multi_accounts.db"
/* GET home page. */
let schedule_time = '';
router.get('/', function (req, res, next) {
res.render('index', {title: 'Express'});
if (!req.body.schedule_time) {
schedule_time = default_times[Math.floor(Math.random() * default_times.length)];
}
res.render('index', {accounts_to_select, reqBody: req.body, schedule_time});
});
@ -288,4 +320,58 @@ router.get('/dispatch-publication-in-time', function (req, res, next) {
});
router.post('/direct-post', function (req, res, next) {
if (process.env['TOKEN_' + req.body.author]) {
let visibility = 'public';
let language = 'fr';
let sensitive = false;
let accessToken = process.env['TOKEN_' + req.body.author]
console.log('accessToken', accessToken)
const masto = new Masto({
access_token: accessToken,
api_url: process.env.INSTANCE_MASTODON + '/api/v1/',
});
let params = {
status: req.body.message,
visibility,
language,
sensitive
}
if (req.body.cw) {
params['spoiler_text'] = req.body.cw
}
if (req.body.scheduled_at && req.body.scheduled_at_bool) {
let dateschedule = new Date(req.body.scheduled_at)
params['scheduled_at'] = dateschedule.toISOString()
}
console.log(req.body)
if (!req.body.fichier) {
masto.post('statuses', params).then(rep => {
console.log('rep', rep)
}, err => {
console.error(err)
})
res.render('index', {bodyReq: req.body})
}
// if (req.body.fichier) {
//
// masto.post('statuses', params).then(rep => {
// console.log('rep', rep)
// }, err => {
// console.error(err)
// })
// res.render('index', {bodyReq: req.body})
// }
} else {
console.error('pas de token pour ' + req.body.author)
}
})
module.exports = router;

11
routes/postQzine.js Normal file
View File

@ -0,0 +1,11 @@
var sqlite3 = require('sqlite3');
var Masto = require('mastodon');
// masto.post('statuses', {
// status: status,
// media_ids: [id],
// account_id,
// visibility,
// language,
// sensitive
// }

View File

@ -6,7 +6,8 @@ block content
if message
p.alert.alert-error=message
form(action="/add-to-queue",method="post")
//form(action="/add-to-queue",method="post")
form(action="/direct-post",method="post")
span.account
span Choix du compte
br
@ -15,9 +16,13 @@ block content
// .navigation-bar__profile
// a.permalink.acct(href='https://mastodon.cipherbliss.com/@voixdunucleaire')
// strong @voixdunucleaire
select(method="post", name="author")
//p=accounts_to_select.length
select(method="post", name="author", value=bodyReq? bodyReq.author:"")
option(value="tykayn")
span tykayn
span TyKayn
option(value="voixdunuc")
span voix du nucléaire
option(value="modominem")
@ -30,19 +35,29 @@ block content
span meme
option(value="cil_gometz")
span CIL Gometz
// each item in accounts_to_select.length ? item : ['There are no values']
// option(value=item.label)
// span=item.value
br
div.compose-form__autosuggest-wrapper
.autosuggest-textarea
label
span Content warning (optionnel)
input.autosuggest-textarea__textarea(name="cw", type="text", width="500")
span Quavez-vous en tête?
textarea.autosuggest-textarea__textarea(name="message", width="500", lines="20",autofocus="autofocus")
br
label
span Fichier à joindre
span Fichier à joindre (optionnel)
textarea.autosuggest-textarea__textarea(name="fichier", width="500", lines="1",value="default_picture.jpg")
label Schedule in time
input.input.checkbox(type="checkbox", value=false)
input(type="date", name="schedule")
fieldset.wip
label Schedule in time (work in progress, not working by now)
input.input.checkbox(type="checkbox", value=false, name="scheduled_at_bool")
input.input.checkbox(type="date", name="scheduled_at")
input.input.checkbox(type="text", name="scheduled_at_time",value=schedule_time)
//div(id=flatpickr)
br
div.composer--publisher
input.button.primary(type="submit", value="ajouter à la file d'attente")
//input.button.primary(type="submit", value="ajouter à la file d'attente")
input.button.primary(type="submit", value="poster tout de suite")

View File

@ -4,7 +4,9 @@ html
title= title + 'Multi account posting mastodon'
link(rel='stylesheet', href='https://mastodon.cipherbliss.com/packs/css/core/common-d59731aa.chunk.css')
link(rel='stylesheet', href='https://mastodon.cipherbliss.com/packs/css/flavours/glitch/common-6bdd3298.chunk.css')
link(rel='stylesheet', href='https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css')
link(rel='stylesheet', href='/stylesheets/style.css')
script(src='https://cdn.jsdelivr.net/npm/flatpickr')
body
block nav
div.columns-area__panels__main.with-fab