mastercontroller 1.2.12 → 1.2.14
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.
- package/.claude/settings.local.json +12 -0
- package/MasterAction.js +297 -73
- package/MasterControl.js +112 -19
- package/MasterHtml.js +101 -14
- package/MasterRouter.js +281 -66
- package/MasterTemplate.js +96 -3
- package/README.md +0 -44
- package/error/ErrorBoundary.js +353 -0
- package/error/HydrationMismatch.js +265 -0
- package/error/MasterBackendErrorHandler.js +769 -0
- package/{MasterError.js → error/MasterError.js} +2 -2
- package/error/MasterErrorHandler.js +487 -0
- package/error/MasterErrorLogger.js +360 -0
- package/error/MasterErrorMiddleware.js +407 -0
- package/error/SSRErrorHandler.js +273 -0
- package/monitoring/MasterCache.js +400 -0
- package/monitoring/MasterMemoryMonitor.js +188 -0
- package/monitoring/MasterProfiler.js +409 -0
- package/monitoring/PerformanceMonitor.js +233 -0
- package/package.json +3 -3
- package/security/CSPConfig.js +319 -0
- package/security/EventHandlerValidator.js +464 -0
- package/security/MasterSanitizer.js +429 -0
- package/security/MasterValidator.js +546 -0
- package/security/SecurityMiddleware.js +486 -0
- package/security/SessionSecurity.js +416 -0
- package/ssr/hydration-client.js +93 -0
- package/ssr/runtime-ssr.cjs +553 -0
- package/ssr/ssr-shims.js +73 -0
- package/examples/FileServingExample.js +0 -88
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
// Example: Binary File Serving with MasterController
|
|
2
|
-
//
|
|
3
|
-
// This example demonstrates how to use the returnFile() method
|
|
4
|
-
// to serve binary files in your MasterController application.
|
|
5
|
-
|
|
6
|
-
class ExampleController extends MasterAction {
|
|
7
|
-
|
|
8
|
-
// Example 1: Serve a PDF file for download
|
|
9
|
-
downloadPdf(){
|
|
10
|
-
var filePath = master.root + '/storage/documents/report.pdf';
|
|
11
|
-
this.returnFile(filePath);
|
|
12
|
-
// Downloads as 'report.pdf' with auto-detected content-type
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Example 2: Display an image inline
|
|
16
|
-
showImage(){
|
|
17
|
-
var filePath = master.root + '/storage/images/photo.jpg';
|
|
18
|
-
this.returnFile(filePath, {
|
|
19
|
-
disposition: 'inline' // Display in browser instead of download
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Example 3: Serve file with custom filename
|
|
24
|
-
downloadReport(){
|
|
25
|
-
var filePath = master.root + '/storage/reports/monthly-2024-01.pdf';
|
|
26
|
-
this.returnFile(filePath, {
|
|
27
|
-
filename: 'January_Report.pdf' // Custom filename for download
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Example 4: Serve file with explicit content type
|
|
32
|
-
downloadCsv(){
|
|
33
|
-
var filePath = master.root + '/storage/exports/data.csv';
|
|
34
|
-
this.returnFile(filePath, {
|
|
35
|
-
contentType: 'text/csv',
|
|
36
|
-
filename: 'export.csv'
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Example 5: Serve dynamic file based on user request
|
|
41
|
-
downloadUserFile(){
|
|
42
|
-
var fileId = this.params.id;
|
|
43
|
-
var filePath = master.root + '/storage/user-files/' + fileId;
|
|
44
|
-
|
|
45
|
-
// You might want to add authentication/authorization checks here
|
|
46
|
-
// if (this.session.userId !== file.ownerId) { ... }
|
|
47
|
-
|
|
48
|
-
this.returnFile(filePath, {
|
|
49
|
-
filename: 'user-document.pdf'
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Example 6: Serve images inline (for img src tags)
|
|
54
|
-
serveUserAvatar(){
|
|
55
|
-
var userId = this.params.id;
|
|
56
|
-
var avatarPath = master.root + '/storage/avatars/' + userId + '.png';
|
|
57
|
-
this.returnFile(avatarPath, {
|
|
58
|
-
disposition: 'inline',
|
|
59
|
-
contentType: 'image/png'
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
module.exports = ExampleController;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// Supported MIME types (auto-detected by file extension):
|
|
69
|
-
//
|
|
70
|
-
// Images: jpg, jpeg, png, gif, svg
|
|
71
|
-
// Documents: pdf, doc, docx, xls, xlsx, ppt, pptx
|
|
72
|
-
// Data: csv, json, xml, txt
|
|
73
|
-
// Archives: zip
|
|
74
|
-
// Media: mp3, mp4, wav
|
|
75
|
-
//
|
|
76
|
-
// For other file types, use contentType option or files will be served as 'application/octet-stream'
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// Route configuration example:
|
|
80
|
-
// In your routes.js:
|
|
81
|
-
//
|
|
82
|
-
// {
|
|
83
|
-
// "url" : "/download/pdf",
|
|
84
|
-
// "namespace" : "example",
|
|
85
|
-
// "controller" : "ExampleController",
|
|
86
|
-
// "action" : "downloadPdf",
|
|
87
|
-
// "type" : "GET"
|
|
88
|
-
// }
|