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'});
|
||||
});
|
||||
|
||||
|
||||
// publier un message avec un certain compte
|
||||
router.get('/publish', function (req, res, next) {
|
||||
res.render('index', {title: 'Express'});
|
||||
@ -42,13 +43,13 @@ function createTables(newdb) {
|
||||
await db.query(sql`
|
||||
create table posts_scheduled
|
||||
(
|
||||
action_id integer
|
||||
action_id integer
|
||||
constraint posts_scheduled_pk
|
||||
primary key autoincrement,
|
||||
post_username varchar not null,
|
||||
content varchar not null,
|
||||
medias varchar,
|
||||
datetime datetime
|
||||
content varchar not null,
|
||||
medias varchar,
|
||||
datetime datetime
|
||||
);
|
||||
|
||||
create unique index posts_scheduled_action_id_uindex
|
||||
@ -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) {
|
||||
@ -141,10 +171,10 @@ router.get('/publish-last-entry', function (req, res, next) {
|
||||
|
||||
let status = "#mastoart of @tykayn"
|
||||
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 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";
|
||||
@ -158,70 +188,70 @@ router.get('/publish-last-entry', function (req, res, next) {
|
||||
//
|
||||
// console.log(err, accessToken, refreshToken , res);
|
||||
|
||||
const masto = new Masto({
|
||||
access_token: accessToken,
|
||||
api_url: process.env.INSTANCE_MASTODON + '/api/v1/',
|
||||
});
|
||||
const masto = new Masto({
|
||||
access_token: accessToken,
|
||||
api_url: process.env.INSTANCE_MASTODON + '/api/v1/',
|
||||
});
|
||||
|
||||
if(enable_post){
|
||||
if (enable_post) {
|
||||
|
||||
|
||||
masto.post('media', { file: fs.createReadStream(file_path) }).then(resp => {
|
||||
id = resp.data.id;
|
||||
// doc https://docs.joinmastodon.org/methods/statuses/
|
||||
masto.post('media', {file: fs.createReadStream(file_path)}).then(resp => {
|
||||
id = resp.data.id;
|
||||
// doc https://docs.joinmastodon.org/methods/statuses/
|
||||
|
||||
console.log('media id ', resp.data.id)
|
||||
console.log(resp.data)
|
||||
masto.post('statuses', {
|
||||
status: status,
|
||||
media_ids: [id] ,
|
||||
account_id,
|
||||
visibility,
|
||||
language,
|
||||
sensitive
|
||||
}).then(resp=>{
|
||||
console.log('media id ', resp.data.id)
|
||||
console.log(resp.data)
|
||||
masto.post('statuses', {
|
||||
status: status,
|
||||
media_ids: [id],
|
||||
account_id,
|
||||
visibility,
|
||||
language,
|
||||
sensitive
|
||||
}).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 oldPath = file_path
|
||||
var newPath = 'assets/published/' + media_filename
|
||||
|
||||
fs.rename(oldPath, newPath, function (err) {
|
||||
if (err) throw err
|
||||
console.log('Successfully renamed - AKA moved!')
|
||||
})
|
||||
fs.rename(oldPath, newPath, function (err) {
|
||||
if (err) throw err
|
||||
console.log('Successfully renamed - AKA moved!')
|
||||
})
|
||||
|
||||
},
|
||||
err=> {
|
||||
err => {
|
||||
console.error(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
//
|
||||
// if (!file) {
|
||||
// return masto.post('statuses', {
|
||||
// status,
|
||||
// visibility,
|
||||
// });
|
||||
// }
|
||||
})
|
||||
})
|
||||
}
|
||||
//
|
||||
// if (!file) {
|
||||
// return masto.post('statuses', {
|
||||
// status,
|
||||
// visibility,
|
||||
// });
|
||||
// }
|
||||
|
||||
// const response = await masto.post('media', {
|
||||
// file: {
|
||||
// value: file,
|
||||
// options: {
|
||||
// filename: 'assets/test.png',
|
||||
// contentType: 'image/png',
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
//
|
||||
// return masto.post('statuses', {
|
||||
// status,
|
||||
// visibility,
|
||||
// media_ids: [response.data.id],
|
||||
// });
|
||||
// const response = await masto.post('media', {
|
||||
// file: {
|
||||
// value: file,
|
||||
// options: {
|
||||
// filename: 'assets/test.png',
|
||||
// contentType: 'image/png',
|
||||
// },
|
||||
// },
|
||||
// });
|
||||
//
|
||||
// return masto.post('statuses', {
|
||||
// status,
|
||||
// visibility,
|
||||
// media_ids: [response.data.id],
|
||||
// });
|
||||
|
||||
// })
|
||||
// })
|
||||
|
||||
res.render('index', {});
|
||||
//
|
||||
|
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user