mirror of
https://github.com/andy-stack/vaultkeeper-ai.git
synced 2026-07-22 06:42:03 +00:00
Address remaining Obsidian plugin scanner warnings
This commit is contained in:
parent
2131ad0edd
commit
0372b9a182
4 changed files with 15 additions and 15 deletions
|
|
@ -146,20 +146,17 @@ export abstract class BaseAIFileService implements IAIFileService {
|
|||
|
||||
// Calculate total length and concatenate
|
||||
const totalLength = parts.reduce((sum, part) => sum + part.byteLength, 0);
|
||||
const result = new Uint8Array(totalLength);
|
||||
const buffer = new ArrayBuffer(totalLength);
|
||||
const result = new Uint8Array(buffer);
|
||||
let offset = 0;
|
||||
for (const part of parts) {
|
||||
result.set(part, offset);
|
||||
offset += part.byteLength;
|
||||
}
|
||||
|
||||
return this.bytesToBuffer(result);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
protected bytesToBuffer(bytes: Uint8Array): ArrayBuffer {
|
||||
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer;
|
||||
}
|
||||
|
||||
protected getHeader(headerName: string, headers: Record<string, string>): string | undefined {
|
||||
const header = Object.keys(headers).find(header => header.toLowerCase() === headerName.toLowerCase());
|
||||
return header ? headers[header] : undefined;
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ export class GeminiFileService extends BaseAIFileService {
|
|||
|
||||
protected async uploadFileToAPI(data: string, mimeType: string, displayName?: string): Promise<string> {
|
||||
return this.withRetry("Upload file", async () => {
|
||||
const bytes = StringTools.toBytes(data);
|
||||
const numBytes = bytes.byteLength;
|
||||
const buffer = StringTools.toBuffer(data);
|
||||
const numBytes = buffer.byteLength;
|
||||
|
||||
const metadata = displayName ? { file: { displayName } } : {};
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ export class GeminiFileService extends BaseAIFileService {
|
|||
"X-Goog-Upload-Offset": "0",
|
||||
"X-Goog-Upload-Command": "upload, finalize"
|
||||
},
|
||||
body: this.bytesToBuffer(bytes),
|
||||
body: buffer,
|
||||
throw: false
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -78,17 +78,21 @@ export abstract class StringTools {
|
|||
}
|
||||
|
||||
public static toBytes(input: string): Uint8Array {
|
||||
return new Uint8Array(this.toBuffer(input));
|
||||
}
|
||||
|
||||
public static toBuffer(input: string): ArrayBuffer {
|
||||
const binaryString = atob(input);
|
||||
const bytes = new Uint8Array(new ArrayBuffer(binaryString.length));
|
||||
const buffer = new ArrayBuffer(binaryString.length);
|
||||
const bytes = new Uint8Array(buffer);
|
||||
for (let i = 0; i < binaryString.length; i++) {
|
||||
bytes[i] = binaryString.charCodeAt(i);
|
||||
}
|
||||
return bytes;
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static async computeSHA256Hash(base64: string): Promise<string> {
|
||||
const bytes = this.toBytes(base64);
|
||||
const buffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer;
|
||||
const buffer = this.toBuffer(base64);
|
||||
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('');
|
||||
|
|
|
|||
|
|
@ -229,8 +229,7 @@ export class ConversationFileSystemService {
|
|||
return filePath;
|
||||
}
|
||||
|
||||
const bytes = StringTools.toBytes(attachment.base64);
|
||||
const arrayBuffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength) as ArrayBuffer;
|
||||
const arrayBuffer = StringTools.toBuffer(attachment.base64);
|
||||
|
||||
const result = await this.fileSystemService.writeBinaryFile(filePath, arrayBuffer, true);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue