nodejs: add ability to use custom path for storage-folder

This commit is contained in:
Oleg Sinizin
2021-09-24 17:52:00 +03:00
parent 04f5cac85d
commit 69ac7771d5
3 changed files with 25 additions and 7 deletions

View File

@ -19,10 +19,14 @@ Download the [Node.js example](https://api.onlyoffice.com/editors/demopreview) f
You need to connect the editors to your website. Specify the path to the editors installation in the *config/default.json* file: You need to connect the editors to your website. Specify the path to the editors installation in the *config/default.json* file:
``` ```
"storageFolder": "./files"
"storagePath": "/files"
"siteUrl": "https://documentserver/" "siteUrl": "https://documentserver/"
``` ```
where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed. where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed.
**storageFolder** and **storagePath** is the path where files will created and stored, you can set an absolute path, for example **D:\\\\folder**.
Note, use double backslash as separator.
If you want to experiment with the editor configuration, modify the [parameters](https://api.onlyoffice.com/editors/advanced) in the *\views\editor.ejs* file. If you want to experiment with the editor configuration, modify the [parameters](https://api.onlyoffice.com/editors/advanced) in the *\views\editor.ejs* file.
@ -117,10 +121,18 @@ See the detailed guide to learn how to [install Document Server for Linux](https
Edit the following line: Edit the following line:
``` ```
"storageFolder": "./files"
"storagePath": "/files"
"siteUrl": "https://documentserver/" "siteUrl": "https://documentserver/"
``` ```
where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed. where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed.
**storageFolder** and **storagePath** is the path where files will created and stored.
Note, you must have read and write permissions to folder.
If not, please, use next command:
```
sudo chmod -R ugo+rw /{path}
```
6. Run the project with Node.js: 6. Run the project with Node.js:

View File

@ -729,7 +729,8 @@ app.get("/editor", function (req, res) { // define a handler for editing docume
key: historyData[i-2].key, key: historyData[i-2].key,
url: historyData[i-2].url, url: historyData[i-2].url,
}; };
historyD.changesUrl = docManager.getlocalFileUri(fileName, i-1) + "/diff.zip"; // get the path to the diff.zip file and write it to the history object let changesUrl = docManager.getlocalFileUri(fileName, i-1);
historyD.changesUrl = changesUrl.includes("diff.zip") ? changesUrl : changesUrl + "/diff.zip"; // get the path to the diff.zip file and write it to the history object
} }
historyData.push(historyD); historyData.push(historyD);

View File

@ -151,7 +151,12 @@ docManager.getFileUri = function (fileName) {
docManager.getlocalFileUri = function (fileName, version, forDocumentServer) { docManager.getlocalFileUri = function (fileName, version, forDocumentServer) {
const serverPath = docManager.getServerUrl(forDocumentServer); const serverPath = docManager.getServerUrl(forDocumentServer);
const hostAddress = docManager.curUserHostAddress(); const hostAddress = docManager.curUserHostAddress();
const url = serverPath + configServer.get("storagePath") + "/" + hostAddress + "/" + encodeURIComponent(fileName); // get full url address to the file let url = serverPath + configServer.get("storagePath") + "/" + hostAddress + "/" + encodeURIComponent(fileName); // get full url address to the file
if (path.isAbsolute(configServer.get("storageFolder"))) {
let separator = configServer.get("storagePath").includes("/") ? "/" : "\\";
url = docManager.getDownloadUrl(fileName + "-history" + separator + version + separator + "diff.zip");
return url;
}
if (!version) { if (!version) {
return url; return url;
} }
@ -193,14 +198,14 @@ docManager.getDownloadUrl = function (fileName) {
// get the storage path of the given file // get the storage path of the given file
docManager.storagePath = function (fileName, userAddress) { docManager.storagePath = function (fileName, userAddress) {
fileName = fileUtility.getFileName(fileName); // get the file name with extension fileName = fileUtility.getFileName(fileName); // get the file name with extension
const directory = path.join(docManager.dir, docManager.curUserHostAddress(userAddress)); // get the path to the directory for the host address const directory = path.isAbsolute(docManager.dir) ? docManager.dir : path.join(docManager.dir, docManager.curUserHostAddress(userAddress)); // get the path to the directory for the host address
this.createDirectory(directory); // create a new directory if it doesn't exist this.createDirectory(directory); // create a new directory if it doesn't exist
return path.join(directory, fileName); // put the given file to this directory return path.join(directory, fileName); // put the given file to this directory
}; };
// get the path to the forcesaved file version // get the path to the forcesaved file version
docManager.forcesavePath = function (fileName, userAddress, create) { docManager.forcesavePath = function (fileName, userAddress, create) {
let directory = path.join(docManager.dir, docManager.curUserHostAddress(userAddress)); let directory = path.isAbsolute(docManager.dir) ? docManager.dir : path.join(docManager.dir, docManager.curUserHostAddress(userAddress));
if (!this.existsSync(directory)) { // the directory with host address doesn't exist if (!this.existsSync(directory)) { // the directory with host address doesn't exist
return ""; return "";
} }
@ -218,7 +223,7 @@ docManager.forcesavePath = function (fileName, userAddress, create) {
// create the path to the file history // create the path to the file history
docManager.historyPath = function (fileName, userAddress, create) { docManager.historyPath = function (fileName, userAddress, create) {
let directory = path.join(docManager.dir, docManager.curUserHostAddress(userAddress)); let directory = path.isAbsolute(docManager.dir) ? docManager.dir : path.join(docManager.dir, userAddress);
if (!this.existsSync(directory)) { if (!this.existsSync(directory)) {
return ""; return "";
} }
@ -263,7 +268,7 @@ docManager.changesUser = function (fileName, userAddress, version) {
// get all the stored files // get all the stored files
docManager.getStoredFiles = function () { docManager.getStoredFiles = function () {
const userAddress = docManager.curUserHostAddress(); const userAddress = docManager.curUserHostAddress();
const directory = path.join(docManager.dir, userAddress); const directory = path.isAbsolute(docManager.dir) ? docManager.dir : path.join(docManager.dir, userAddress);
this.createDirectory(directory); this.createDirectory(directory);
const result = []; const result = [];
const storedFiles = fileSystem.readdirSync(directory); // read the user host directory contents const storedFiles = fileSystem.readdirSync(directory); // read the user host directory contents
@ -441,7 +446,7 @@ docManager.cleanFolderRecursive = function (folder, me) {
// get files information // get files information
docManager.getFilesInfo = function (fileId) { docManager.getFilesInfo = function (fileId) {
const userAddress = docManager.curUserHostAddress(); const userAddress = docManager.curUserHostAddress();
const directory = path.join(docManager.dir, userAddress); const directory = path.isAbsolute(docManager.dir) ? docManager.dir : path.join(docManager.dir, userAddress);
const filesInDirectory = this.getStoredFiles(); // get all the stored files from the folder const filesInDirectory = this.getStoredFiles(); // get all the stored files from the folder
let responseArray = []; let responseArray = [];
let responseObject; let responseObject;