sitepaige-mcp-server 1.2.3 → 1.2.5

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.
@@ -1,160 +0,0 @@
1
- /*
2
- Sitepaige v1.0.0
3
- WARNING: This file is automatically generated and should not be modified.
4
- */
5
-
6
- import fs from 'fs/promises';
7
- import path from 'path';
8
- import { randomBytes } from 'crypto';
9
-
10
- // File storage for the application
11
- const fileStorage: { [key: string]: string } = {};
12
- const fileNames: { [key: string]: string } = {};
13
-
14
- /**
15
- * Get the files storage path
16
- * Uses EFS_MOUNT_PATH for production (in container with EFS) or SQLITE_DIR for local development
17
- */
18
- function getFilesStoragePath(): string {
19
- const efsMountPath = process.env.EFS_MOUNT_PATH;
20
- const sqliteDir = process.env.SQLITE_DIR || '.';
21
-
22
- if (efsMountPath) {
23
- // In production with EFS
24
- return path.join(efsMountPath, 'files');
25
- } else {
26
- // In local development - use a separate files directory
27
- return path.join(sqliteDir, 'files');
28
- }
29
- }
30
-
31
- /**
32
- * Store file function that writes files to the filesystem and returns a reference
33
- * @param filename The original filename
34
- * @param filedata Base64 encoded file data
35
- * @param isImage Whether this is an image file
36
- * @returns Promise that resolves to a file reference string (path starting with /files/)
37
- */
38
- export async function store_file(filename: string, filedata: string, isImage: boolean): Promise<string> {
39
- console.log(`📁 Storing ${isImage ? 'image' : 'file'}: ${filename} (${filedata.length} bytes)`);
40
-
41
- try {
42
- // Generate a unique key for this file
43
- const fileKey = `${Date.now()}_${randomBytes(6).toString('hex')}`;
44
-
45
- // Determine file extension
46
- const extension = path.extname(filename) || (isImage ? '.png' : '.bin');
47
- const safeFilename = `${fileKey}${extension}`;
48
-
49
- // Get storage directory and create subdirectories if needed
50
- const storageBasePath = getFilesStoragePath();
51
- const storageDir = path.join(storageBasePath, isImage ? 'images' : 'documents');
52
- await fs.mkdir(storageDir, { recursive: true });
53
-
54
- // Write file to filesystem
55
- const filePath = path.join(storageDir, safeFilename);
56
- const buffer = Buffer.from(filedata, 'base64');
57
- await fs.writeFile(filePath, buffer);
58
-
59
- // Store metadata
60
- fileStorage[fileKey] = filePath;
61
- fileNames[fileKey] = filename;
62
-
63
- console.log(`✅ File stored successfully: ${filePath}`);
64
-
65
- // Return the public path that will be used to access the file
66
- // This path starts with /files/ and matches what the API route will serve
67
- const publicPath = `/files/${isImage ? 'images' : 'documents'}/${safeFilename}`;
68
- return publicPath;
69
- } catch (error) {
70
- console.error('❌ Error storing file:', error);
71
- throw new Error(`Failed to store file: ${error}`);
72
- }
73
- }
74
-
75
- /**
76
- * Get the filesystem path for a stored file
77
- * @param fileKey The file key returned from store_file
78
- * @returns The filesystem path or undefined if not found
79
- */
80
- export function getStoredFilePath(fileKey: string): string | undefined {
81
- return fileStorage[fileKey];
82
- }
83
-
84
- /**
85
- * Get the original filename for a stored file
86
- * @param fileKey The file key returned from store_file
87
- * @returns The original filename or undefined if not found
88
- */
89
- export function getStoredFileName(fileKey: string): string | undefined {
90
- return fileNames[fileKey];
91
- }
92
-
93
- /**
94
- * Get the file data as base64 for a stored file
95
- * @param fileKey The file key returned from store_file
96
- * @returns Promise that resolves to base64 file data or undefined if not found
97
- */
98
- export async function getStoredFileData(fileKey: string): Promise<string | undefined> {
99
- const filePath = fileStorage[fileKey];
100
- if (!filePath) {
101
- return undefined;
102
- }
103
-
104
- try {
105
- const buffer = await fs.readFile(filePath);
106
- return buffer.toString('base64');
107
- } catch (error) {
108
- console.error('Error reading stored file:', error);
109
- return undefined;
110
- }
111
- }
112
-
113
- /**
114
- * Delete a stored file from the filesystem
115
- * @param fileKey The file key returned from store_file
116
- * @returns Promise that resolves to true if deleted, false if not found
117
- */
118
- export async function deleteStoredFile(fileKey: string): Promise<boolean> {
119
- const filePath = fileStorage[fileKey];
120
- if (!filePath) {
121
- return false;
122
- }
123
-
124
- try {
125
- await fs.unlink(filePath);
126
- delete fileStorage[fileKey];
127
- delete fileNames[fileKey];
128
- console.log(`🗑️ File deleted: ${filePath}`);
129
- return true;
130
- } catch (error) {
131
- console.error('Error deleting stored file:', error);
132
- return false;
133
- }
134
- }
135
-
136
- /**
137
- * List all stored files
138
- * @returns Array of objects containing file information
139
- */
140
- export function listStoredFiles(): Array<{fileKey: string, filename: string, path: string}> {
141
- return Object.keys(fileStorage).map(fileKey => ({
142
- fileKey,
143
- filename: fileNames[fileKey],
144
- path: fileStorage[fileKey]
145
- }));
146
- }
147
-
148
- /**
149
- * Initialize global store_file function for generated API code
150
- * This makes store_file available in the same way as the preview environment
151
- */
152
- export function initializeGlobalStorageAPI(): void {
153
- // Make store_file available globally for API code execution
154
- (global as any).store_file = store_file;
155
- (global as any).getStoredFilePath = getStoredFilePath;
156
- (global as any).getStoredFileName = getStoredFileName;
157
- (global as any).getStoredFileData = getStoredFileData;
158
-
159
- console.log('✅ Global storage API initialized');
160
- }