代码 Mail.mjs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 import nodemailer from "nodemailer" ;export default async function sendMail (to, title, msg ) { const transporter = nodemailer.createTransport ({ host : "smtp.qq.com" , auth : { user : "[email protected] " , pass : process.env .QQMAIL_SMTP_TOKEN } }); const mailInfo = { from : "[email protected] " , to : to, subject : title, text : "仓库容量邮件通知" , html : msg, }; const ret = await transporter.sendMail (mailInfo); console .log ("send mail finish to " + to); return ret; }
测试 Checkrepo.mjs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 import fetch from 'node-fetch' ;import sendMail from "./mail.mjs" const args = process.argv .slice (2 )console .log (args[1 ] + " repo size:" );fetch ('https://api.github.com/repos/' + args[0 ] + '/' + args[1 ]) .then (v => v.json ()).then (async (v) => { const msize = (v['size' ] / 1024 ).toFixed (2 ) const gsize = (v['size' ] / 1024 / 1024 ).toFixed (2 ) console .log (msize + 'MB' ); console .log (gsize + 'GB' ); const repoName = args[0 ] + '/' + args[1 ] const to = "[email protected] " ; const title = "仓库【" + repoName + "】容量邮件通知邮件✔" ; const msg = "您的仓库【" + repoName + "】目前容量大小为请留意!" ; console .log ("check token is=>" + process.env .QQMAIL_SMTP_TOKEN ); const ret = await sendMail (to, title, msg); console .log ("finish." + ret.response ); }) .catch (err => console .log (err));
运行 1 node checkrepo.mjs terwer upload
效果
图片处理 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 import fetch from 'node-fetch' ;export default function handler (req, res ) { const imagePath = req.query .slug .join ("/" ); let host = req.headers .host ; if (host.indexOf ("localhost" ) > -1 ) { host = "http://localhost:3000" ; } else { host = "https://img1.terwergreen.com" ; } const fileUrl = `${host} /${imagePath} ` ; console .log ("fileUrl=>" , fileUrl) fetch (fileUrl).then (async (v) => { if (v.status == 200 ) { const absUrl = '/' + imagePath; console .log ("absUrl=>" , absUrl) res.redirect (307 , '/' + imagePath).end () } else { const newUrl = 'https://ghproxy.com/https://raw.githubusercontent.com/terwer/upload/main/public/' + imagePath console .log ("newUrl=>" , newUrl) res.redirect (307 , newUrl).end () } }).catch (err => { console .log (err) res.end ("500" ) }); }
测试图片 未同步的时候 https://img1.terwergreen.com/api/public/20220707191555.png
已经同步的 https://img1.terwergreen.com/api/public/20220706194731.png