mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
nodejs: onRequestSaveAs event
This commit is contained in:
committed by
Sergey Linnik
parent
70836bb67d
commit
1cd275188b
@ -224,6 +224,54 @@ app.post("/upload", function (req, res) { // define a handler for uploading fil
|
||||
});
|
||||
});
|
||||
|
||||
app.post("/create", function (req, res) {
|
||||
var title = req.body.title;
|
||||
var fileUrl = req.body.url;
|
||||
|
||||
try {
|
||||
docManager.init(storageFolder, req, res);
|
||||
docManager.storagePath(""); // mkdir if not exist
|
||||
|
||||
var fileName = docManager.getCorrectName(title);
|
||||
var userAddress = docManager.curUserHostAddress();
|
||||
docManager.historyPath(fileName, userAddress, true);
|
||||
|
||||
urllib.request(fileUrl, {method: "GET"},function(err, data) {
|
||||
if (configServer.get("maxFileSize") < data.length || data.length <= 0) { // check if the file size exceeds the maximum file size
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.write(JSON.stringify({ "error": "File size is incorrect" }));
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
const exts = [].concat(configServer.get("viewedDocs"), configServer.get("editedDocs"), configServer.get("convertedDocs")); // all the supported file extensions
|
||||
const curExt = fileUtility.getFileExtension(fileName);
|
||||
|
||||
if (exts.indexOf(curExt) == -1) { // check if the file extension is supported
|
||||
res.writeHead(200, { "Content-Type": "application/json" }); // and write the error status and message to the response
|
||||
res.write(JSON.stringify({ "error": "File type is not supported" }));
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
fileSystem.writeFileSync(docManager.storagePath(fileName), data);
|
||||
|
||||
res.writeHead(200, { "Content-Type": "application/json" });
|
||||
res.write(JSON.stringify({ "file" : fileName }));
|
||||
res.end();
|
||||
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
res.status(500);
|
||||
res.write(JSON.stringify({
|
||||
error: 1,
|
||||
message: e.message
|
||||
}));
|
||||
res.end();
|
||||
}
|
||||
});
|
||||
|
||||
app.post("/convert", function (req, res) { // define a handler for converting files
|
||||
|
||||
var fileName = fileUtility.getFileName(req.body.filename);
|
||||
|
||||
Reference in New Issue
Block a user