hop, ajout a la file d'attente de messages
This commit is contained in:
parent
dfd24253db
commit
d8917676ef
BIN
assets/not_published/default_picture.jpg
Executable file
BIN
assets/not_published/default_picture.jpg
Executable file
Binary file not shown.
After Width: | Height: | Size: 130 KiB |
Binary file not shown.
146
routes/index.js
146
routes/index.js
@ -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'});
|
||||||
@ -42,13 +43,13 @@ function createTables(newdb) {
|
|||||||
await db.query(sql`
|
await db.query(sql`
|
||||||
create table posts_scheduled
|
create table posts_scheduled
|
||||||
(
|
(
|
||||||
action_id integer
|
action_id integer
|
||||||
constraint posts_scheduled_pk
|
constraint posts_scheduled_pk
|
||||||
primary key autoincrement,
|
primary key autoincrement,
|
||||||
post_username varchar not null,
|
post_username varchar not null,
|
||||||
content varchar not null,
|
content varchar not null,
|
||||||
medias varchar,
|
medias varchar,
|
||||||
datetime datetime
|
datetime datetime
|
||||||
);
|
);
|
||||||
|
|
||||||
create unique index posts_scheduled_action_id_uindex
|
create unique index posts_scheduled_action_id_uindex
|
||||||
@ -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) {
|
||||||
@ -141,10 +171,10 @@ router.get('/publish-last-entry', function (req, res, next) {
|
|||||||
|
|
||||||
let status = "#mastoart of @tykayn"
|
let status = "#mastoart of @tykayn"
|
||||||
let visibility = "unlisted" // public, unlisted, private, direct.
|
let visibility = "unlisted" // public, unlisted, private, direct.
|
||||||
let media_filename = "colline.JPG"
|
let media_filename = "colline.JPG"
|
||||||
let file_path = "assets/not_published/" + media_filename
|
let file_path = "assets/not_published/" + media_filename
|
||||||
let accessToken = process.env.TOKEN
|
let accessToken = process.env.TOKEN
|
||||||
let sensitive= false;
|
let sensitive = false;
|
||||||
let scheduled_at = "2022-07-07T21:36:29.100Z";
|
let scheduled_at = "2022-07-07T21:36:29.100Z";
|
||||||
let account_id = "2974"; // curator bliss
|
let account_id = "2974"; // curator bliss
|
||||||
let language = "fr";
|
let language = "fr";
|
||||||
@ -158,70 +188,70 @@ router.get('/publish-last-entry', function (req, res, next) {
|
|||||||
//
|
//
|
||||||
// console.log(err, accessToken, refreshToken , res);
|
// console.log(err, accessToken, refreshToken , res);
|
||||||
|
|
||||||
const masto = new Masto({
|
const masto = new Masto({
|
||||||
access_token: accessToken,
|
access_token: accessToken,
|
||||||
api_url: process.env.INSTANCE_MASTODON + '/api/v1/',
|
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;
|
id = resp.data.id;
|
||||||
// doc https://docs.joinmastodon.org/methods/statuses/
|
// doc https://docs.joinmastodon.org/methods/statuses/
|
||||||
|
|
||||||
console.log('media id ', resp.data.id)
|
console.log('media id ', resp.data.id)
|
||||||
console.log(resp.data)
|
console.log(resp.data)
|
||||||
masto.post('statuses', {
|
masto.post('statuses', {
|
||||||
status: status,
|
status: status,
|
||||||
media_ids: [id] ,
|
media_ids: [id],
|
||||||
account_id,
|
account_id,
|
||||||
visibility,
|
visibility,
|
||||||
language,
|
language,
|
||||||
sensitive
|
sensitive
|
||||||
}).then(resp=>{
|
}).then(resp => {
|
||||||
// succès, marquer le post comme fait en BDD
|
// succès, marquer le post comme fait en BDD
|
||||||
console.log(resp)
|
console.log(resp)
|
||||||
|
|
||||||
var oldPath = file_path
|
var oldPath = file_path
|
||||||
var newPath = 'assets/published/'+media_filename
|
var newPath = 'assets/published/' + media_filename
|
||||||
|
|
||||||
fs.rename(oldPath, newPath, function (err) {
|
fs.rename(oldPath, newPath, function (err) {
|
||||||
if (err) throw err
|
if (err) throw err
|
||||||
console.log('Successfully renamed - AKA moved!')
|
console.log('Successfully renamed - AKA moved!')
|
||||||
})
|
})
|
||||||
|
|
||||||
},
|
},
|
||||||
err=> {
|
err => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
// if (!file) {
|
// if (!file) {
|
||||||
// return masto.post('statuses', {
|
// return masto.post('statuses', {
|
||||||
// status,
|
// status,
|
||||||
// visibility,
|
// visibility,
|
||||||
// });
|
// });
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// const response = await masto.post('media', {
|
// const response = await masto.post('media', {
|
||||||
// file: {
|
// file: {
|
||||||
// value: file,
|
// value: file,
|
||||||
// options: {
|
// options: {
|
||||||
// filename: 'assets/test.png',
|
// filename: 'assets/test.png',
|
||||||
// contentType: 'image/png',
|
// contentType: 'image/png',
|
||||||
// },
|
// },
|
||||||
// },
|
// },
|
||||||
// });
|
// });
|
||||||
//
|
//
|
||||||
// return masto.post('statuses', {
|
// return masto.post('statuses', {
|
||||||
// status,
|
// status,
|
||||||
// visibility,
|
// visibility,
|
||||||
// media_ids: [response.data.id],
|
// media_ids: [response.data.id],
|
||||||
// });
|
// });
|
||||||
|
|
||||||
// })
|
// })
|
||||||
|
|
||||||
res.render('index', {});
|
res.render('index', {});
|
||||||
//
|
//
|
||||||
|
@ -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")
|
||||||
|
Loading…
Reference in New Issue
Block a user