Merge branch 'character' into dev

This commit is contained in:
Clément Pons
2025-07-21 18:00:00 +02:00
82 changed files with 15935 additions and 1000 deletions

View File

@@ -28,69 +28,78 @@ const transport = nodemailer.createTransport({
pool: true,
host: config.mail.host,
port: config.mail.port,
secure: true,
secure: config.mail.port === "465",
auth: {
user: config.mail.user,
pass: config.mail.passwd,
},
requireTLS: true,
tls: { rejectUnauthorized: false },
dkim: {
domainName: domain,
keySelector: selector,
privateKey: dkim,
},
proxy: config.mail.proxy,
});
export default defineTask({
meta: {
name: 'mail',
description: 'Send email',
},
async run(e) {
try {
if(e.payload.type !== 'mail')
{
throw new Error(`Données inconnues`);
}
const payload = e.payload as MailPayload;
const template = templates[payload.template];
if(!template)
{
throw new Error(`Modèle de mail ${payload.template} inconnu`);
}
console.time('Generating HTML');
const mail: Mail.Options = {
from: 'd[any] - Ne pas répondre <no-reply@peaceultime.com>',
to: payload.to,
html: await render(template.component, payload.data),
subject: template.subject,
textEncoding: 'quoted-printable',
};
console.timeEnd('Generating HTML');
if(mail.html === '')
return { result: false, error: new Error("Invalid content") };
console.time('Sending Mail');
const status = await transport.sendMail(mail);
console.timeEnd('Sending Mail');
if(status.rejected.length > 0)
{
return { result: false, error: status.response, details: status.rejectedErrors };
}
return { result: true };
}
catch(e)
if(process.env.NODE_ENV === 'production')
{
transport.verify((error) => {
if(error)
{
return { result: false, error: e };
console.log('Mail server cannot be reached');
console.error(error);
}
},
})
else
console.log("Mail server is reachable and ready to communicate");
});
}
export default async function(e: TaskEvent) {
try {
if(e.payload.type !== 'mail')
{
throw new Error(`Données inconnues`);
}
const payload = e.payload as MailPayload;
const template = templates[payload.template];
if(!template)
{
throw new Error(`Modèle de mail ${payload.template} inconnu`);
}
console.time('Generating HTML');
const mail: Mail.Options = {
from: 'd[any] - Ne pas répondre <no-reply@peaceultime.com>',
to: payload.to,
html: await render(template.component, payload.data),
subject: template.subject,
textEncoding: 'quoted-printable',
};
console.timeEnd('Generating HTML');
if(mail.html === '')
return { result: false, error: new Error("Invalid content") };
console.time('Sending Mail');
const status = await transport.sendMail(mail);
console.timeEnd('Sending Mail');
if(status.rejected.length > 0)
{
return { result: false, error: status.response, details: status.rejectedErrors };
}
return { result: true };
}
catch(e)
{
console.error(e);
return { result: false, error: e };
}
}
async function render(component: any, data: Record<string, any>): Promise<string>
{

View File

@@ -34,12 +34,11 @@ export default defineTask({
{
const title = basename(e.path);
const order = /(\d+)\. ?(.+)/gsmi.exec(title);
const path = (e.path as string).split('/').map(f => { const check = /(\d+)\. ?(.+)/gsmi.exec(f); return check && check[2] ? check[2] : f }).join('/');
return {
id: getID(ID_SIZE),
path: parsePath(path),
path: parsePath(e.path),
order: i,
title: order && order[2] ? order[2] : title,
title: title,
type: 'folder',
content: null,
owner: 1,
@@ -52,14 +51,13 @@ export default defineTask({
const extension = extname(e.path);
const title = basename(e.path, extension);
const order = /(\d+)\. ?(.+)/gsmi.exec(title);
const path = (e.path as string).split('/').map(f => { const check = /(\d+)\. ?(.+)/gsmi.exec(f); return check && check[2] ? check[2] : f }).join('/');
const content = (await $fetch(`https://git.peaceultime.com/api/v1/repos/peaceultime/system-aspect/raw/${encodeURIComponent(e.path)}`));
return {
id: getID(ID_SIZE),
path: parsePath(extension === '.md' ? path.replace(extension, '') : path),
path: parsePath(extension === '.md' ? e.path.replace(extension, '') : e.path),
order: i,
title: order && order[2] ? order[2] : title,
title: title,
type: (typeMapping[extension] ?? 'file'),
content: reshapeContent(content as string, typeMapping[extension] ?? 'File'),
owner: 1,
@@ -107,8 +105,8 @@ function reshapeContent(content: string, type: FileType): string | null
return content;
case "canvas":
const data = JSON.parse(content) as CanvasContent;
data.edges?.forEach(e => e.color = typeof e.color === 'string' ? getColor(e.color) : undefined);
data.nodes?.forEach(e => e.color = typeof e.color === 'string' ? getColor(e.color) : undefined);
data.edges?.forEach(e => { console.log(e.color); e.color = typeof e.color === 'string' ? getColor(e.color) : undefined; console.log(e.color); });
data.nodes?.forEach(e => { console.log(e.color); e.color = typeof e.color === 'string' ? getColor(e.color) : undefined; console.log(e.color); });
return JSON.stringify(data);
default:
case 'folder':

View File

@@ -14,7 +14,7 @@ export default defineTask({
name: 'validation',
description: 'Add email ID to DB',
},
async run(e) {
run(e) {
try {
if(e.payload.type !== 'validation')
{