Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

V1 - Export Files from Dev-App #130

Merged
merged 2 commits into from
Jul 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions client/js/controllers/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,45 @@
}
};

var saveFile = (function () {
var a = document.createElement('a');
document.body.appendChild(a);
a.style = 'display: none';
return function (blob, file_name) {
var url = window.URL.createObjectURL(blob);
a.href = url;
a.download = file_name;
a.click();
setTimeout( function() {
window.URL.revokeObjectURL(url);
}, 100);
};
}());

$scope.exportFile = function () {
var file = filePath;
if (file) {
if (isLeaf) {
$http.get('/api/file/download',
{ params: { "file": file },
responseType: "arraybuffer"
}).success( function (data, status, headers, config) {
var f = headers('Content-Disposition').match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g);
var file_name = String(f).split('=').pop().slice(1, -1);
var mime_type = headers('Content-Type');
var blob = new Blob([data], { type: String(mime_type) });
saveFile(blob, file_name);
}).error( function (data, status, headers, config) {
alert('Error: Unable to Download File');
});
} else {
alert('Error: Cannot Download Folder');
}
} else {
alert('Please select File first!');
}
};

$scope.remove = function () {
if (filePath) {
var file_name = filePath.split("/").pop();
Expand Down Expand Up @@ -1100,6 +1139,9 @@
case "file.importfile":
$scope.importFile();
break;
case "file.exportfile":
$scope.exportFile();
break;
case "file.remove":
$scope.remove();
break;
Expand Down
14 changes: 14 additions & 0 deletions server/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,20 @@
})
});

router.get('/api/file/download', function(req, res) {
var file_path = req.query.file;
if ( file_path.search('soletta-dev-app/repos') > -1 ) {
var file_name = file_path.split('/').pop();
if (fs.statSync(file_path)) {
res.download(file_path, file_name);
} else {
res.sendStatus(400);
}
} else {
res.sendStatus(400);
}
});

router.post('/api/git/repo/delete/file', function (req, res) {
var file_path = req.body.params.file_path;
if (!file_path) {
Expand Down
5 changes: 5 additions & 0 deletions server/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@
<md-button ng-click="ctrl.menuAction('file.importfile', $event)">
Import File
</md-button>
</md-menu-item>
<md-menu-item>
<md-button ng-click="ctrl.menuAction('file.exportfile', $event)">
Export File
</md-button>
</md-menu-item>
<md-menu-divider></md-menu-divider>
<md-menu-item>
Expand Down