mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:10:43 +00:00
refactor: reuse media base64 helper in qqbot
This commit is contained in:
@@ -1,41 +1,9 @@
|
||||
import { estimateBase64DecodedBytes } from "openclaw/plugin-sdk/media-runtime";
|
||||
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
|
||||
import type { RefAttachmentSummary } from "../ref-index-store.js";
|
||||
|
||||
const MAX_FACE_EXT_BYTES = 64 * 1024;
|
||||
|
||||
function estimateBase64DecodedBytes(base64: string): number {
|
||||
let effectiveLen = 0;
|
||||
for (let i = 0; i < base64.length; i += 1) {
|
||||
if (base64.charCodeAt(i) > 0x20) {
|
||||
effectiveLen += 1;
|
||||
}
|
||||
}
|
||||
if (effectiveLen === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let padding = 0;
|
||||
let end = base64.length - 1;
|
||||
while (end >= 0 && base64.charCodeAt(end) <= 0x20) {
|
||||
end -= 1;
|
||||
}
|
||||
if (end >= 0 && base64[end] === "=") {
|
||||
padding = 1;
|
||||
end -= 1;
|
||||
while (end >= 0 && base64.charCodeAt(end) <= 0x20) {
|
||||
end -= 1;
|
||||
}
|
||||
if (end >= 0 && base64[end] === "=") {
|
||||
padding = 2;
|
||||
}
|
||||
}
|
||||
|
||||
return Math.max(0, Math.floor((effectiveLen * 3) / 4) - padding);
|
||||
}
|
||||
|
||||
function normalizeLowercaseStringOrEmpty(value: unknown): string {
|
||||
return typeof value === "string" ? value.trim().toLowerCase() : "";
|
||||
}
|
||||
|
||||
/** Replace QQ face tags with readable text labels. */
|
||||
export function parseFaceTags(text: string | undefined | null): string {
|
||||
if (!text) {
|
||||
|
||||
Reference in New Issue
Block a user