feat: add COS integration for uploading generated invoices to cloud storage
This commit is contained in:
parent
64578233f0
commit
1db3122579
749
backend/package-lock.json
generated
749
backend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -26,6 +26,7 @@
|
||||||
"description": "",
|
"description": "",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@prisma/client": "^6.2.1",
|
"@prisma/client": "^6.2.1",
|
||||||
|
"cos-nodejs-sdk-v5": "^2.14.6",
|
||||||
"dayjs": "^1.11.13",
|
"dayjs": "^1.11.13",
|
||||||
"debug": "^4.4.0",
|
"debug": "^4.4.0",
|
||||||
"decimal.js": "^10.4.3",
|
"decimal.js": "^10.4.3",
|
||||||
|
|
|
@ -9,6 +9,7 @@ import handlebars from 'handlebars'
|
||||||
import puppeteer from 'puppeteer'
|
import puppeteer from 'puppeteer'
|
||||||
import nodemailer from 'nodemailer'
|
import nodemailer from 'nodemailer'
|
||||||
import marked from 'marked'
|
import marked from 'marked'
|
||||||
|
import COS from 'cos-nodejs-sdk-v5'
|
||||||
|
|
||||||
console.log = Debug('invoiceIssuer:func/issueInvoice.ts')
|
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)
|
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
|
||||||
|
})
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user