-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreviewFile.js
More file actions
63 lines (52 loc) · 1.69 KB
/
previewFile.js
File metadata and controls
63 lines (52 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// ===================================================================
// Handler Function: processFile
// ===================================================================
// Import shared functions
const shared = require('sharedFunctions');
function previewFile(params) {
var pathValidation = shared.validateFilePath(params.filePath || "", "filePath");
var filePath;
var content;
var lines;
var wordCount;
var result;
if (!pathValidation.ok) {
return shared.setErrorResult(pathValidation.message, {
operation: "previewFile"
});
}
filePath = pathValidation.value;
console.log("Processing file: " + filePath);
// Check if file exists
if (!MCPStudio.fileExists(filePath)) {
return shared.setErrorResult("File not found: " + filePath, {
operation: "previewFile",
filePath: filePath
});
}
// Read file content
content = MCPStudio.readFile(filePath);
if (content === null) {
return shared.setErrorResult("Failed to read file: " + filePath, {
operation: "previewFile",
filePath: filePath
});
}
// Process the content (example: count lines and words)
lines = content.split('\n');
wordCount = content.split(/\s+/).filter(function(w) { return w.length > 0; }).length;
result = {
filePath: filePath,
lineCount: lines.length,
wordCount: wordCount,
charCount: content.length,
preview: lines.slice(0, 10).join('\n')
};
return shared.setSuccessResult(result, {
filePath: filePath,
operation: "previewFile"
});
}
module.exports = {
previewFile
};