clawbr 0.0.43 → 0.0.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,7 +9,7 @@ function _ts_metadata(k, v) {
|
|
|
9
9
|
}
|
|
10
10
|
import { Command, CommandRunner, Option } from "nest-commander";
|
|
11
11
|
import { readFileSync } from "fs";
|
|
12
|
-
import { validateImageInput, isUrl } from "../utils/image.js";
|
|
12
|
+
import { validateImageInput, isUrl, getMimeTypeFromExtension, detectMimeTypeFromBuffer, normalizeMimeType } from "../utils/image.js";
|
|
13
13
|
import inquirer from "inquirer";
|
|
14
14
|
import ora from "ora";
|
|
15
15
|
import chalk from "chalk";
|
|
@@ -125,19 +125,34 @@ export class PostCommand extends CommandRunner {
|
|
|
125
125
|
if (!imageResponse.ok) {
|
|
126
126
|
throw new Error(`Failed to fetch image from URL: ${imageResponse.statusText}`);
|
|
127
127
|
}
|
|
128
|
-
const contentType = imageResponse.headers.get("content-type") || "image/jpeg";
|
|
129
128
|
const buffer = Buffer.from(await imageResponse.arrayBuffer());
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
else
|
|
139
|
-
|
|
140
|
-
|
|
129
|
+
// Prefer magic-byte detection for the MIME type; normalise + fall back
|
|
130
|
+
// to the Content-Type header so that non-standard aliases like
|
|
131
|
+
// 'image/jpg' or 'image/jpeg; charset=binary' don't break the upload.
|
|
132
|
+
const { fileTypeFromBuffer } = await import("file-type");
|
|
133
|
+
const detected = await fileTypeFromBuffer(buffer);
|
|
134
|
+
let contentType;
|
|
135
|
+
if (detected) {
|
|
136
|
+
contentType = normalizeMimeType(detected.mime);
|
|
137
|
+
} else {
|
|
138
|
+
const headerCt = imageResponse.headers.get("content-type") || "image/jpeg";
|
|
139
|
+
contentType = normalizeMimeType(headerCt);
|
|
140
|
+
}
|
|
141
|
+
// Derive a sane extension from the resolved content type
|
|
142
|
+
const ctToExt = {
|
|
143
|
+
"image/jpeg": "jpg",
|
|
144
|
+
"image/png": "png",
|
|
145
|
+
"image/webp": "webp",
|
|
146
|
+
"image/gif": "gif",
|
|
147
|
+
"image/avif": "avif",
|
|
148
|
+
"image/bmp": "bmp",
|
|
149
|
+
"image/tiff": "tiff",
|
|
150
|
+
"video/mp4": "mp4",
|
|
151
|
+
"video/webm": "webm",
|
|
152
|
+
"video/quicktime": "mov",
|
|
153
|
+
"video/x-msvideo": "avi"
|
|
154
|
+
};
|
|
155
|
+
const extension = ctToExt[contentType] ?? "bin";
|
|
141
156
|
const filename = `media.${extension}`;
|
|
142
157
|
formData.append("file", buffer, {
|
|
143
158
|
filename,
|
|
@@ -146,26 +161,13 @@ export class PostCommand extends CommandRunner {
|
|
|
146
161
|
} else {
|
|
147
162
|
// Read file from disk as buffer
|
|
148
163
|
const buffer = readFileSync(filePath);
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
contentType = "video/quicktime";
|
|
157
|
-
} else if (filePath.match(/\.avi$/i)) {
|
|
158
|
-
contentType = "video/x-msvideo";
|
|
159
|
-
} else if (filePath.match(/\.jpe?g$/i)) {
|
|
160
|
-
contentType = "image/jpeg";
|
|
161
|
-
} else if (filePath.match(/\.png$/i)) {
|
|
162
|
-
contentType = "image/png";
|
|
163
|
-
} else if (filePath.match(/\.gif$/i)) {
|
|
164
|
-
contentType = "image/gif";
|
|
165
|
-
} else if (filePath.match(/\.webp$/i)) {
|
|
166
|
-
contentType = "image/webp";
|
|
167
|
-
}
|
|
168
|
-
// Extract filename from path
|
|
164
|
+
// Use magic-byte detection for the most reliable MIME type.
|
|
165
|
+
// Fall back to extension-based lookup if file-type can't identify it.
|
|
166
|
+
const detectedMime = await detectMimeTypeFromBuffer(buffer);
|
|
167
|
+
let contentType = detectedMime ?? getMimeTypeFromExtension(filePath);
|
|
168
|
+
// Extra safety: also handle any aliased MIME from the extension lookup
|
|
169
|
+
contentType = normalizeMimeType(contentType);
|
|
170
|
+
// Extract filename from path, preserving the original extension
|
|
169
171
|
const filename = filePath.split("/").pop() || "file";
|
|
170
172
|
formData.append("file", buffer, {
|
|
171
173
|
filename: filename,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/commands/post.command.ts"],"sourcesContent":["import { Command, CommandRunner, Option } from \"nest-commander\";\nimport { readFileSync } from \"fs\";\nimport { validateImageInput, isUrl } from \"../utils/image.js\";\nimport inquirer from \"inquirer\";\nimport ora from \"ora\";\nimport chalk from \"chalk\";\nimport FormData from \"form-data\";\nimport fetch from \"node-fetch\";\nimport { getApiToken, getApiUrl, loadCredentials } from \"../utils/credentials.js\";\nimport { requireOnboarding } from \"../utils/config.js\";\nimport { statSync } from \"fs\";\n\ninterface PostCommandOptions {\n file?: string;\n image?: string;\n video?: string;\n caption?: string;\n json?: boolean;\n}\n\ninterface ApiResponse {\n success: boolean;\n post: {\n id: string;\n caption: string;\n imageUrl: string;\n visualSnapshot: string;\n createdAt: string;\n agent: {\n username: string;\n };\n };\n}\n\n@Command({\n name: \"post\",\n description: \"Create a new post with image/video and caption\",\n arguments: \"\",\n options: { isDefault: false },\n})\nexport class PostCommand extends CommandRunner {\n async run(inputs: string[], options: PostCommandOptions): Promise<void> {\n // Require onboarding before posting\n await requireOnboarding();\n\n // ─────────────────────────────────────────────────────────────────────\n // Detect TTY - Determine if running interactively\n // ─────────────────────────────────────────────────────────────────────\n const isInteractive = process.stdout.isTTY && !options.image && !options.caption;\n\n let filePath: string | undefined;\n let caption: string;\n\n // ─────────────────────────────────────────────────────────────────────\n // INTERACTIVE MODE - Use inquirer prompts\n // ─────────────────────────────────────────────────────────────────────\n if (isInteractive) {\n const answers = await inquirer.prompt([\n {\n type: \"input\",\n name: \"filePath\",\n message: \"Enter the path to your image/video file (or press Enter to skip):\",\n validate: (input: string) => {\n if (!input) {\n return true; // Allow empty for text-only posts\n }\n const validation = validateImageInput(input);\n if (!validation.valid) {\n return validation.error || \"Invalid media input\";\n }\n return true;\n },\n },\n {\n type: \"input\",\n name: \"caption\",\n message: \"Enter a caption for your post:\",\n validate: (input: string) => {\n if (!input || input.trim().length === 0) {\n return \"Caption is required\";\n }\n return true;\n },\n },\n ]);\n\n filePath = answers.filePath || undefined;\n caption = answers.caption;\n }\n // ─────────────────────────────────────────────────────────────────────\n // NON-INTERACTIVE MODE - Use command-line flags\n // ─────────────────────────────────────────────────────────────────────\n else {\n // Support --file, --image, and --video flags\n filePath = options.video || options.image || options.file;\n caption = options.caption || \"\";\n\n // At least one of image/video or caption is required\n if (!filePath && !caption) {\n throw new Error(\n \"At least one of --image, --video, or --caption is required.\\n\" +\n \"Usage: clawbr post --image <path> --caption <text>\\n\" +\n \" clawbr post --video <path> --caption <text>\\n\" +\n \" clawbr post --caption <text>\"\n );\n }\n\n if (filePath) {\n // Check if it's a video file\n const isVideo = /\\.(mp4|webm|mov|avi)$/i.test(filePath);\n\n if (!isVideo) {\n const validation = validateImageInput(filePath);\n if (!validation.valid) {\n throw new Error(validation.error);\n }\n } else {\n // Basic validation for video files\n if (!isUrl(filePath)) {\n try {\n const stats = statSync(filePath);\n const maxSize = 50 * 1024 * 1024; // 50MB\n if (stats.size > maxSize) {\n throw new Error(`Video file too large. Max size: 50MB`);\n }\n } catch (err) {\n if ((err as any).code === \"ENOENT\") {\n throw new Error(`Video file not found: ${filePath}`);\n }\n throw err;\n }\n }\n }\n }\n }\n\n // ─────────────────────────────────────────────────────────────────────\n // Get credentials from config or environment\n // ─────────────────────────────────────────────────────────────────────\n const agentToken = getApiToken();\n const apiUrl = getApiUrl();\n\n if (!agentToken) {\n throw new Error(\n \"Authentication required. Please run 'clawbr onboard' first.\\n\" +\n \"Or set CLAWBR_TOKEN environment variable.\"\n );\n }\n\n // Get provider key if available\n const credentials = loadCredentials();\n let providerKey = \"\";\n if (credentials && credentials.apiKeys && credentials.aiProvider) {\n providerKey = credentials.apiKeys[credentials.aiProvider] || \"\";\n }\n\n // ─────────────────────────────────────────────────────────────────────\n // Processing - Upload post with spinner\n // ─────────────────────────────────────────────────────────────────────\n const spinner = options.json ? null : ora(\"Processing your post...\").start();\n\n try {\n // Create FormData\n const formData = new FormData();\n\n if (filePath) {\n if (isUrl(filePath)) {\n // Fetch from URL\n const imageResponse = await fetch(filePath);\n if (!imageResponse.ok) {\n throw new Error(`Failed to fetch image from URL: ${imageResponse.statusText}`);\n }\n\n const contentType = imageResponse.headers.get(\"content-type\") || \"image/jpeg\";\n const buffer = Buffer.from(await imageResponse.arrayBuffer());\n\n // Determine extension from content-type\n let extension = \"jpg\";\n if (contentType.includes(\"png\")) extension = \"png\";\n else if (contentType.includes(\"webp\")) extension = \"webp\";\n else if (contentType.includes(\"gif\")) extension = \"gif\";\n else if (contentType.includes(\"mp4\")) extension = \"mp4\";\n else if (contentType.includes(\"webm\")) extension = \"webm\";\n else if (contentType.includes(\"quicktime\")) extension = \"mov\";\n else if (contentType.includes(\"x-msvideo\")) extension = \"avi\";\n\n // Use a generic filename with correct extension\n // We can't easily rely on the URL path for redirected URLs like picsum.photos\n const filename = `media.${extension}`;\n\n formData.append(\"file\", buffer, { filename, contentType });\n } else {\n // Read file from disk as buffer\n const buffer = readFileSync(filePath);\n\n // Determine content type from file extension\n let contentType = \"application/octet-stream\";\n if (filePath.match(/\\.mp4$/i)) {\n contentType = \"video/mp4\";\n } else if (filePath.match(/\\.webm$/i)) {\n contentType = \"video/webm\";\n } else if (filePath.match(/\\.mov$/i)) {\n contentType = \"video/quicktime\";\n } else if (filePath.match(/\\.avi$/i)) {\n contentType = \"video/x-msvideo\";\n } else if (filePath.match(/\\.jpe?g$/i)) {\n contentType = \"image/jpeg\";\n } else if (filePath.match(/\\.png$/i)) {\n contentType = \"image/png\";\n } else if (filePath.match(/\\.gif$/i)) {\n contentType = \"image/gif\";\n } else if (filePath.match(/\\.webp$/i)) {\n contentType = \"image/webp\";\n }\n\n // Extract filename from path\n const filename = filePath.split(\"/\").pop() || \"file\";\n\n formData.append(\"file\", buffer, {\n filename: filename,\n contentType: contentType,\n });\n }\n }\n\n if (caption) {\n formData.append(\"caption\", caption);\n }\n\n // Make API request\n const headers: Record<string, string> = {\n \"X-Agent-Token\": agentToken,\n };\n\n if (providerKey) {\n headers[\"X-Provider-Key\"] = providerKey;\n }\n\n const response = await fetch(`${apiUrl}/api/posts/create`, {\n method: \"POST\",\n headers,\n body: formData,\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n let errorMessage: string;\n let isVerificationError = false;\n\n try {\n const errorJson = JSON.parse(errorText);\n errorMessage = errorJson.error || errorJson.message || \"Unknown error\";\n if (\n response.status === 403 &&\n (errorMessage.includes(\"Verification\") || errorJson.error === \"Verification Required\")\n ) {\n isVerificationError = true;\n errorMessage = errorJson.message || errorMessage;\n }\n } catch {\n errorMessage = errorText || `HTTP ${response.status} ${response.statusText}`;\n }\n\n if (spinner) {\n spinner.fail(`Failed to create post: ${errorMessage}`);\n }\n\n if (isVerificationError) {\n console.log(chalk.yellow(\"\\n⚠️ Account Verification Required\"));\n console.log(\n chalk.gray(\"To prevent spam, all agents must verify their X (Twitter) account.\")\n );\n console.log(chalk.cyan(\"\\nRun the following command to verify:\"));\n console.log(chalk.bold.green(\" clawbr verify\\n\"));\n }\n\n throw new Error(errorMessage);\n }\n\n const result = (await response.json()) as ApiResponse;\n\n if (spinner) {\n spinner.succeed(\"Post created successfully!\");\n }\n\n // Display result\n if (options.json) {\n console.log(JSON.stringify(result, null, 2));\n } else {\n console.log(\"\\n📸 Post Details:\");\n console.log(\"─────────────────────────────────────\");\n console.log(`ID: ${result.post.id}`);\n console.log(`Caption: ${result.post.caption || \"(no caption)\"}`);\n console.log(`Image URL: ${result.post.imageUrl || \"(no image)\"}`);\n console.log(`Visual Snapshot: ${result.post.visualSnapshot || \"(none)\"}`);\n console.log(`Agent: ${result.post.agent.username}`);\n console.log(`Created: ${new Date(result.post.createdAt).toLocaleString()}`);\n console.log(\"─────────────────────────────────────\\n\");\n }\n } catch (error) {\n if (spinner && spinner.isSpinning) {\n spinner.fail(\"Failed to create post\");\n }\n throw error;\n }\n }\n\n @Option({\n flags: \"-f, --file <path>\",\n description: \"Path to the image file (deprecated, use --image)\",\n })\n parseFile(val: string): string {\n return val;\n }\n\n @Option({\n flags: \"-i, --image <path>\",\n description: \"Path to the image file or URL\",\n })\n parseImage(val: string): string {\n return val;\n }\n\n @Option({\n flags: \"-v, --video <path>\",\n description: \"Path to the video file or URL (MP4, WebM, MOV, AVI - max 50MB)\",\n })\n parseVideo(val: string): string {\n return val;\n }\n\n @Option({\n flags: \"-c, --caption <text>\",\n description: \"Caption for the post\",\n })\n parseCaption(val: string): string {\n return val;\n }\n\n @Option({\n flags: \"--json\",\n description: \"Output in JSON format\",\n })\n parseJson(): boolean {\n return true;\n }\n}\n"],"names":["Command","CommandRunner","Option","readFileSync","validateImageInput","isUrl","inquirer","ora","chalk","FormData","fetch","getApiToken","getApiUrl","loadCredentials","requireOnboarding","statSync","PostCommand","run","inputs","options","isInteractive","process","stdout","isTTY","image","caption","filePath","answers","prompt","type","name","message","validate","input","validation","valid","error","trim","length","undefined","video","file","Error","isVideo","test","stats","maxSize","size","err","code","agentToken","apiUrl","credentials","providerKey","apiKeys","aiProvider","spinner","json","start","formData","imageResponse","ok","statusText","contentType","headers","get","buffer","Buffer","from","arrayBuffer","extension","includes","filename","append","match","split","pop","response","method","body","errorText","text","errorMessage","isVerificationError","errorJson","JSON","parse","status","fail","console","log","yellow","gray","cyan","bold","green","result","succeed","stringify","post","id","imageUrl","visualSnapshot","agent","username","Date","createdAt","toLocaleString","isSpinning","parseFile","val","parseImage","parseVideo","parseCaption","parseJson","flags","description","arguments","isDefault"],"mappings":";;;;;;;;;AAAA,SAASA,OAAO,EAAEC,aAAa,EAAEC,MAAM,QAAQ,iBAAiB;AAChE,SAASC,YAAY,QAAQ,KAAK;AAClC,SAASC,kBAAkB,EAAEC,KA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EAAEC,cAAc,IAAI;gBAC1ElB,QAAQC,GAAG,CAAC;YACd;QACF,EAAE,OAAOtD,OAAO;YACd,IAAIoB,WAAWA,QAAQoD,UAAU,EAAE;gBACjCpD,QAAQgC,IAAI,CAAC;YACf;YACA,MAAMpD;QACR;IACF;IAMAyE,UAAUC,GAAW,EAAU;QAC7B,OAAOA;IACT;IAMAC,WAAWD,GAAW,EAAU;QAC9B,OAAOA;IACT;IAMAE,WAAWF,GAAW,EAAU;QAC9B,OAAOA;IACT;IAMAG,aAAaH,GAAW,EAAU;QAChC,OAAOA;IACT;IAMAI,YAAqB;QACnB,OAAO;IACT;AACF;;;QAtCIC,OAAO;QACPC,aAAa;;;;;;;;;;QAObD,OAAO;QACPC,aAAa;;;;;;;;;;QAObD,OAAO;QACPC,aAAa;;;;;;;;;;QAObD,OAAO;QACPC,aAAa;;;;;;;;;;QAObD,OAAO;QACPC,aAAa;;;;;;;;QAlTftF,MAAM;QACNsF,aAAa;QACbC,WAAW;QACXlG,SAAS;YAAEmG,WAAW;QAAM"}
|
|
1
|
+
{"version":3,"sources":["../../src/commands/post.command.ts"],"sourcesContent":["import { Command, CommandRunner, Option } from \"nest-commander\";\nimport { readFileSync } from \"fs\";\nimport {\n validateImageInput,\n isUrl,\n getMimeTypeFromExtension,\n detectMimeTypeFromBuffer,\n normalizeMimeType,\n} from \"../utils/image.js\";\nimport inquirer from \"inquirer\";\nimport ora from \"ora\";\nimport chalk from \"chalk\";\nimport FormData from \"form-data\";\nimport fetch from \"node-fetch\";\nimport { getApiToken, getApiUrl, loadCredentials } from \"../utils/credentials.js\";\nimport { requireOnboarding } from \"../utils/config.js\";\nimport { statSync } from \"fs\";\n\ninterface PostCommandOptions {\n file?: string;\n image?: string;\n video?: string;\n caption?: string;\n json?: boolean;\n}\n\ninterface ApiResponse {\n success: boolean;\n post: {\n id: string;\n caption: string;\n imageUrl: string;\n visualSnapshot: string;\n createdAt: string;\n agent: {\n username: string;\n };\n };\n}\n\n@Command({\n name: \"post\",\n description: \"Create a new post with image/video and caption\",\n arguments: \"\",\n options: { isDefault: false },\n})\nexport class PostCommand extends CommandRunner {\n async run(inputs: string[], options: PostCommandOptions): Promise<void> {\n // Require onboarding before posting\n await requireOnboarding();\n\n // ─────────────────────────────────────────────────────────────────────\n // Detect TTY - Determine if running interactively\n // ─────────────────────────────────────────────────────────────────────\n const isInteractive = process.stdout.isTTY && !options.image && !options.caption;\n\n let filePath: string | undefined;\n let caption: string;\n\n // ─────────────────────────────────────────────────────────────────────\n // INTERACTIVE MODE - Use inquirer prompts\n // ─────────────────────────────────────────────────────────────────────\n if (isInteractive) {\n const answers = await inquirer.prompt([\n {\n type: \"input\",\n name: \"filePath\",\n message: \"Enter the path to your image/video file (or press Enter to skip):\",\n validate: (input: string) => {\n if (!input) {\n return true; // Allow empty for text-only posts\n }\n const validation = validateImageInput(input);\n if (!validation.valid) {\n return validation.error || \"Invalid media input\";\n }\n return true;\n },\n },\n {\n type: \"input\",\n name: \"caption\",\n message: \"Enter a caption for your post:\",\n validate: (input: string) => {\n if (!input || input.trim().length === 0) {\n return \"Caption is required\";\n }\n return true;\n },\n },\n ]);\n\n filePath = answers.filePath || undefined;\n caption = answers.caption;\n }\n // ─────────────────────────────────────────────────────────────────────\n // NON-INTERACTIVE MODE - Use command-line flags\n // ─────────────────────────────────────────────────────────────────────\n else {\n // Support --file, --image, and --video flags\n filePath = options.video || options.image || options.file;\n caption = options.caption || \"\";\n\n // At least one of image/video or caption is required\n if (!filePath && !caption) {\n throw new Error(\n \"At least one of --image, --video, or --caption is required.\\n\" +\n \"Usage: clawbr post --image <path> --caption <text>\\n\" +\n \" clawbr post --video <path> --caption <text>\\n\" +\n \" clawbr post --caption <text>\"\n );\n }\n\n if (filePath) {\n // Check if it's a video file\n const isVideo = /\\.(mp4|webm|mov|avi)$/i.test(filePath);\n\n if (!isVideo) {\n const validation = validateImageInput(filePath);\n if (!validation.valid) {\n throw new Error(validation.error);\n }\n } else {\n // Basic validation for video files\n if (!isUrl(filePath)) {\n try {\n const stats = statSync(filePath);\n const maxSize = 50 * 1024 * 1024; // 50MB\n if (stats.size > maxSize) {\n throw new Error(`Video file too large. Max size: 50MB`);\n }\n } catch (err) {\n if ((err as any).code === \"ENOENT\") {\n throw new Error(`Video file not found: ${filePath}`);\n }\n throw err;\n }\n }\n }\n }\n }\n\n // ─────────────────────────────────────────────────────────────────────\n // Get credentials from config or environment\n // ─────────────────────────────────────────────────────────────────────\n const agentToken = getApiToken();\n const apiUrl = getApiUrl();\n\n if (!agentToken) {\n throw new Error(\n \"Authentication required. Please run 'clawbr onboard' first.\\n\" +\n \"Or set CLAWBR_TOKEN environment variable.\"\n );\n }\n\n // Get provider key if available\n const credentials = loadCredentials();\n let providerKey = \"\";\n if (credentials && credentials.apiKeys && credentials.aiProvider) {\n providerKey = credentials.apiKeys[credentials.aiProvider] || \"\";\n }\n\n // ─────────────────────────────────────────────────────────────────────\n // Processing - Upload post with spinner\n // ─────────────────────────────────────────────────────────────────────\n const spinner = options.json ? null : ora(\"Processing your post...\").start();\n\n try {\n // Create FormData\n const formData = new FormData();\n\n if (filePath) {\n if (isUrl(filePath)) {\n // Fetch from URL\n const imageResponse = await fetch(filePath);\n if (!imageResponse.ok) {\n throw new Error(`Failed to fetch image from URL: ${imageResponse.statusText}`);\n }\n\n const buffer = Buffer.from(await imageResponse.arrayBuffer());\n\n // Prefer magic-byte detection for the MIME type; normalise + fall back\n // to the Content-Type header so that non-standard aliases like\n // 'image/jpg' or 'image/jpeg; charset=binary' don't break the upload.\n const { fileTypeFromBuffer } = await import(\"file-type\");\n const detected = await fileTypeFromBuffer(buffer);\n let contentType: string;\n if (detected) {\n contentType = normalizeMimeType(detected.mime);\n } else {\n const headerCt = imageResponse.headers.get(\"content-type\") || \"image/jpeg\";\n contentType = normalizeMimeType(headerCt);\n }\n\n // Derive a sane extension from the resolved content type\n const ctToExt: Record<string, string> = {\n \"image/jpeg\": \"jpg\",\n \"image/png\": \"png\",\n \"image/webp\": \"webp\",\n \"image/gif\": \"gif\",\n \"image/avif\": \"avif\",\n \"image/bmp\": \"bmp\",\n \"image/tiff\": \"tiff\",\n \"video/mp4\": \"mp4\",\n \"video/webm\": \"webm\",\n \"video/quicktime\": \"mov\",\n \"video/x-msvideo\": \"avi\",\n };\n const extension = ctToExt[contentType] ?? \"bin\";\n const filename = `media.${extension}`;\n\n formData.append(\"file\", buffer, { filename, contentType });\n } else {\n // Read file from disk as buffer\n const buffer = readFileSync(filePath);\n\n // Use magic-byte detection for the most reliable MIME type.\n // Fall back to extension-based lookup if file-type can't identify it.\n const detectedMime = await detectMimeTypeFromBuffer(buffer);\n let contentType = detectedMime ?? getMimeTypeFromExtension(filePath);\n\n // Extra safety: also handle any aliased MIME from the extension lookup\n contentType = normalizeMimeType(contentType);\n\n // Extract filename from path, preserving the original extension\n const filename = filePath.split(\"/\").pop() || \"file\";\n\n formData.append(\"file\", buffer, {\n filename: filename,\n contentType: contentType,\n });\n }\n }\n\n if (caption) {\n formData.append(\"caption\", caption);\n }\n\n // Make API request\n const headers: Record<string, string> = {\n \"X-Agent-Token\": agentToken,\n };\n\n if (providerKey) {\n headers[\"X-Provider-Key\"] = providerKey;\n }\n\n const response = await fetch(`${apiUrl}/api/posts/create`, {\n method: \"POST\",\n headers,\n body: formData,\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n let errorMessage: string;\n let isVerificationError = false;\n\n try {\n const errorJson = JSON.parse(errorText);\n errorMessage = errorJson.error || errorJson.message || \"Unknown error\";\n if (\n response.status === 403 &&\n (errorMessage.includes(\"Verification\") || errorJson.error === \"Verification Required\")\n ) {\n isVerificationError = true;\n errorMessage = errorJson.message || errorMessage;\n }\n } catch {\n errorMessage = errorText || `HTTP ${response.status} ${response.statusText}`;\n }\n\n if (spinner) {\n spinner.fail(`Failed to create post: ${errorMessage}`);\n }\n\n if (isVerificationError) {\n console.log(chalk.yellow(\"\\n⚠️ Account Verification Required\"));\n console.log(\n chalk.gray(\"To prevent spam, all agents must verify their X (Twitter) account.\")\n );\n console.log(chalk.cyan(\"\\nRun the following command to verify:\"));\n console.log(chalk.bold.green(\" clawbr verify\\n\"));\n }\n\n throw new Error(errorMessage);\n }\n\n const result = (await response.json()) as ApiResponse;\n\n if (spinner) {\n spinner.succeed(\"Post created successfully!\");\n }\n\n // Display result\n if (options.json) {\n console.log(JSON.stringify(result, null, 2));\n } else {\n console.log(\"\\n📸 Post Details:\");\n console.log(\"─────────────────────────────────────\");\n console.log(`ID: ${result.post.id}`);\n console.log(`Caption: ${result.post.caption || \"(no caption)\"}`);\n console.log(`Image URL: ${result.post.imageUrl || \"(no image)\"}`);\n console.log(`Visual Snapshot: ${result.post.visualSnapshot || \"(none)\"}`);\n console.log(`Agent: ${result.post.agent.username}`);\n console.log(`Created: ${new Date(result.post.createdAt).toLocaleString()}`);\n console.log(\"─────────────────────────────────────\\n\");\n }\n } catch (error) {\n if (spinner && spinner.isSpinning) {\n spinner.fail(\"Failed to create post\");\n }\n throw error;\n }\n }\n\n @Option({\n flags: \"-f, --file <path>\",\n description: \"Path to the image file (deprecated, use --image)\",\n })\n parseFile(val: string): string {\n return val;\n }\n\n @Option({\n flags: \"-i, --image <path>\",\n description: \"Path to the image file or URL\",\n })\n parseImage(val: string): string {\n return val;\n }\n\n @Option({\n flags: \"-v, --video <path>\",\n description: \"Path to the video file or URL (MP4, WebM, MOV, AVI - max 50MB)\",\n })\n parseVideo(val: string): string {\n return val;\n }\n\n @Option({\n flags: \"-c, --caption <text>\",\n description: \"Caption for the post\",\n })\n parseCaption(val: string): string {\n return val;\n }\n\n @Option({\n flags: \"--json\",\n description: \"Output in JSON format\",\n })\n parseJson(): boolean {\n return true;\n }\n}\n"],"names":["Command","CommandRunner","Option","readFileSync","validateImageInput","isUrl","getMimeTypeFromExtension","detectMimeTypeFromBuffer","normalizeMimeType","inquirer","ora","chalk","FormData","fetch","getApiToken","getApiUrl","loadCredentials","requireOnboarding","statSync","PostCommand","run","inputs","options","isInteractive","process","stdout","isTTY","image","caption","filePath","answers","prompt","type","name","message","validate","input","validation","valid","error","trim","length","undefined","video","file","Error","isVideo","test","stats","maxSize","size","err","code","agentToken","apiUrl","credentials","providerKey","apiKeys","aiProvider","spinner","json","start","formData","imageResponse","ok","statusText","buffer","Buffer","from","arrayBuffer","fileTypeFromBuffer","detected","contentType","mime","headerCt","headers","get","ctToExt","extension","filename","append","detectedMime","split","pop","response","method","body","errorText","text","errorMessage","isVerificationError","errorJson","JSON","parse","status","includes","fail","console","log","yellow","gray","cyan","bold","green","result","succeed","stringify","post","id","imageUrl","visualSnapshot","agent","username","Date","createdAt","toLocaleString","isSpinning","parseFile","val","parseImage","parseVideo","parseCaption","parseJson","flags","description","arguments","isDefault"],"mappings":";;;;;;;;;AAAA,SAASA,OAAO,EAAEC,aAAa,EAAEC,MAAM,QAAQ,iBAAiB;AAChE,SAASC,YAAY,QAAQ,KAAK;AAClC,SACEC,kBAAkB,EAClBC,KAAK,EACLC,wBAAwB,EACxBC,wBAAwB,EACxBC,iBAAiB,QACZ,oBAAoB;AAC3B,OAAOC,cAAc,WAAW;AAChC,OAAOC,SAAS,MAAM;AACtB,OAAOC,WAAW,QAAQ;AAC1B,OAAOC,cAAc,YAAY;AACjC,OAAOC,WAAW,aAAa;AAC/B,SAASC,WAAW,EAAEC,SAAS,EAAEC,eAAe,QAAQ,0BAA0B;AAClF,SAASC,iBAAiB,QAAQ,qBAAqB;AACvD,SAASC,QAAQ,QAAQ,KAAK;AA8B9B,OAAO,MAAMC,oBAAoBlB;IAC/B,MAAMmB,IAAIC,MAAgB,EAAEC,OAA2B,EAAiB;QACtE,oCAAoC;QACpC,MAAML;QAEN,wEAAwE;QACxE,kDAAkD;QAClD,wEAAwE;QACxE,MAAMM,gBAAgBC,QAAQC,MAAM,CAACC,KAAK,IAAI,CAACJ,QAAQK,KAAK,IAAI,CAACL,QAAQM,OAAO;QAEhF,IAAIC;QACJ,IAAID;QAEJ,wEAAwE;QACxE,0CAA0C;QAC1C,wEAAwE;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/DqE,QAAQC,GAAG,CAAC,CAAC,WAAW,EAAEM,OAAOG,IAAI,CAACE,QAAQ,IAAI,cAAc;gBAChEZ,QAAQC,GAAG,CAAC,CAAC,iBAAiB,EAAEM,OAAOG,IAAI,CAACG,cAAc,IAAI,UAAU;gBACxEb,QAAQC,GAAG,CAAC,CAAC,OAAO,EAAEM,OAAOG,IAAI,CAACI,KAAK,CAACC,QAAQ,EAAE;gBAClDf,QAAQC,GAAG,CAAC,CAAC,SAAS,EAAE,IAAIe,KAAKT,OAAOG,IAAI,CAACO,SAAS,EAAEC,cAAc,IAAI;gBAC1ElB,QAAQC,GAAG,CAAC;YACd;QACF,EAAE,OAAO3D,OAAO;YACd,IAAIoB,WAAWA,QAAQyD,UAAU,EAAE;gBACjCzD,QAAQqC,IAAI,CAAC;YACf;YACA,MAAMzD;QACR;IACF;IAMA8E,UAAUC,GAAW,EAAU;QAC7B,OAAOA;IACT;IAMAC,WAAWD,GAAW,EAAU;QAC9B,OAAOA;IACT;IAMAE,WAAWF,GAAW,EAAU;QAC9B,OAAOA;IACT;IAMAG,aAAaH,GAAW,EAAU;QAChC,OAAOA;IACT;IAMAI,YAAqB;QACnB,OAAO;IACT;AACF;;;QAtCIC,OAAO;QACPC,aAAa;;;;;;;;;;QAObD,OAAO;QACPC,aAAa;;;;;;;;;;QAObD,OAAO;QACPC,aAAa;;;;;;;;;;QAObD,OAAO;QACPC,aAAa;;;;;;;;;;QAObD,OAAO;QACPC,aAAa;;;;;;;;QArTf3F,MAAM;QACN2F,aAAa;QACbC,WAAW;QACXvG,SAAS;YAAEwG,WAAW;QAAM"}
|
package/dist/utils/image.js
CHANGED
|
@@ -1,19 +1,51 @@
|
|
|
1
1
|
import { readFileSync, existsSync } from "fs";
|
|
2
2
|
import fetch from "node-fetch";
|
|
3
|
+
import { fileTypeFromBuffer } from "file-type";
|
|
3
4
|
/**
|
|
4
5
|
* Supported image MIME types
|
|
5
6
|
*/ export const SUPPORTED_IMAGE_TYPES = {
|
|
6
7
|
png: "image/png",
|
|
7
8
|
jpg: "image/jpeg",
|
|
8
9
|
jpeg: "image/jpeg",
|
|
10
|
+
jpe: "image/jpeg",
|
|
9
11
|
webp: "image/webp",
|
|
10
|
-
gif: "image/gif"
|
|
12
|
+
gif: "image/gif",
|
|
13
|
+
avif: "image/avif",
|
|
14
|
+
bmp: "image/bmp",
|
|
15
|
+
tiff: "image/tiff",
|
|
16
|
+
tif: "image/tiff"
|
|
11
17
|
};
|
|
12
18
|
/**
|
|
13
|
-
*
|
|
19
|
+
* Non-standard MIME aliases normalised to canonical form
|
|
20
|
+
*/ const MIME_ALIASES = {
|
|
21
|
+
"image/jpg": "image/jpeg",
|
|
22
|
+
"image/jpe": "image/jpeg",
|
|
23
|
+
"image/pjpeg": "image/jpeg",
|
|
24
|
+
"image/x-png": "image/png",
|
|
25
|
+
"image/x-bmp": "image/bmp",
|
|
26
|
+
"image/x-ms-bmp": "image/bmp"
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Normalise a raw MIME string: strip parameters (charset, etc.) and resolve
|
|
30
|
+
* known non-standard aliases to their canonical equivalents.
|
|
31
|
+
*/ export function normalizeMimeType(raw) {
|
|
32
|
+
const base = raw.split(";")[0].trim().toLowerCase();
|
|
33
|
+
return MIME_ALIASES[base] ?? base;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get MIME type from file extension (normalised).
|
|
37
|
+
* Falls back gracefully for unknown extensions.
|
|
14
38
|
*/ export function getMimeTypeFromExtension(filePath) {
|
|
15
39
|
const ext = filePath.toLowerCase().split(".").pop() || "";
|
|
16
|
-
return SUPPORTED_IMAGE_TYPES[ext]
|
|
40
|
+
return SUPPORTED_IMAGE_TYPES[ext] ?? "image/octet-stream";
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Detect MIME type from buffer magic bytes via the file-type library.
|
|
44
|
+
* Returns the canonical (normalised) MIME type, or null if unrecognised.
|
|
45
|
+
*/ export async function detectMimeTypeFromBuffer(buffer) {
|
|
46
|
+
const result = await fileTypeFromBuffer(buffer);
|
|
47
|
+
if (!result) return null;
|
|
48
|
+
return normalizeMimeType(result.mime);
|
|
17
49
|
}
|
|
18
50
|
/**
|
|
19
51
|
* Check if a string is a URL
|
|
@@ -73,8 +105,9 @@ import fetch from "node-fetch";
|
|
|
73
105
|
return `data:${mimeType};base64,${base64Image}`;
|
|
74
106
|
}
|
|
75
107
|
/**
|
|
76
|
-
* Resolve image to base64 data URI
|
|
77
|
-
* Handles both local files and URLs asynchronously
|
|
108
|
+
* Resolve image to base64 data URI.
|
|
109
|
+
* Handles both local files and URLs asynchronously.
|
|
110
|
+
* Uses magic-byte detection for the most accurate MIME type.
|
|
78
111
|
*/ export async function resolveImageToDataUri(imagePath) {
|
|
79
112
|
// If it's already a data URI, return as-is
|
|
80
113
|
if (isDataUri(imagePath)) {
|
|
@@ -88,8 +121,10 @@ import fetch from "node-fetch";
|
|
|
88
121
|
}
|
|
89
122
|
const arrayBuffer = await response.arrayBuffer();
|
|
90
123
|
const buffer = Buffer.from(arrayBuffer);
|
|
91
|
-
//
|
|
92
|
-
const
|
|
124
|
+
// Prefer magic-byte detection; fall back to the Content-Type header
|
|
125
|
+
const detectedMime = await detectMimeTypeFromBuffer(buffer);
|
|
126
|
+
const headerMime = response.headers.get("content-type") ? normalizeMimeType(response.headers.get("content-type")) : null;
|
|
127
|
+
const contentType = detectedMime ?? headerMime ?? "image/jpeg";
|
|
93
128
|
const base64Image = buffer.toString("base64");
|
|
94
129
|
return `data:${contentType};base64,${base64Image}`;
|
|
95
130
|
}
|
package/dist/utils/image.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/image.ts"],"sourcesContent":["import { readFileSync, existsSync } from \"fs\";\nimport fetch from \"node-fetch\";\n\n/**\n * Supported image MIME types\n */\nexport const SUPPORTED_IMAGE_TYPES = {\n png: \"image/png\",\n jpg: \"image/jpeg\",\n jpeg: \"image/jpeg\",\n webp: \"image/webp\",\n gif: \"image/gif\",\n} as const;\n\n/**\n * Get MIME type from file extension
|
|
1
|
+
{"version":3,"sources":["../../src/utils/image.ts"],"sourcesContent":["import { readFileSync, existsSync } from \"fs\";\nimport fetch from \"node-fetch\";\nimport { fileTypeFromBuffer } from \"file-type\";\n\n/**\n * Supported image MIME types\n */\nexport const SUPPORTED_IMAGE_TYPES = {\n png: \"image/png\",\n jpg: \"image/jpeg\",\n jpeg: \"image/jpeg\",\n jpe: \"image/jpeg\",\n webp: \"image/webp\",\n gif: \"image/gif\",\n avif: \"image/avif\",\n bmp: \"image/bmp\",\n tiff: \"image/tiff\",\n tif: \"image/tiff\",\n} as const;\n\n/**\n * Non-standard MIME aliases normalised to canonical form\n */\nconst MIME_ALIASES: Record<string, string> = {\n \"image/jpg\": \"image/jpeg\",\n \"image/jpe\": \"image/jpeg\",\n \"image/pjpeg\": \"image/jpeg\",\n \"image/x-png\": \"image/png\",\n \"image/x-bmp\": \"image/bmp\",\n \"image/x-ms-bmp\": \"image/bmp\",\n};\n\n/**\n * Normalise a raw MIME string: strip parameters (charset, etc.) and resolve\n * known non-standard aliases to their canonical equivalents.\n */\nexport function normalizeMimeType(raw: string): string {\n const base = raw.split(\";\")[0].trim().toLowerCase();\n return MIME_ALIASES[base] ?? base;\n}\n\n/**\n * Get MIME type from file extension (normalised).\n * Falls back gracefully for unknown extensions.\n */\nexport function getMimeTypeFromExtension(filePath: string): string {\n const ext = filePath.toLowerCase().split(\".\").pop() || \"\";\n return SUPPORTED_IMAGE_TYPES[ext as keyof typeof SUPPORTED_IMAGE_TYPES] ?? \"image/octet-stream\";\n}\n\n/**\n * Detect MIME type from buffer magic bytes via the file-type library.\n * Returns the canonical (normalised) MIME type, or null if unrecognised.\n */\nexport async function detectMimeTypeFromBuffer(buffer: Buffer): Promise<string | null> {\n const result = await fileTypeFromBuffer(buffer);\n if (!result) return null;\n return normalizeMimeType(result.mime);\n}\n\n/**\n * Check if a string is a URL\n */\nexport function isUrl(input: string): boolean {\n return input.startsWith(\"http://\") || input.startsWith(\"https://\");\n}\n\n/**\n * Check if a string is a base64 data URI\n */\nexport function isDataUri(input: string): boolean {\n return input.startsWith(\"data:image\");\n}\n\n/**\n * Validate image path or URL\n */\nexport function validateImageInput(input: string): { valid: boolean; error?: string } {\n if (!input || input.trim() === \"\") {\n return { valid: false, error: \"Image path or URL is required\" };\n }\n\n const cleanInput = input.trim();\n\n // Check if it's a URL\n if (isUrl(cleanInput)) {\n return { valid: true };\n }\n\n // Check if it's already a data URI\n if (isDataUri(cleanInput)) {\n return { valid: true };\n }\n\n // Check if it's a local file\n if (!existsSync(cleanInput)) {\n return { valid: false, error: `File not found: ${cleanInput}` };\n }\n\n return { valid: true };\n}\n\n/**\n * Convert image to base64 data URI\n * Supports local files, URLs, and data URIs\n */\nexport function encodeImageToDataUri(imagePath: string): string {\n // If it's already a URL or data URI, return as-is\n if (isUrl(imagePath) || isDataUri(imagePath)) {\n return imagePath;\n }\n\n // Read local file and encode to base64\n const fileBuffer = readFileSync(imagePath);\n const mimeType = getMimeTypeFromExtension(imagePath);\n const base64Image = fileBuffer.toString(\"base64\");\n\n return `data:${mimeType};base64,${base64Image}`;\n}\n\n/**\n * Resolve image to base64 data URI.\n * Handles both local files and URLs asynchronously.\n * Uses magic-byte detection for the most accurate MIME type.\n */\nexport async function resolveImageToDataUri(imagePath: string): Promise<string> {\n // If it's already a data URI, return as-is\n if (isDataUri(imagePath)) {\n return imagePath;\n }\n\n // If it's a URL, fetch it\n if (isUrl(imagePath)) {\n const response = await fetch(imagePath);\n if (!response.ok) {\n throw new Error(`Failed to fetch image from URL: ${response.statusText}`);\n }\n\n const arrayBuffer = await response.arrayBuffer();\n const buffer = Buffer.from(arrayBuffer);\n\n // Prefer magic-byte detection; fall back to the Content-Type header\n const detectedMime = await detectMimeTypeFromBuffer(buffer);\n const headerMime = response.headers.get(\"content-type\")\n ? normalizeMimeType(response.headers.get(\"content-type\")!)\n : null;\n const contentType = detectedMime ?? headerMime ?? \"image/jpeg\";\n\n const base64Image = buffer.toString(\"base64\");\n return `data:${contentType};base64,${base64Image}`;\n }\n\n // Fallback to local file encoding\n return encodeImageToDataUri(imagePath);\n}\n\n/**\n * Extract base64 data from data URI (for Google API)\n */\nexport function extractBase64FromDataUri(dataUri: string): {\n mimeType: string;\n base64Data: string;\n} {\n if (!isDataUri(dataUri)) {\n throw new Error(\"Input is not a data URI\");\n }\n\n const [header, base64Data] = dataUri.split(\",\");\n const mimeType = header.split(\";\")[0].split(\":\")[1] || \"image/jpeg\";\n\n return { mimeType, base64Data };\n}\n"],"names":["readFileSync","existsSync","fetch","fileTypeFromBuffer","SUPPORTED_IMAGE_TYPES","png","jpg","jpeg","jpe","webp","gif","avif","bmp","tiff","tif","MIME_ALIASES","normalizeMimeType","raw","base","split","trim","toLowerCase","getMimeTypeFromExtension","filePath","ext","pop","detectMimeTypeFromBuffer","buffer","result","mime","isUrl","input","startsWith","isDataUri","validateImageInput","valid","error","cleanInput","encodeImageToDataUri","imagePath","fileBuffer","mimeType","base64Image","toString","resolveImageToDataUri","response","ok","Error","statusText","arrayBuffer","Buffer","from","detectedMime","headerMime","headers","get","contentType","extractBase64FromDataUri","dataUri","header","base64Data"],"mappings":"AAAA,SAASA,YAAY,EAAEC,UAAU,QAAQ,KAAK;AAC9C,OAAOC,WAAW,aAAa;AAC/B,SAASC,kBAAkB,QAAQ,YAAY;AAE/C;;CAEC,GACD,OAAO,MAAMC,wBAAwB;IACnCC,KAAK;IACLC,KAAK;IACLC,MAAM;IACNC,KAAK;IACLC,MAAM;IACNC,KAAK;IACLC,MAAM;IACNC,KAAK;IACLC,MAAM;IACNC,KAAK;AACP,EAAW;AAEX;;CAEC,GACD,MAAMC,eAAuC;IAC3C,aAAa;IACb,aAAa;IACb,eAAe;IACf,eAAe;IACf,eAAe;IACf,kBAAkB;AACpB;AAEA;;;CAGC,GACD,OAAO,SAASC,kBAAkBC,GAAW;IAC3C,MAAMC,OAAOD,IAAIE,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AUmB;IAAW;AAChC"}
|
package/dist/version.js
CHANGED
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/version.ts"],"sourcesContent":["// This file is auto-generated. Do not edit manually.\nexport const CLAWBR_VERSION = \"0.0.
|
|
1
|
+
{"version":3,"sources":["../src/version.ts"],"sourcesContent":["// This file is auto-generated. Do not edit manually.\nexport const CLAWBR_VERSION = \"0.0.44\";\n"],"names":["CLAWBR_VERSION"],"mappings":"AAAA,qDAAqD;AACrD,OAAO,MAAMA,iBAAiB,SAAS"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clawbr",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.44",
|
|
4
4
|
"description": "Official CLI for clawbr - Tumblr for AI agents. Full social interaction: post, like, comment, quote, and browse feeds.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"chalk": "^5.3.0",
|
|
42
42
|
"commander": "^12.0.0",
|
|
43
43
|
"dotenv": "^16.6.1",
|
|
44
|
+
"file-type": "^21.3.0",
|
|
44
45
|
"form-data": "^4.0.5",
|
|
45
46
|
"inquirer": "^9.2.12",
|
|
46
47
|
"nest-commander": "^3.20.1",
|
|
@@ -65,5 +66,11 @@
|
|
|
65
66
|
},
|
|
66
67
|
"engines": {
|
|
67
68
|
"node": ">=22.0.0"
|
|
69
|
+
},
|
|
70
|
+
"overrides": {
|
|
71
|
+
"minimatch": "^10.2.1",
|
|
72
|
+
"@angular-devkit/core": {
|
|
73
|
+
"ajv": "^8.18.0"
|
|
74
|
+
}
|
|
68
75
|
}
|
|
69
76
|
}
|