nodejs: delete file

This commit is contained in:
Sergey Linnik
2016-03-29 17:56:26 +03:00
parent f64f3a25f1
commit a25892219c
5 changed files with 57 additions and 0 deletions

View File

@ -227,6 +227,41 @@ app.get("/convert", function (req, res) {
});
app.delete("/file", function (req, res) {
try {
docManager.init(__dirname, req, res);
var fileName = req.query.filename;
var filePath = docManager.storagePath(fileName)
fileSystem.unlinkSync(filePath);
var userAddress = docManager.curUserHostAddress();
var historyPath = docManager.historyPath(fileName, userAddress, true);
var deleteFolderRecursive = function (path) {
if (fileSystem.existsSync(path)) {
var files = fileSystem.readdirSync(path);
files.forEach(function (file, index) {
var curPath = path + "/" + file;
if (fileSystem.lstatSync(curPath).isDirectory()) {
deleteFolderRecursive(curPath);
} else {
fileSystem.unlinkSync(curPath);
}
});
fileSystem.rmdirSync(path);
}
};
deleteFolderRecursive(historyPath);
res.write("{\"success\":true}");
} catch (ex) {
res.write(JSON.stringify(ex));
}
res.end();
});
app.post("/track", function (req, res) {
docManager.init(__dirname, req, res);

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -262,6 +262,22 @@ if (typeof jQuery != "undefined") {
jq.unblockUI();
});
jq(document).on("click", ".delete-file", function () {
var fileName = jq(this).attr("data");
var requestAddress = "file?filename=" + fileName;
jq.ajax({
async: true,
contentType: "text/xml",
type: "delete",
url: requestAddress,
complete: function (data) {
document.location.reload();
}
});
});
jq.dropdownToggle({
switcherSelector: ".question",
dropdownID: "hint"

View File

@ -482,3 +482,7 @@ footer {
.icon-download {
margin-bottom: -5px;
}
.icon-delete {
cursor: pointer;
margin-bottom: -6px;
}

View File

@ -183,6 +183,8 @@
<span title="<%= storedFiles[i].url %>"><%= storedFiles[i].name %></span></a>
<a href="<%= storedFiles[i].url %>">
<img class="icon-download" src="images/download-24.png" alt="download" /></a>
<a class="delete-file" data="<%= encodeURIComponent(storedFiles[i].name) %>">
<img class="icon-delete" src="images/delete-24.png" alt="delete" /></a>
</td>
<td class="contentCells contentCells-icon">
<a href="editor?fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">