replace toByteArray with Response(stream).bytes()

This commit is contained in:
Siddharth Singh
2024-11-06 12:12:27 +05:30
parent 38288aadb3
commit e96a9e4f35
2 changed files with 4 additions and 16 deletions

View File

@@ -3,7 +3,7 @@ import { HTTPException } from '@hono/hono/http-exception';
import { AppContext } from '@/app.ts';
import { Conf } from '@/config.ts';
import { DittoUpload, dittoUploads } from '@/DittoUploads.ts';
import { getOptionalNip94Metadata, toByteArray } from '@/utils/image-metadata.ts';
import { getOptionalNip94Metadata } from '@/utils/image-metadata.ts';
import type { Nip94MetadataOptional } from '@/interfaces/Nip94Metadata.ts';
import { encodeHex } from '@std/encoding/hex';
@@ -53,7 +53,8 @@ export async function uploadFile(
}
}
if (!tagMap.has('x') || !tagMap.has('ox')) {
const hash = metadata?.x || await crypto.subtle.digest('SHA-256', await toByteArray(file)).then(encodeHex);
const hash = metadata?.x ||
await crypto.subtle.digest('SHA-256', await new Response(file.stream()).bytes()).then(encodeHex);
tags.push(['x', hash!]);
tags.push(['ox', hash!]);
}