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'}); res.render('index', {title: 'Express'});
}); });
// publier un message avec un certain compte // publier un message avec un certain compte
router.get('/publish', function (req, res, next) { router.get('/publish', function (req, res, next) {
res.render('index', {title: 'Express'}); res.render('index', {title: 'Express'});
@ -64,10 +65,39 @@ function createTables(newdb) {
const prepared = prepare(); 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) { function getAllPosts(db) {
return db.query(sql`SELECT * return db.query(sql`SELECT *
FROM posts_scheduled 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) { router.get('/init-db', function (req, res, next) {

View File

@ -4,7 +4,9 @@ block content
div.column-header__wrapper div.column-header__wrapper
h1.button.column-header Publier un message 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.account
span compte span compte
br br
@ -37,7 +39,7 @@ block content
br br
label label
span Fichier à joindre 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 br
div.composer--publisher 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")