mastercontroller 1.2.12 → 1.2.13

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,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
- // }