refactor(utils): consolidate uppercase hex into toHexUpper
Adds toHexUpper alongside toHex in utils/hex.ts. Routes group-file's bytesToHexUpper through it so the incoming msg-push split can share one implementation.
This commit is contained in:
2 files changed
+12
-1
No files matched your search
@@ -27,6 +27,7 @@ import {
|
|||||||
NTV2RichMediaRespSchema,
|
NTV2RichMediaRespSchema,
|
||||||
} from '../proto/oidb-action';
|
} from '../proto/oidb-action';
|
||||||
import { FileUploadExtSchema } from '../proto/highway';
|
import { FileUploadExtSchema } from '../proto/highway';
|
||||||
|
import { toHexUpper } from '../../utils/hex';
|
||||||
import { ensureRetCodeZero, resolveSelfUid, toInt, type MediaIndexNode } from './shared';
|
import { ensureRetCodeZero, resolveSelfUid, toInt, type MediaIndexNode } from './shared';
|
||||||
|
|
||||||
// ─────────────── public result types ───────────────
|
// ─────────────── public result types ───────────────
|
||||||
@@ -76,7 +77,7 @@ function normalizeDirectory(dir?: string): string {
|
|||||||
|
|
||||||
function bytesToHexUpper(data: unknown): string {
|
function bytesToHexUpper(data: unknown): string {
|
||||||
if (!(data instanceof Uint8Array) || data.length === 0) return '';
|
if (!(data instanceof Uint8Array) || data.length === 0) return '';
|
||||||
return Buffer.from(data).toString('hex').toUpperCase();
|
return toHexUpper(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeUploadFileName(name: string, fallback: string): string {
|
function normalizeUploadFileName(name: string, fallback: string): string {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const HEX_CHARS = '0123456789abcdef';
|
const HEX_CHARS = '0123456789abcdef';
|
||||||
|
const HEX_CHARS_UPPER = '0123456789ABCDEF';
|
||||||
|
|
||||||
export function toHex(data: Uint8Array | Buffer): string {
|
export function toHex(data: Uint8Array | Buffer): string {
|
||||||
let h = '';
|
let h = '';
|
||||||
@@ -9,6 +10,15 @@ export function toHex(data: Uint8Array | Buffer): string {
|
|||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function toHexUpper(data: Uint8Array | Buffer): string {
|
||||||
|
let h = '';
|
||||||
|
for (const b of data) {
|
||||||
|
h += HEX_CHARS_UPPER[b >> 4];
|
||||||
|
h += HEX_CHARS_UPPER[b & 0xf];
|
||||||
|
}
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
export function hexPreview(data: Uint8Array | Buffer, maxBytes = 64): string {
|
export function hexPreview(data: Uint8Array | Buffer, maxBytes = 64): string {
|
||||||
const limit = Math.max(0, Math.min(maxBytes, data.length));
|
const limit = Math.max(0, Math.min(maxBytes, data.length));
|
||||||
const head = toHex(data.subarray(0, limit));
|
const head = toHex(data.subarray(0, limit));
|
||||||
|
|||||||
Reference in new issue
Block a user