From 2131ad0edd711a0df6c45e815d4dc7cb7a1417e2 Mon Sep 17 00:00:00 2001 From: Andrew Beal Date: Sun, 28 Jun 2026 15:31:07 +0100 Subject: [PATCH] Address Obsidian plugin scanner warnings. --- AIClasses/BaseAIFileService.ts | 8 ++++---- Helpers/StringTools.ts | 5 +++-- Services/ConversationFileSystemService.ts | 2 +- tsconfig.json | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/AIClasses/BaseAIFileService.ts b/AIClasses/BaseAIFileService.ts index 00f463f..7b056fa 100644 --- a/AIClasses/BaseAIFileService.ts +++ b/AIClasses/BaseAIFileService.ts @@ -114,8 +114,8 @@ export abstract class BaseAIFileService implements IAIFileService { return `----FormBoundary${Date.now()}${Math.random().toString(36).substring(2)}`; } - protected createFormData(displayName: string | undefined, mimeType: string, boundary: string, bytes: Uint8Array, additionalFields?: Record): ArrayBuffer { - const parts: Uint8Array[] = []; + protected createFormData(displayName: string | undefined, mimeType: string, boundary: string, bytes: Uint8Array, additionalFields?: Record): ArrayBuffer { + const parts: Uint8Array[] = []; const encoder = new TextEncoder(); // Add the file field @@ -156,8 +156,8 @@ export abstract class BaseAIFileService implements IAIFileService { return this.bytesToBuffer(result); } - protected bytesToBuffer(bytes: Uint8Array): ArrayBuffer { - return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength); + protected bytesToBuffer(bytes: Uint8Array): ArrayBuffer { + return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer; } protected getHeader(headerName: string, headers: Record): string | undefined { diff --git a/Helpers/StringTools.ts b/Helpers/StringTools.ts index 3b86060..0014f9c 100644 --- a/Helpers/StringTools.ts +++ b/Helpers/StringTools.ts @@ -77,7 +77,7 @@ export abstract class StringTools { return btoa(binary); } - public static toBytes(input: string): Uint8Array { + public static toBytes(input: string): Uint8Array { const binaryString = atob(input); const bytes = new Uint8Array(new ArrayBuffer(binaryString.length)); for (let i = 0; i < binaryString.length; i++) { @@ -88,7 +88,8 @@ export abstract class StringTools { public static async computeSHA256Hash(base64: string): Promise { const bytes = this.toBytes(base64); - const hashBuffer = await crypto.subtle.digest('SHA-256', bytes); + const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer; + const hashBuffer = await crypto.subtle.digest('SHA-256', buffer); const hashArray = Array.from(new Uint8Array(hashBuffer)); return hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); } diff --git a/Services/ConversationFileSystemService.ts b/Services/ConversationFileSystemService.ts index 7e86655..f730479 100644 --- a/Services/ConversationFileSystemService.ts +++ b/Services/ConversationFileSystemService.ts @@ -230,7 +230,7 @@ export class ConversationFileSystemService { } const bytes = StringTools.toBytes(attachment.base64); - const arrayBuffer = bytes.buffer; + const arrayBuffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer; const result = await this.fileSystemService.writeBinaryFile(filePath, arrayBuffer, true); diff --git a/tsconfig.json b/tsconfig.json index 699f3fc..f67d217 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,6 +14,7 @@ "strictNullChecks": true, "lib": [ "DOM", + "DOM.Iterable", "ES2022" ], "paths": {