From 0e17ab9c6f7b1513692c44ac15e03f93f0ee7cc2 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Wed, 14 Dec 2022 16:47:57 +0100 Subject: [PATCH] improve image capture --- helpers/cipherbliss_post.mjs | 11 ++++++----- helpers/qzine_article.mjs | 8 +------- helpers/tykayn_blog.mjs | 2 +- helpers/utils.mjs | 9 +++------ 4 files changed, 11 insertions(+), 19 deletions(-) diff --git a/helpers/cipherbliss_post.mjs b/helpers/cipherbliss_post.mjs index fb7990a..8923576 100644 --- a/helpers/cipherbliss_post.mjs +++ b/helpers/cipherbliss_post.mjs @@ -1,6 +1,11 @@ import fs from "fs"; import path from 'path'; -import sendPostMastodon, {randomIntFromInterval, findFirstImageInContent, findPictureAndSendPost} from './utils.mjs' +import sendPostMastodon, { + randomIntFromInterval, + findFirstImageInContent, + findPictureAndSendPost, + getRandomElementOfArray +} from './utils.mjs' const __dirname = path.resolve(); const tkpostsjson = JSON.parse(fs.readFileSync(__dirname + "/assets/documents/cipherbliss_tkwp_posts.json", 'utf-8')) @@ -8,10 +13,6 @@ let reallySendPost = false; // reallySendPost = true; -export function getRandomElementOfArray(listItems) { - return listItems[Math.floor(Math.random() * listItems.length)] -} - function getRandomLink() { let filteredLinks = tkpostsjson.filter(elem => elem.post_status === 'publish') diff --git a/helpers/qzine_article.mjs b/helpers/qzine_article.mjs index 009c6c4..4a4d8a1 100644 --- a/helpers/qzine_article.mjs +++ b/helpers/qzine_article.mjs @@ -2,8 +2,7 @@ import fs from "fs"; import path from 'path'; import sendPostMastodon, { randomIntFromInterval, - findFirstImageInContent, - downloadImage, + getRandomElementOfArray, findPictureAndSendPost } from './utils.mjs' @@ -27,11 +26,6 @@ let reallySendPost = false; // reallySendPost = true; -export function getRandomElementOfArray(listItems) { - return listItems[Math.floor(Math.random() * listItems.length)] -} - - function getRandomLinkQzine() { let filteredLinks = list_posts_json.filter(elem => elem.status === 'publish') return getRandomElementOfArray(filteredLinks) diff --git a/helpers/tykayn_blog.mjs b/helpers/tykayn_blog.mjs index 56216e3..4bdba83 100644 --- a/helpers/tykayn_blog.mjs +++ b/helpers/tykayn_blog.mjs @@ -3,6 +3,7 @@ import path from 'path'; import { randomIntFromInterval, findPictureAndSendPost, getRandomLinkGeneral + } from './utils.mjs' import Masto from "mastodon"; @@ -15,7 +16,6 @@ let reallySendPost = false; // reallySendPost = true; - function postLink() { let postObject = getRandomLinkGeneral(tkpostsjson) diff --git a/helpers/utils.mjs b/helpers/utils.mjs index de5f6cc..eeedb39 100644 --- a/helpers/utils.mjs +++ b/helpers/utils.mjs @@ -105,9 +105,9 @@ export default function sendPostMastodon(config) { /** * envoi avec fichier, * on doit d'abord faire un upload du fichier, - * puis relier son id de media au nouveau post. + * puis relier son id de média au nouveau post. */ - if (config.image) { + else if (config.image) { var id; console.log("envoi du média", config.image) @@ -223,6 +223,7 @@ function clearLink(linkString){ linkString = linkString.replace('http:', 'https:') linkString = linkString.replace('https://www.ailesse.info/~tykayn/bazar/kotlife', 'https://www.tykayn.fr/wp-content/uploads/i/kotlife') linkString = linkString.replace('https://blog.artlemoine.com/public/i', 'https://www.tykayn.fr/wp-content/uploads/i') + linkString = linkString.replace('https://www.ailesse.com/%7Etykayn/bazar', 'https://www.tykayn.fr/wp-content/uploads/i/bazar') return linkString } @@ -284,10 +285,6 @@ export function getRandomLinkGeneral(tkpostsjson) { return getRandomElementOfArray(filteredLinks) } -export function getRandomElementOfArray(listItems) { - return listItems[Math.floor(Math.random() * listItems.length)] -} - /** * trouver l'image du contenu si il y en a