aboutsummaryrefslogtreecommitdiff
path: root/js/io/system/fileio.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/system/fileio.js')
-rwxr-xr-xjs/io/system/fileio.js68
1 files changed, 65 insertions, 3 deletions
diff --git a/js/io/system/fileio.js b/js/io/system/fileio.js
index 7bf4d41f..045fa2fd 100755
--- a/js/io/system/fileio.js
+++ b/js/io/system/fileio.js
@@ -64,13 +64,40 @@ exports.FileIo = Montage.create(Component, {
64 // 64 //
65 readFile: { 65 readFile: {
66 enumerable: true, 66 enumerable: true,
67 value: function() { 67 value: function(file) {
68 //Checking for API to be available 68 //Checking for API to be available
69 if (!this.application.ninja.coreIoApi.cloudAvailable()) { 69 if (!this.application.ninja.coreIoApi.cloudAvailable()) {
70 //API not available, no IO action taken 70 //API not available, no IO action taken
71 return null; 71 return null;
72 } 72 }
73 // 73 //Peforming check for file to exist
74 var check = this.application.ninja.coreIoApi.fileExists({uri: file.uri}), status, create, result;
75 //Upon successful check, handling results
76 if (check.success) {
77 //Handling status of check
78 switch (check.status) {
79 case 204:
80 //File exists
81 result = {};
82 result.content = this.application.ninja.coreIoApi.readFile(file).content;
83 result.details = this.infoFile(file);
84 status = check.status;
85 break;
86 case 404:
87 //File does not exists, ready to be created
88 status = check.status;
89 break;
90 default:
91 //Unknown Error
92 status = 500;
93 break;
94 }
95 } else {
96 //Unknown Error
97 status = 500;
98 }
99 //Returning resulting code
100 return {status: status, file: result};
74 } 101 }
75 }, 102 },
76 //////////////////////////////////////////////////////////////////// 103 ////////////////////////////////////////////////////////////////////
@@ -116,14 +143,49 @@ exports.FileIo = Montage.create(Component, {
116 // 143 //
117 infoFile: { 144 infoFile: {
118 enumerable: true, 145 enumerable: true,
119 value: function() { 146 value: function(file) {
120 //Checking for API to be available 147 //Checking for API to be available
121 if (!this.application.ninja.coreIoApi.cloudAvailable()) { 148 if (!this.application.ninja.coreIoApi.cloudAvailable()) {
122 //API not available, no IO action taken 149 //API not available, no IO action taken
123 return null; 150 return null;
124 } 151 }
125 // 152 //
153 var check = this.application.ninja.coreIoApi.fileExists({uri: file.uri}), details;
154 //
155 if (check.success) {
156 //Handling status of check
157 switch (check.status) {
158 case 204:
159 //File exists
160 details = JSON.parse(this.application.ninja.coreIoApi.isFileWritable(file).content);
161 details.uri = file.uri;
162 details.name = this.getFileNameFromPath(file.uri);
163 details.extension = details.name.split('.')[details.name.split('.').length-1];
164 break;
165 case 404:
166 //File does not exists, ready to be created
167
168 break;
169 default:
170 //Unknown Error
171
172 break;
173 }
174 } else {
175 //Unknown Error
176
177 }
178 return details;
126 } 179 }
180 },
181 ////////////////////////////////////////////////////////////////////
182 //
183 getFileNameFromPath : {
184 value: function(path) {
185 path = path.replace(/[/\\]$/g,"");
186 path = path.replace(/\\/g,"/");
187 return path.substr(path.lastIndexOf('/') + 1);
188 }
127 } 189 }
128 //////////////////////////////////////////////////////////////////// 190 ////////////////////////////////////////////////////////////////////
129 //////////////////////////////////////////////////////////////////// 191 ////////////////////////////////////////////////////////////////////