Skip to content

Commit 72a9b8d

Browse files
claudejlobue10
authored andcommitted
Drop redundant buffer copies and a dead hook export
The verified-preview path copied every downloaded byte twice for no gain: fetchBuffer re-allocated each response chunk element-by-element via Uint8Array.from before collecting it (Electron's net module delivers fresh Buffers, so retaining them is safe and Buffer.concat already performs the single final copy), and the metadata checksum round-tripped the whole buffer through a latin1 string before hashing, which allocates an up-to-10MB string to produce the digest hashing the Buffer directly yields. Also removes the unused useNFTVideoLoop default export: both consumers import the named hooks and derive the effective global-or-per-video state themselves, so the wrapper only added surface that could drift from the real logic. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FUAhsJYiWuD36Hq4h49gLg
1 parent f68778e commit 72a9b8d

3 files changed

Lines changed: 7 additions & 13 deletions

File tree

packages/gui/src/electron/api/nftGetMetadata.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type NftMetadata = Record<string, unknown> & {
2020
};
2121

2222
function checksum(data: Buffer): string {
23-
return crypto.createHash('sha256').update(data.toString('latin1'), 'latin1').digest('hex');
23+
return crypto.createHash('sha256').update(data).digest('hex');
2424
}
2525

2626
function getImageContentType(headers: Headers): string | undefined {

packages/gui/src/electron/utils/fetchBuffer.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,21 @@ export default async function fetchBuffer(
102102
}
103103
}
104104

105-
const chunks: Uint8Array[] = [];
105+
const chunks: Buffer[] = [];
106106
let dataSize = 0;
107107

108108
response.on('data', (chunk: Buffer) => {
109109
if (settled) {
110110
return;
111111
}
112112

113-
const buffer = Uint8Array.from(chunk);
114-
dataSize += buffer.byteLength;
113+
dataSize += chunk.byteLength;
115114
if (maxSize > 0 && dataSize > maxSize) {
116115
abortWith(new MaxSizeExceededError(response.headers as Headers));
117116
return;
118117
}
119118

120-
chunks.push(buffer);
119+
chunks.push(chunk);
121120
});
122121

123122
response.on('end', () => {

packages/gui/src/hooks/useNFTVideoLoop.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ export function useNFTVideoLoopForNFT(nftId: string): [boolean, (loopVideo: bool
3434
return [loop, setLoop];
3535
}
3636

37-
// The effective looping state for one NFT video: the global preference forces
38-
// looping on when set, but never disables a video's own loop preference.
39-
export default function useNFTVideoLoop(nftId: string): boolean {
40-
const [globalLoop] = useNFTVideoLoopGlobal();
41-
const [videoLoop] = useNFTVideoLoopForNFT(nftId);
42-
43-
return globalLoop || videoLoop;
44-
}
37+
// The effective looping state for one NFT video is `global || perVideo`:
38+
// the global preference forces looping on when set, but never disables a
39+
// video's own loop preference. Consumers combine the two hooks above.

0 commit comments

Comments
 (0)