小雅对id进行base58

This commit is contained in:
mtvpls
2026-01-11 22:05:32 +08:00
parent b6026199e3
commit 30278b3ac1
5 changed files with 99 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any,no-console */
import he from 'he';
import Hls from 'hls.js';
import bs58 from 'bs58';
function getDoubanImageProxyConfig(): {
proxyType:
@@ -330,3 +331,43 @@ export function cleanHtmlTags(text: string): string {
// 使用 he 库解码 HTML 实体
return he.decode(cleanedText);
}
/**
* 将字符串编码为 Base58
* @param str 要编码的字符串
* @returns Base58 编码后的字符串
*/
export function base58Encode(str: string): string {
if (!str) return '';
// 在浏览器环境中使用 TextEncoder
if (typeof window !== 'undefined') {
const encoder = new TextEncoder();
const bytes = encoder.encode(str);
return bs58.encode(bytes);
}
// 在 Node.js 环境中使用 Buffer
const buffer = Buffer.from(str, 'utf-8');
return bs58.encode(buffer);
}
/**
* 将 Base58 字符串解码为原始字符串
* @param encoded Base58 编码的字符串
* @returns 解码后的原始字符串
*/
export function base58Decode(encoded: string): string {
if (!encoded) return '';
const bytes = bs58.decode(encoded);
// 在浏览器环境中使用 TextDecoder
if (typeof window !== 'undefined') {
const decoder = new TextDecoder();
return decoder.decode(bytes);
}
// 在 Node.js 环境中使用 Buffer
return Buffer.from(bytes).toString('utf-8');
}