新增邮件发送和管理员功能

This commit is contained in:
eoao
2025-05-29 17:38:50 +08:00
parent de742d31e7
commit 2341d14b2d
364 changed files with 24202 additions and 1079 deletions

View File

@@ -1,3 +1,5 @@
import Compressor from "compressorjs";
export function getExtName(fileName) {
const index = fileName.lastIndexOf('.')
return index !== -1 ? fileName.slice(index + 1).toLowerCase() : ''
@@ -10,4 +12,38 @@ export function formatBytes(bytes) {
const i = Math.floor(Math.log(bytes) / Math.log(k));
const size = (bytes / Math.pow(k, i)).toFixed(2);
return `${size} ${units[i]}`;
}
}
export function fileToBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
const base64 = reader.result.split(',')[1];
resolve(base64);
};
reader.onerror = reject;
});
}
export function base64Size(base64String) {
const padding = (base64String.match(/=*$/) || [''])[0].length;
const base64Length = base64String.length;
return (base64Length * 3) / 4 - padding;
}
export function compressImage(file, quality = 0.6) {
return new Promise((resolve, reject) => {
new Compressor(file, {
quality,
mimeType: 'image/jpeg',
convertSize: 1024 * 1024,
success(result) {
resolve(result);
},
error(err) {
reject(err);
},
});
});
}