refactor: separate notification distribution from field mapping
This commit is contained in:
1 parent
3748d05d96
commit
c53da6f025
25 files changed
+773
-118
No files matched your search
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
const path=require('node:path');
|
||||
const {escape}=require('../mail/parser.cjs');
|
||||
const lines=value=>escape(value).replace(/\r?\n/g,'<br>');
|
||||
function fileLink(filePath){
|
||||
if(filePath.startsWith('\\\\'))return 'file://'+filePath.slice(2).split('\\').map(encodeURIComponent).join('/');
|
||||
if(/^[a-z]:[\\/]/i.test(filePath))return 'file:///'+filePath.replace(/\\/g,'/').split('/').map((p,i)=>i===0?p:encodeURIComponent(p)).join('/');
|
||||
return 'file://'+filePath.split('/').map(encodeURIComponent).join('/');
|
||||
}
|
||||
// Content is derived from the event and its recorded archive, never current configuration.
|
||||
function mailContent(orders){
|
||||
const details=orders.map(order=>order.event.titleOrders?.length&&order.event.titleOrders.every(row=>typeof row.text==='string'&&row.text.trim())?order.event.titleOrders.map(row=>row.text).join('\n\n'):String(order.event.brief||'')).join('\n\n');
|
||||
const seen=new Set(),directories=[];
|
||||
for(const order of orders)for(const file of order.archive.files){
|
||||
const windows=path.win32.isAbsolute(file.path),directory=(windows?path.win32:path.posix).dirname(file.path),key=windows?directory.toLowerCase():directory;
|
||||
if(!seen.has(key)){seen.add(key);directories.push(directory);}
|
||||
}
|
||||
return {details,directories,htmlDetails:'<div style="color:#0000ff">'+lines(details)+'</div>',htmlDirectories:'<div>存放地址:<br>'+directories.map(directory=>'<a style="color:#0000ff" href="'+escape(fileLink(directory))+'">'+escape(directory)+'</a>').join('<br>')+'</div>'};
|
||||
}
|
||||
module.exports={mailContent,fileLink};
|
||||
Reference in new issue
Block a user