37 lines
962 B
JavaScript
37 lines
962 B
JavaScript
'use strict';
|
|
|
|
const bokanteMastodon = require('./bokante-mastodon');
|
|
|
|
async function backfillBokanteMirror({strapi}) {
|
|
const [parole] = await strapi.db.query('api::parole.parole').findMany({
|
|
where: {
|
|
publishedAt: {$notNull: true},
|
|
bokanteStatusId: {$null: true}
|
|
},
|
|
orderBy: {publishedAt: 'asc'},
|
|
limit: 1
|
|
});
|
|
|
|
if (!parole) {
|
|
return {backfilled: false};
|
|
}
|
|
|
|
try {
|
|
const status = await bokanteMastodon.createStatus(
|
|
`"${parole.titre}" — à (re)découvrir sur pawol.nu\n${process.env.WEBSITE_URL}/paroles/${parole.slug}`
|
|
);
|
|
|
|
await strapi.db.query('api::parole.parole').updateMany({
|
|
where: {documentId: parole.documentId},
|
|
data: {bokanteStatusId: status.id}
|
|
});
|
|
|
|
return {backfilled: true, slug: parole.slug};
|
|
} catch (err) {
|
|
strapi.log.error(`Backfill bokante (${parole.slug}) : ${err.message}`);
|
|
return {backfilled: false};
|
|
}
|
|
}
|
|
|
|
module.exports = {backfillBokanteMirror};
|