mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-02-10 18:05:10 +08:00
nodejs: delete file
This commit is contained in:
@ -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);
|
||||
|
||||
BIN
web/documentserver-example/nodejs/public/images/delete-24.png
Normal file
BIN
web/documentserver-example/nodejs/public/images/delete-24.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@ -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"
|
||||
|
||||
@ -482,3 +482,7 @@ footer {
|
||||
.icon-download {
|
||||
margin-bottom: -5px;
|
||||
}
|
||||
.icon-delete {
|
||||
cursor: pointer;
|
||||
margin-bottom: -6px;
|
||||
}
|
||||
|
||||
@ -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">
|
||||
|
||||
Reference in New Issue
Block a user