MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / getFileOrFolderPathFromText

Function getFileOrFolderPathFromText

cli/src/utils/clipboard-image.ts:318–353  ·  view source on GitHub ↗
(text: string, cwd: string)

Source from the content-addressed store, hash-verified

316 * Returns the resolved path and whether it's a directory, or null.
317 */
318export function getFileOrFolderPathFromText(text: string, cwd: string): { path: string; isDirectory: boolean } | null {
319 // Must be single line
320 if (text.includes('\n') || text.includes('\r')) return null
321
322 let trimmed = text.trim()
323 if (!trimmed) return null
324
325 // Handle file:// URLs
326 if (trimmed.startsWith('file://')) {
327 trimmed = decodeURIComponent(trimmed.slice(7))
328 }
329
330 // Skip other URLs
331 if (trimmed.includes('://')) return null
332
333 // Remove surrounding quotes
334 if ((trimmed.startsWith('"') && trimmed.endsWith('"')) ||
335 (trimmed.startsWith("'") && trimmed.endsWith("'"))) {
336 trimmed = trimmed.slice(1, -1)
337 }
338
339 try {
340 const resolvedPath = resolveFilePath(trimmed, cwd)
341 if (!existsSync(resolvedPath)) return null
342 // Skip images — they're handled by image-specific logic
343 if (isImageFile(resolvedPath)) return null
344
345 const stats = statSync(resolvedPath)
346 return {
347 path: resolvedPath,
348 isDirectory: stats.isDirectory(),
349 }
350 } catch {
351 return null
352 }
353}
354
355/**
356 * Check if text looks like a single file path pointing to an existing image.

Callers 1

createPasteHandlerFunction · 0.90

Calls 2

resolveFilePathFunction · 0.90
isImageFileFunction · 0.90

Tested by

no test coverage detected