feat: add COS integration for uploading generated invoices to cloud storage

This commit is contained in:
Astrian Zheng 2025-01-12 11:27:43 +11:00
parent 64578233f0
commit 1db3122579
Signed by: Astrian
SSH Key Fingerprint: SHA256:rVnhx3DAKjujCwWE13aDl7uV6+9U1MvydLkNRXJrBiA
3 changed files with 763 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -26,6 +26,7 @@
"description": "",
"dependencies": {
"@prisma/client": "^6.2.1",
"cos-nodejs-sdk-v5": "^2.14.6",
"dayjs": "^1.11.13",
"debug": "^4.4.0",
"decimal.js": "^10.4.3",

View File

@ -9,6 +9,7 @@ import handlebars from 'handlebars'
import puppeteer from 'puppeteer'
import nodemailer from 'nodemailer'
import marked from 'marked'
import COS from 'cos-nodejs-sdk-v5'
console.log = Debug('invoiceIssuer:func/issueInvoice.ts')
@ -153,4 +154,16 @@ export default async (prisma: PrismaClient, payerId: number, period: Date[], ite
]
}
await transporter.sendMail(mailOptions)
// 上传到 COS
const cos = new COS({
SecretId: process.env.COS_USER,
SecretKey: process.env.COS_PASS
})
await cos.putObject({
Bucket: process.env.COS_BUCKET || '',
Region: process.env.COS_REGION || '',
Key: `${invoiceNumber}.pdf`,
Body: invoiceBuffer
})
}