diff --git a/extensions/tlon/src/channel.ts b/extensions/tlon/src/channel.ts index b7cbdc9963f..ac5881273c3 100644 --- a/extensions/tlon/src/channel.ts +++ b/extensions/tlon/src/channel.ts @@ -1,11 +1,10 @@ +import { configureClient } from "@tloncorp/api"; import type { ChannelOutboundAdapter, ChannelPlugin, ChannelSetupInput, OpenClawConfig, } from "openclaw/plugin-sdk"; -// NOTE: configureClient not available in current @tloncorp/api-beta version -// import { configureClient } from "@tloncorp/api"; import { applyAccountNameToChannelSection, DEFAULT_ACCOUNT_ID, @@ -213,13 +212,13 @@ const tlonOutbound: ChannelOutboundAdapter = { throw new Error(`Invalid Tlon target. Use ${formatTargetHint()}`); } - // NOTE: configureClient not available in current @tloncorp/api-beta version - // configureClient({ - // shipUrl: account.url, - // shipName: account.ship.replace(/^~/, ""), - // verbose: false, - // getCode: async () => account.code!, - // }); + // Configure the API client for uploads + configureClient({ + shipUrl: account.url, + shipName: account.ship.replace(/^~/, ""), + verbose: false, + getCode: async () => account.code!, + }); const uploadedUrl = mediaUrl ? await uploadImageFromUrl(mediaUrl) : undefined; diff --git a/extensions/tlon/src/urbit/upload.ts b/extensions/tlon/src/urbit/upload.ts index 7c3e1cb6c6a..78338de7b03 100644 --- a/extensions/tlon/src/urbit/upload.ts +++ b/extensions/tlon/src/urbit/upload.ts @@ -1,17 +1,40 @@ /** * Upload an image from a URL to Tlon storage. - * - * NOTE: uploadFile is not yet available in @tloncorp/api-beta. - * For now, this returns the original URL. Once the API supports uploads, - * we can implement proper Tlon storage uploads. */ +import { uploadFile } from "@tloncorp/api"; /** * Fetch an image from a URL and upload it to Tlon storage. * Returns the uploaded URL, or falls back to the original URL on error. + * + * Note: configureClient must be called before using this function. */ export async function uploadImageFromUrl(imageUrl: string): Promise { - // TODO: Implement once @tloncorp/api exports uploadFile - // For now, just return the original URL - return imageUrl; + try { + // Fetch the image + const response = await fetch(imageUrl); + if (!response.ok) { + console.warn(`[tlon] Failed to fetch image from ${imageUrl}: ${response.status}`); + return imageUrl; + } + + const contentType = response.headers.get("content-type") || "image/png"; + const blob = await response.blob(); + + // Extract filename from URL or use a default + const urlPath = new URL(imageUrl).pathname; + const fileName = urlPath.split("/").pop() || `upload-${Date.now()}.png`; + + // Upload to Tlon storage + const result = await uploadFile({ + blob, + fileName, + contentType, + }); + + return result.url; + } catch (err) { + console.warn(`[tlon] Failed to upload image, using original URL: ${err}`); + return imageUrl; + } }