23 lines
559 B
JavaScript
23 lines
559 B
JavaScript
// 二维码生成 — 使用 qrcode 库生成 PNG 图片
|
|
|
|
const QRCode = require('qrcode');
|
|
const path = require('path');
|
|
const { saveQrCode } = require('./profile-store');
|
|
|
|
// 生成二维码并保存为 PNG 文件,返回文件名
|
|
async function generateAndSaveQrCode(profileId, bindUrl) {
|
|
const pngBuffer = await QRCode.toBuffer(bindUrl, {
|
|
type: 'png',
|
|
width: 320,
|
|
margin: 2,
|
|
color: {
|
|
dark: '#000000',
|
|
light: '#ffffff',
|
|
},
|
|
});
|
|
|
|
return saveQrCode(profileId, pngBuffer);
|
|
}
|
|
|
|
module.exports = { generateAndSaveQrCode };
|