MCPcopy
hub / github.com/Doorman11991/smallcode / detectDroppedFile

Function detectDroppedFile

src/session/images.js:99–114  ·  view source on GitHub ↗

* Detect if input is just a file path (from drag-and-drop into terminal). * Returns the cleaned path or null.

(input)

Source from the content-addressed store, hash-verified

97 * Returns the cleaned path or null.
98 */
99function detectDroppedFile(input) {
100 const trimmed = input.trim().replace(/^["']|["']$/g, ''); // Strip quotes terminals sometimes add
101
102 // Check if it looks like a file path (absolute or relative with image extension)
103 const ext = require('path').extname(trimmed).toLowerCase();
104 if (!IMAGE_EXTENSIONS.includes(ext)) return null;
105
106 // Must look like a path (has slashes or starts with drive letter)
107 if (trimmed.includes('/') || trimmed.includes('\\') || /^[A-Z]:/i.test(trimmed) || trimmed.startsWith('.')) {
108 const fs = require('fs');
109 const resolved = require('path').resolve(trimmed);
110 if (fs.existsSync(resolved)) return resolved;
111 }
112
113 return null;
114}
115
116module.exports = { extractImages, formatImagesForAPI, modelSupportsVision, detectDroppedFile, IMAGE_EXTENSIONS };

Callers 1

runAgentLoopFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected