perf: 使用 Bytes 存放 md5

This commit is contained in:
Clansty 2022-03-02 19:40:51 +08:00
parent 1727c39603
commit c44e1be231
No known key found for this signature in database
GPG Key ID: 05F8479BA63A8E92
3 changed files with 8 additions and 3 deletions

View File

@ -83,5 +83,5 @@ model AvatarCache {
id Int @id @default(autoincrement())
forwardPair ForwardPair @relation(fields: [forwardPairId], references: [id])
forwardPairId Int @unique
hash String
hash Bytes
}

View File

@ -9,7 +9,7 @@ import db from '../providers/db';
import { Api, utils } from 'telegram';
import commands from '../constants/commands';
import OicqClient from '../client/OicqClient';
import { md5B64 } from '../utils/hashing';
import { md5 } from '../utils/hashing';
import TelegramChat from '../client/TelegramChat';
import forwardPairs from '../providers/forwardPairs';
@ -174,7 +174,7 @@ export default class ConfigService {
// 更新头像
status && await status.edit({ text: '正在更新头像…' });
const avatar = await getAvatar(roomId);
const avatarHash = md5B64(avatar);
const avatarHash = md5(avatar);
await chatForBot.setProfilePhoto(avatar);
await db.avatarCache.create({
data: { forwardPairId: dbPair.id, hash: avatarHash },

View File

@ -1,5 +1,10 @@
import crypto from 'crypto';
export function md5(input: crypto.BinaryLike) {
const hash = crypto.createHash('md5');
return hash.update(input).digest();
}
export function md5Hex(input: crypto.BinaryLike) {
const hash = crypto.createHash('md5');
return hash.update(input).digest('hex');