hop, ajout a la file d'attente de messages

This commit is contained in:
Tykayn 2022-07-10 22:38:47 +02:00 committed by tykayn
parent dfd24253db
commit d8917676ef
4 changed files with 93 additions and 61 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

Binary file not shown.

View File

@ -16,6 +16,7 @@ router.get('/', function (req, res, next) {
res.render('index', {title: 'Express'});
});
// publier un message avec un certain compte
router.get('/publish', function (req, res, next) {
res.render('index', {title: 'Express'});
@ -64,10 +65,39 @@ function createTables(newdb) {
const prepared = prepare();
}
// ajouter un message à la file d'attente avec un certain compte
router.post('/add-to-queue', function (req, res, next) {
// get account
// get content*
// add to sql DB
// insert into posts_scheduled
// values (NULL, "modominem", "un message d'example", NULL);
var db = new sqlite3.Database(database_masto, sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, (err) => {
}
)
db.serialize(() => {
db.run('INSERT INTO posts_scheduled VALUES(?,?,?,?,?)', [null, req.body.author, req.body.message, req.body.fichier, null], function (err) {
if (err) {
return console.log(err.message);
res.render('index', {message: 'erreur '+err.message});
}
console.log("nouveau post ajouté", req.body.author, req.body.message);
res.render('index', {message: 'message ajouté OK'});
});
});
});
function getAllPosts(db) {
return db.query(sql`SELECT *
FROM posts_scheduled
ORDER BY action_id ASC LIMIT 15;`)
ORDER BY action_id DESC LIMIT 15;`)
}
router.get('/init-db', function (req, res, next) {
@ -144,7 +174,7 @@ router.get('/publish-last-entry', function (req, res, next) {
let media_filename = "colline.JPG"
let file_path = "assets/not_published/" + media_filename
let accessToken = process.env.TOKEN
let sensitive= false;
let sensitive = false;
let scheduled_at = "2022-07-07T21:36:29.100Z";
let account_id = "2974"; // curator bliss
let language = "fr";
@ -163,10 +193,10 @@ router.get('/publish-last-entry', function (req, res, next) {
api_url: process.env.INSTANCE_MASTODON + '/api/v1/',
});
if(enable_post){
if (enable_post) {
masto.post('media', { file: fs.createReadStream(file_path) }).then(resp => {
masto.post('media', {file: fs.createReadStream(file_path)}).then(resp => {
id = resp.data.id;
// doc https://docs.joinmastodon.org/methods/statuses/
@ -174,17 +204,17 @@ router.get('/publish-last-entry', function (req, res, next) {
console.log(resp.data)
masto.post('statuses', {
status: status,
media_ids: [id] ,
media_ids: [id],
account_id,
visibility,
language,
sensitive
}).then(resp=>{
}).then(resp => {
// succès, marquer le post comme fait en BDD
console.log(resp)
var oldPath = file_path
var newPath = 'assets/published/'+media_filename
var newPath = 'assets/published/' + media_filename
fs.rename(oldPath, newPath, function (err) {
if (err) throw err
@ -192,7 +222,7 @@ router.get('/publish-last-entry', function (req, res, next) {
})
},
err=> {
err => {
console.error(err)
})
})

View File

@ -4,7 +4,9 @@ block content
div.column-header__wrapper
h1.button.column-header Publier un message
form(action="/submit",method="post")
if message
p.alert.alert-error=message
form(action="/add-to-queue",method="post")
span.account
span compte
br
@ -37,7 +39,7 @@ block content
br
label
span Fichier à joindre
textarea.autosuggest-textarea__textarea(name="fichier", width="500", lines="1")
textarea.autosuggest-textarea__textarea(name="fichier", width="500", lines="1",value="default_picture.jpg")
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")