新增支持API添加用户,查询邮件
This commit is contained in:
@@ -25,6 +25,15 @@ const saltHashUtils = {
|
||||
async verifyPassword(inputPassword, salt, storedHash) {
|
||||
const hash = await this.genHashPassword(inputPassword, salt);
|
||||
return hash === storedHash;
|
||||
},
|
||||
|
||||
genRandomPwd(length = 8) {
|
||||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
||||
let result = '';
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += chars.charAt(Math.floor(Math.random() * chars.length));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
const ipUtils = {
|
||||
getIp(c) {
|
||||
return c.req.header('CF-Connecting-IP') ||
|
||||
c.req.header('X-Forwarded-For') ||
|
||||
'Unknown';
|
||||
}
|
||||
}
|
||||
|
||||
export default ipUtils
|
||||
45
mail-worker/src/utils/req-utils.js
Normal file
45
mail-worker/src/utils/req-utils.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import { UAParser } from 'ua-parser-js';
|
||||
const reqUtils = {
|
||||
getIp(c) {
|
||||
return c.req.header('CF-Connecting-IP') ||
|
||||
c.req.header('X-Forwarded-For') ||
|
||||
'Unknown';
|
||||
},
|
||||
|
||||
getUserAgent(c) {
|
||||
const ua = c.req.header('user-agent') || '';
|
||||
|
||||
const parser = new UAParser(ua);
|
||||
const { browser, device, os } = parser.getResult();
|
||||
|
||||
let browserInfo = null;
|
||||
let osInfo = null;
|
||||
|
||||
if (browser.name) {
|
||||
browserInfo = browser.name + ' ' + browser.version;
|
||||
}
|
||||
|
||||
if (os.name) {
|
||||
osInfo = os.name + os.version;
|
||||
}
|
||||
|
||||
let deviceInfo = 'Desktop';
|
||||
|
||||
const hasVendor = !!device?.vendor;
|
||||
const hasModel = !!device?.model;
|
||||
|
||||
if (hasVendor || hasModel) {
|
||||
const vendor = device.vendor || '';
|
||||
const model = device.model || '';
|
||||
const type = device.type || '';
|
||||
|
||||
const namePart = [vendor, model].filter(Boolean).join(' ');
|
||||
const typePart = type ? ` (${type})` : '';
|
||||
deviceInfo = (namePart + typePart).trim();
|
||||
}
|
||||
|
||||
return {browser: browserInfo || '', device: deviceInfo || '', os: osInfo || ''}
|
||||
}
|
||||
}
|
||||
|
||||
export default reqUtils
|
||||
Reference in New Issue
Block a user