Rename tek to parole
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
'use strict';
|
||||
|
||||
const slugify = require('slugify')
|
||||
const axios = require('axios')
|
||||
|
||||
const TELEGRAM_API_URL = 'https://api.telegram.org'
|
||||
const TELEGRAM_CHAN_ID = process.env.TELEGRAM_CHAN_ID || null
|
||||
const TELEGRAM_API_TOKEN = process.env.TELEGRAM_API_TOKEN || null
|
||||
const MESSAGE_URL = `${TELEGRAM_API_URL}/bot${TELEGRAM_API_TOKEN}/sendMessage?chat_id=${TELEGRAM_CHAN_ID}&parse_mode=html`
|
||||
|
||||
const jwennAwtisEpiId = async data => {
|
||||
const artiste = await strapi.query('artiste').find({id: data})
|
||||
return artiste.map(a => a.alias).join('-')
|
||||
}
|
||||
|
||||
const jwennUserEpiId = async userId => {
|
||||
if (!userId) {
|
||||
return null
|
||||
}
|
||||
|
||||
const user = await strapi.query('user', 'users-permissions').findOne({id: userId})
|
||||
return user
|
||||
}
|
||||
|
||||
const jwennUserAdminEpiId = async userAdminId => {
|
||||
if (!userAdminId) {
|
||||
return null
|
||||
}
|
||||
|
||||
const user = await strapi.query('user', 'admin').findOne({id: userAdminId, 'roles.code_nin': 'strapi-super-admin'})
|
||||
return user
|
||||
}
|
||||
|
||||
const translateTeks = async teksFR => {
|
||||
const english = await strapi.services.translator.translate('FR', 'EN', teksFR)
|
||||
const espagnol = await strapi.services.translator.translate('FR', 'ES', teksFR)
|
||||
const deutsch = await strapi.services.translator.translate('FR', 'DE', teksFR)
|
||||
const italiano = await strapi.services.translator.translate('FR', 'IT', teksFR)
|
||||
|
||||
return {
|
||||
francais: teksFR,
|
||||
english: english + '\n\n (Translated by DeepL)',
|
||||
espagnol: espagnol + '\n\n (Traducido por DeepL)',
|
||||
deutsch: deutsch + '\n\n (Übersetzt von DeepL)',
|
||||
italiano: italiano + '\n\n (Tradotto da DeepL)'
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
beforeCreate: async event => {
|
||||
let {data} = event
|
||||
const user = await jwennUserEpiId(data?.user?.id)
|
||||
const userAdmin = await jwennUserAdminEpiId(data?.created_by)
|
||||
|
||||
if (userAdmin) {
|
||||
data.userAdmin = userAdmin.username
|
||||
}
|
||||
|
||||
if (data.tit && !data.forceSlug) {
|
||||
const artiste = await jwennAwtisEpiId(data.artiste)
|
||||
data.slug = slugify(`${artiste}-${data.tit}`, {lower: true, remove: /[*#+~.()'"!:@]/g})
|
||||
}
|
||||
|
||||
if (user && user.canAutoTranslate && data.tradiksyonOtomatik && data.tradiksyon.francais && (!data.tradiksyon.english || !data.tradiksyon.espagnol || !data.tradiksyon.deutsch || !data.tradiksyon.italiano)) {
|
||||
const traslate = await translateTeks(data.tradiksyon.francais)
|
||||
data.tradiksyon = traslate
|
||||
}
|
||||
|
||||
},
|
||||
beforeUpdate: async event => {
|
||||
let {data} = event
|
||||
|
||||
if (data.tit && !data.forceSlug) {
|
||||
const artiste = await jwennAwtisEpiId(data.artiste)
|
||||
data.slug = slugify(`${artiste}-${data.tit}`, {lower: true, remove: /[*#+~.()'"!:@]/g})
|
||||
}
|
||||
if (data.published_at != null) {
|
||||
const {id} = params
|
||||
const previousData = await strapi.query('paroles').findOne({id})
|
||||
|
||||
const previousPublishedAt = previousData.published_at
|
||||
const currentPublished_at = data.published_at
|
||||
if (currentPublished_at != previousPublishedAt) {
|
||||
const message = `<b>Nouvelle publication</b> \xF0\x9F\x8E\xB6 \xF0\x9F\x94\xA5
|
||||
\n${process.env.WEBSITE_URL}/paroles/${previousData.slug}`
|
||||
if (previousData.user) {
|
||||
strapi.services.email.send(
|
||||
process.env.SMTP_FROM,
|
||||
previousData.user.email,
|
||||
`Publication de "${previousData.tit}"`,
|
||||
`Le titre que vous avez soumis, "${previousData.tit}" a été publié sur le site. Vous pouvez le trouver à l'adresse ${process.env.WEBSITE_URL}/paroles/${previousData.slug}`
|
||||
)
|
||||
}
|
||||
|
||||
const user = await jwennUserAdminEpiId(previousData?.created_by?.id)
|
||||
|
||||
if (user) {
|
||||
strapi.services.email.send(
|
||||
process.env.SMTP_FROM,
|
||||
user.email,
|
||||
`Publication de "${previousData.tit}"`,
|
||||
`Le titre que vous avez soumis, "${previousData.tit}" a été publié sur le site. Vous pouvez le trouver à l'adresse ${process.env.WEBSITE_URL}/paroles/${previousData.slug}`
|
||||
)
|
||||
}
|
||||
|
||||
await axios.post(`${MESSAGE_URL}&text=${message}`)
|
||||
}
|
||||
}
|
||||
},
|
||||
afterCreate: async event => {
|
||||
let {data} = event
|
||||
|
||||
if (data.user) {
|
||||
strapi.services.email.send(
|
||||
process.env.SMTP_FROM,
|
||||
process.env.SMTP_SEND_TO,
|
||||
`Nouveau texte de ${data.user.username} : "${data.tit}" (site)`,
|
||||
`Le titre "${data.tit}" a été soumis depuis le site.`
|
||||
)
|
||||
}
|
||||
|
||||
const user = await jwennUserAdminEpiId(data?.created_by?.id)
|
||||
|
||||
if (user) {
|
||||
strapi.services.email.send(
|
||||
process.env.SMTP_FROM,
|
||||
process.env.SMTP_SEND_TO,
|
||||
`Nouveau texte de ${user.username} : "${data.tit}" (dashboard)`,
|
||||
`Le titre "${data.tit}" a été soumis depuis le dashboard.`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
{
|
||||
"kind": "collectionType",
|
||||
"collectionName": "paroles",
|
||||
"info": {
|
||||
"singularName": "parole",
|
||||
"pluralName": "paroles",
|
||||
"displayName": "Paroles",
|
||||
"description": ""
|
||||
},
|
||||
"options": {
|
||||
"draftAndPublish": true
|
||||
},
|
||||
"pluginOptions": {},
|
||||
"attributes": {
|
||||
"tit": {
|
||||
"type": "string",
|
||||
"required": true
|
||||
},
|
||||
"transkripsyon": {
|
||||
"type": "richtext",
|
||||
"required": true
|
||||
},
|
||||
"lanne": {
|
||||
"type": "integer"
|
||||
},
|
||||
"slug": {
|
||||
"type": "string"
|
||||
},
|
||||
"okiMizikID": {
|
||||
"type": "integer"
|
||||
},
|
||||
"eksplisit": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"forceSlug": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"tradiksyonOtomatik": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"artistes": {
|
||||
"type": "relation",
|
||||
"relation": "manyToMany",
|
||||
"target": "api::parole.parole",
|
||||
"mappedBy": "paroles"
|
||||
},
|
||||
"admin_user": {
|
||||
"type": "relation",
|
||||
"relation": "oneToOne",
|
||||
"target": "admin::user"
|
||||
},
|
||||
"user": {
|
||||
"type": "relation",
|
||||
"relation": "oneToOne",
|
||||
"target": "plugin::users-permissions.user"
|
||||
},
|
||||
"kouveti": {
|
||||
"type": "media",
|
||||
"multiple": false,
|
||||
"required": false,
|
||||
"allowedTypes": [
|
||||
"images"
|
||||
]
|
||||
},
|
||||
"tradiksyon": {
|
||||
"type": "component",
|
||||
"repeatable": false,
|
||||
"component": "trad.traductions"
|
||||
},
|
||||
"lyen": {
|
||||
"type": "component",
|
||||
"repeatable": true,
|
||||
"component": "url.liens"
|
||||
},
|
||||
"kouteyAchtey": {
|
||||
"type": "component",
|
||||
"repeatable": true,
|
||||
"component": "store.album"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { createCoreController } = require('@strapi/strapi').factories;
|
||||
|
||||
module.exports = createCoreController('api::parole.parole')
|
||||
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { createCoreRouter } = require('@strapi/strapi').factories;
|
||||
|
||||
module.exports = createCoreRouter('api::parole.parole')
|
||||
@@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const { createCoreService } = require('@strapi/strapi').factories;
|
||||
|
||||
module.exports = createCoreService('api::parole.parole');
|
||||
Reference in New Issue
Block a user