新增自定义显示TG邮件消息内容
This commit is contained in:
@@ -6,3 +6,4 @@ app.get('/telegram/getEmail/:token', async (c) => {
|
||||
c.header('Cache-Control', 'public, max-age=604800, immutable');
|
||||
return c.html(content)
|
||||
});
|
||||
|
||||
|
||||
@@ -42,6 +42,8 @@ export const setting = sqliteTable('setting', {
|
||||
s3SecretKey: text('s3_secret_key').default('').notNull(),
|
||||
kvStorage: integer('kv_storage').default(1).notNull(),
|
||||
forcePathStyle: integer('force_path_style').default(1).notNull(),
|
||||
customDomain: text('custom_domain').default('').notNull()
|
||||
customDomain: text('custom_domain').default('').notNull(),
|
||||
tgMsgFrom: text('tg_msg_from').default('only-name').notNull(),
|
||||
tgMsgTo: text('tg_msg_to').default('show').notNull()
|
||||
});
|
||||
export default setting
|
||||
|
||||
@@ -32,7 +32,9 @@ const init = {
|
||||
await c.env.db.batch([
|
||||
c.env.db.prepare(`ALTER TABLE setting ADD COLUMN force_path_style INTEGER NOT NULL DEFAULT 1;`),
|
||||
c.env.db.prepare(`ALTER TABLE setting ADD COLUMN kv_storage INTEGER NOT NULL DEFAULT 1;`),
|
||||
c.env.db.prepare(`ALTER TABLE setting ADD COLUMN custom_domain TEXT NOT NULL DEFAULT '';`)
|
||||
c.env.db.prepare(`ALTER TABLE setting ADD COLUMN custom_domain TEXT NOT NULL DEFAULT '';`),
|
||||
c.env.db.prepare(`ALTER TABLE setting ADD COLUMN tg_msg_to TEXT NOT NULL DEFAULT 'show';`),
|
||||
c.env.db.prepare(`ALTER TABLE setting ADD COLUMN tg_msg_from TEXT NOT NULL DEFAULT 'only-name';`)
|
||||
]);
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
|
||||
@@ -15,26 +15,6 @@ import verifyUtils from '../utils/verify-utils';
|
||||
|
||||
const telegramService = {
|
||||
|
||||
async getEmailById(c, params) {
|
||||
|
||||
const { emailId } = params
|
||||
|
||||
const emailRow = await orm(c).select().from(email).where(eq(email.emailId, emailId)).get();
|
||||
|
||||
if (emailRow) {
|
||||
|
||||
if (emailRow.content) {
|
||||
return emailHtmlTemplate(emailRow.content || '')
|
||||
} else {
|
||||
return emailTextTemplate(emailRow.text || '')
|
||||
}
|
||||
|
||||
} else {
|
||||
return emailTextTemplate('The email does not exist')
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
async getEmailContent(c, params) {
|
||||
|
||||
const { token } = params
|
||||
@@ -50,7 +30,8 @@ const telegramService = {
|
||||
if (emailRow) {
|
||||
|
||||
if (emailRow.content) {
|
||||
return emailHtmlTemplate(emailRow.content || '')
|
||||
const { r2Domain } = await settingService.query(c);
|
||||
return emailHtmlTemplate(emailRow.content || '', r2Domain)
|
||||
} else {
|
||||
return emailTextTemplate(emailRow.text || '')
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { parseHTML } from 'linkedom';
|
||||
import domainUtils from '../utils/domain-uitls';
|
||||
|
||||
export default function emailHtmlTemplate(html) {
|
||||
export default function emailHtmlTemplate(html, domain) {
|
||||
|
||||
const { document } = parseHTML(html);
|
||||
document.querySelectorAll('script').forEach(script => script.remove());
|
||||
html = document.documentElement.outerHTML;
|
||||
html = html.replace(/{{domain}}/g, domainUtils.toOssDomain(domain) + '/');
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
<html lang='en' >
|
||||
@@ -105,6 +107,7 @@ export default function emailHtmlTemplate(html) {
|
||||
}
|
||||
|
||||
function autoScale(shadowRoot, container) {
|
||||
|
||||
if (!shadowRoot || !container) return;
|
||||
|
||||
const parent = container;
|
||||
@@ -113,16 +116,11 @@ export default function emailHtmlTemplate(html) {
|
||||
if (!shadowContent) return;
|
||||
|
||||
const parentWidth = parent.offsetWidth;
|
||||
const parentHeight = parent.offsetHeight;
|
||||
|
||||
const childWidth = shadowContent.scrollWidth;
|
||||
const childHeight = shadowContent.scrollHeight;
|
||||
|
||||
if (childWidth === 0 || childHeight === 0) return;
|
||||
if (childWidth === 0) return;
|
||||
|
||||
const scaleX = parentWidth / childWidth;
|
||||
const scaleY = parentHeight / childHeight;
|
||||
const scale = Math.min(scaleX, scaleY);
|
||||
const scale = parentWidth / childWidth;
|
||||
|
||||
const hostElement = shadowRoot.host;
|
||||
hostElement.style.zoom = scale;
|
||||
|
||||
@@ -1,7 +1,31 @@
|
||||
export default function emailMsgTemplate(email) {
|
||||
return `<b>${email.subject}</b>
|
||||
export default function emailMsgTemplate(email, tgMsgTo, tgMsgFrom) {
|
||||
|
||||
let template = `<b>${email.subject}</b>`
|
||||
|
||||
if (tgMsgFrom === 'only-name') {
|
||||
template += `
|
||||
|
||||
发件人:${email.name}`
|
||||
}
|
||||
|
||||
if (tgMsgFrom === 'show') {
|
||||
template += `
|
||||
|
||||
发件人:${email.name} <${email.sendEmail}>`
|
||||
}
|
||||
|
||||
if(tgMsgTo === 'show' && tgMsgFrom === 'hide') {
|
||||
template += `
|
||||
|
||||
发件人:${email.name} <${email.sendEmail}>
|
||||
收件人:\u200B${email.toEmail}`
|
||||
return template
|
||||
}
|
||||
|
||||
if(tgMsgTo === 'show') {
|
||||
template += `
|
||||
收件人:\u200B${email.toEmail}`
|
||||
}
|
||||
|
||||
return template;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user