It looks like blossom.getOptimizedBlob() defined in
|
/** |
|
* Gets an optimized version of a blob |
|
* @param url The URL of the blob |
|
* @param options Optimization options |
|
* @returns The optimized blob response |
|
*/ |
|
public async getOptimizedBlob(url: string, options: BlossomOptimizationOptions = {}): Promise<Response> { |
|
try { |
|
// Parse the URL and extract relevant parts |
|
const urlObj = new URL(url); |
|
const baseUrl = `${urlObj.protocol}//${urlObj.host}`; |
|
const hash = urlObj.pathname.split("/").pop(); |
|
|
|
if (!hash) { |
|
throw new NDKBlossomOptimizationError("Invalid URL, no hash found", "BLOB_NOT_FOUND", url); |
|
} |
|
|
|
// Construct the media URL |
|
let mediaUrl = `${baseUrl}/media/${hash}`; |
|
|
|
// Add optimization parameters as query string |
|
const params = new URLSearchParams(); |
|
for (const [key, value] of Object.entries(options)) { |
|
if (value !== undefined) { |
|
params.append(key, value.toString()); |
|
} |
|
} |
|
|
|
if (params.toString()) { |
|
mediaUrl += `?${params.toString()}`; |
|
} |
|
|
|
// Fetch the optimized blob |
|
const response = await fetchWithRetry(mediaUrl, {}, this.retryOptions); |
|
|
|
if (!response.ok) { |
|
throw new NDKBlossomOptimizationError( |
|
`Failed to get optimized blob: ${response.status} ${response.statusText}`, |
|
"SERVER_REJECTED", |
|
url, |
|
); |
|
} |
|
|
|
return response; |
|
} catch (error) { |
|
if (error instanceof NDKBlossomOptimizationError) { |
|
throw error; |
|
} |
|
|
|
throw new NDKBlossomOptimizationError( |
|
`Failed to get optimized blob: ${(error as Error).message}`, |
|
"SERVER_UNSUPPORTED", |
|
url, |
|
error as Error, |
|
); |
|
} |
|
} |
is incorrect or uses some non-standard endpoint.
BUD 05 defines PUT /media, which seems to work similar to PUT /upload. OTOH, endpoint GET /media/<SHA256> used by getOptimizedBlob is not specified anywhere, afaics.
Has it been tested against existing Blossom servers, does it work, is it some non-standard behaviour?
PUT /media would be a very useful feature. Some servers may have capabilities like metadata removal, unlike PUT /upload which saves data as-is.
Actual behavior
blossom.getOptimizedBlob() uses non-standard endpoint.
Expected behavior
Standard endpoint PUT /media is available for upload via some method in this library.
It looks like
blossom.getOptimizedBlob()defined inndk/blossom/src/blossom.ts
Lines 400 to 456 in e51b54c
BUD 05 defines
PUT /media, which seems to work similar toPUT /upload. OTOH, endpointGET /media/<SHA256>used bygetOptimizedBlobis not specified anywhere, afaics.Has it been tested against existing Blossom servers, does it work, is it some non-standard behaviour?
PUT /mediawould be a very useful feature. Some servers may have capabilities like metadata removal, unlikePUT /uploadwhich saves data as-is.Actual behavior
blossom.getOptimizedBlob()uses non-standard endpoint.Expected behavior
Standard endpoint
PUT /mediais available for upload via some method in this library.