mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-04-07 14:06:11 +08:00
Compare commits
34 Commits
win-v4.3.0
...
v4.4.0.200
| Author | SHA1 | Date | |
|---|---|---|---|
| 022acfb9cd | |||
| 66c19c1b89 | |||
| bbd8305ad9 | |||
| c5b6b7ab1b | |||
| c854249add | |||
| 837b56b20f | |||
| 80b081883e | |||
| 7c71d42975 | |||
| a52d5cb3be | |||
| a9d261a0ad | |||
| 5dea4c77a9 | |||
| 8eb017b092 | |||
| dd346a380e | |||
| 61497a8da7 | |||
| 34d568bdbc | |||
| 905084dc52 | |||
| e00b662660 | |||
| 5ded3f6135 | |||
| a096e96b29 | |||
| b452a171d1 | |||
| 282ea78799 | |||
| 4824373678 | |||
| df8a575d75 | |||
| e023ec3bb7 | |||
| 535ba03cdf | |||
| f5d416e371 | |||
| 931e05a175 | |||
| 293919bb6e | |||
| 35c4dd6a95 | |||
| 32aff45d7d | |||
| 1b73970ebc | |||
| c014250479 | |||
| b1e216da88 | |||
| 257bf005eb |
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,4 +8,5 @@
|
||||
/web/documentserver-example/nodejs/node_modules
|
||||
/web/documentserver-example/nodejs/public/files
|
||||
/web/documentserver-example/nodejs/config/local.json
|
||||
**/.vscode/
|
||||
**/.idea
|
||||
@ -30,14 +30,20 @@ const bodyParser = require("body-parser");
|
||||
const fileSystem = require("fs");
|
||||
const formidable = require("formidable");
|
||||
const syncRequest = require("sync-request");
|
||||
const jwt = require('jsonwebtoken');
|
||||
const config = require('config');
|
||||
const configServer = config.get('server');
|
||||
const mime = require("mime");
|
||||
const docManager = require("./helpers/docManager");
|
||||
const documentService = require("./helpers/documentService");
|
||||
const fileUtility = require("./helpers/fileUtility");
|
||||
const siteUrl = configServer.get('siteUrl');
|
||||
const fileChoiceUrl = configServer.has('fileChoiceUrl') ? configServer.get('fileChoiceUrl') : "";
|
||||
const plugins = config.get('plugins');
|
||||
const cfgSignatureEnable = configServer.get('token.enable');
|
||||
const cfgSignatureUseForRequest = configServer.get('token.useforrequest');
|
||||
const cfgSignatureSecretExpiresIn = configServer.get('token.expiresIn');
|
||||
const cfgSignatureSecret = configServer.get('token.secret');
|
||||
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
|
||||
|
||||
@ -110,6 +116,26 @@ app.get("/", function (req, res) {
|
||||
}
|
||||
});
|
||||
|
||||
app.get("/download", function(req, res) {
|
||||
docManager.init(__dirname, req, res);
|
||||
|
||||
var fileName = fileUtility.getFileName(req.query.fileName);
|
||||
var userAddress = docManager.curUserHostAddress();
|
||||
|
||||
var path = docManager.forcesavePath(fileName, userAddress, false);
|
||||
if (path == "") {
|
||||
path = docManager.storagePath(fileName, userAddress);
|
||||
}
|
||||
|
||||
res.setHeader("Content-Length", fileSystem.statSync(path).size);
|
||||
res.setHeader("Content-Type", mime.lookup(path));
|
||||
|
||||
res.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
|
||||
|
||||
var filestream = fileSystem.createReadStream(path);
|
||||
filestream.pipe(res);
|
||||
});
|
||||
|
||||
app.post("/upload", function (req, res) {
|
||||
|
||||
docManager.init(__dirname, req, res);
|
||||
@ -135,6 +161,13 @@ app.post("/upload", function (req, res) {
|
||||
|
||||
const file = files.uploadedFile;
|
||||
|
||||
if (file == undefined) {
|
||||
res.writeHead(200, { "Content-Type": "text/plain" });
|
||||
res.write("{ \"error\": \"Uploaded file not found\"}");
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
file.name = docManager.getCorrectName(file.name);
|
||||
|
||||
if (configServer.get('maxFileSize') < file.size || file.size <= 0) {
|
||||
@ -289,7 +322,7 @@ app.post("/track", function (req, res) {
|
||||
|
||||
var processTrack = function (response, body, fileName, userAddress) {
|
||||
|
||||
var processSave = function (downloadUri, body, fileName, userAddress, resp, newVersion) {
|
||||
var processSave = function (downloadUri, body, fileName, userAddress, resp) {
|
||||
var curExt = fileUtility.getFileExtension(fileName);
|
||||
var downloadExt = fileUtility.getFileExtension(downloadUri);
|
||||
|
||||
@ -297,8 +330,8 @@ app.post("/track", function (req, res) {
|
||||
var key = documentService.generateRevisionId(downloadUri);
|
||||
|
||||
try {
|
||||
documentService.getConvertedUriSync(downloadUri, downloadExt, curExt, key, function(dUri){
|
||||
processSave(dUri, body, fileName, userAddress, resp, newVersion)
|
||||
documentService.getConvertedUriSync(downloadUri, downloadExt, curExt, key, function (dUri) {
|
||||
processSave(dUri, body, fileName, userAddress, resp)
|
||||
});
|
||||
return;
|
||||
} catch (ex) {
|
||||
@ -311,7 +344,7 @@ app.post("/track", function (req, res) {
|
||||
|
||||
var path = docManager.storagePath(fileName, userAddress);
|
||||
|
||||
if (newVersion) {
|
||||
if (docManager.existsSync(path)) {
|
||||
var historyPath = docManager.historyPath(fileName, userAddress);
|
||||
if (historyPath == "") {
|
||||
historyPath = docManager.historyPath(fileName, userAddress, true);
|
||||
@ -341,10 +374,52 @@ app.post("/track", function (req, res) {
|
||||
|
||||
var path_prev = docManager.prevFilePath(fileName, userAddress, version);
|
||||
fileSystem.writeFileSync(path_prev, fileSystem.readFileSync(path));
|
||||
|
||||
var file = syncRequest("GET", downloadUri);
|
||||
fileSystem.writeFileSync(path, file.getBody());
|
||||
|
||||
var forcesavePath = docManager.forcesavePath(fileName, userAddress, false);
|
||||
if (forcesavePath != "") {
|
||||
fileSystem.unlinkSync(forcesavePath);
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
console.log(ex);
|
||||
}
|
||||
|
||||
response.write("{\"error\":0}");
|
||||
response.end();
|
||||
};
|
||||
|
||||
var processForceSave = function (downloadUri, body, fileName, userAddress, resp) {
|
||||
var curExt = fileUtility.getFileExtension(fileName);
|
||||
var downloadExt = fileUtility.getFileExtension(downloadUri);
|
||||
|
||||
if (downloadExt != curExt) {
|
||||
var key = documentService.generateRevisionId(downloadUri);
|
||||
|
||||
try {
|
||||
documentService.getConvertedUriSync(downloadUri, downloadExt, curExt, key, function (dUri) {
|
||||
processForceSave(dUri, body, fileName, userAddress, resp)
|
||||
});
|
||||
return;
|
||||
} catch (ex) {
|
||||
console.log(ex);
|
||||
fileName = docManager.getCorrectName(fileUtility.getFileName(fileName, true) + downloadExt, userAddress)
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
var path = docManager.storagePath(fileName, userAddress);
|
||||
|
||||
var forcesavePath = docManager.forcesavePath(fileName, userAddress, false);
|
||||
if (forcesavePath == "") {
|
||||
forcesavePath = docManager.forcesavePath(fileName, userAddress, true);
|
||||
}
|
||||
|
||||
var file = syncRequest("GET", downloadUri);
|
||||
fileSystem.writeFileSync(path, file.getBody());
|
||||
fileSystem.writeFileSync(forcesavePath, file.getBody());
|
||||
} catch (ex) {
|
||||
console.log(ex);
|
||||
}
|
||||
@ -366,10 +441,11 @@ app.post("/track", function (req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
} else if (body.status == 2 || body.status == 3 //MustSave, Corrupted
|
||||
|| body.status == 6 || body.status == 7) { //MustForceSave, CorruptedForceSave
|
||||
var newVersion = (body.status == 2 || body.status == 3);
|
||||
processSave(body.url, body, fileName, userAddress, response, newVersion);
|
||||
} else if (body.status == 2 || body.status == 3) { //MustSave, Corrupted
|
||||
processSave(body.url, body, fileName, userAddress, response);
|
||||
return;
|
||||
} else if (body.status == 6 || body.status == 7) { //MustForceSave, CorruptedForceSave
|
||||
processForceSave(body.url, body, fileName, userAddress, response);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -388,6 +464,29 @@ app.post("/track", function (req, res) {
|
||||
});
|
||||
};
|
||||
|
||||
//checkjwt
|
||||
if (cfgSignatureEnable && cfgSignatureUseForRequest) {
|
||||
var checkJwtHeaderRes = documentService.checkJwtHeader(req);
|
||||
if (checkJwtHeaderRes) {
|
||||
if (checkJwtHeaderRes.payload) {
|
||||
body = checkJwtHeaderRes.payload;
|
||||
}
|
||||
if (checkJwtHeaderRes.query) {
|
||||
if (checkJwtHeaderRes.query.useraddress) {
|
||||
userAddress = checkJwtHeaderRes.query.useraddress;
|
||||
}
|
||||
if (checkJwtHeaderRes.query.filename) {
|
||||
fileName = fileUtility.getFileName(checkJwtHeaderRes.query.filename);
|
||||
}
|
||||
}
|
||||
processTrack(res, body, fileName, userAddress);
|
||||
} else {
|
||||
res.write("{\"error\":1}");
|
||||
res.end();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.body.hasOwnProperty("status")) {
|
||||
processTrack(res, req.body, fileName, userAddress);
|
||||
} else {
|
||||
@ -402,8 +501,7 @@ app.get("/editor", function (req, res) {
|
||||
|
||||
var fileExt = req.query.fileExt;
|
||||
var history = [];
|
||||
var prevUrl = [];
|
||||
var diff = [];
|
||||
var historyData = [];
|
||||
var lang = docManager.getLang();
|
||||
var userid = req.query.userid ? req.query.userid : "uid-1";
|
||||
var name = req.query.name ? req.query.name : "Jonn Smith";
|
||||
@ -417,7 +515,7 @@ app.get("/editor", function (req, res) {
|
||||
}
|
||||
|
||||
var userAddress = docManager.curUserHostAddress();
|
||||
fileName = fileUtility.getFileName(req.query.fileName);
|
||||
var fileName = fileUtility.getFileName(req.query.fileName);
|
||||
var key = docManager.getKey(fileName);
|
||||
var url = docManager.getFileUri(fileName);
|
||||
var mode = req.query.mode || "edit"; //mode: view/edit
|
||||
@ -431,33 +529,55 @@ app.get("/editor", function (req, res) {
|
||||
var countVersion = 1;
|
||||
|
||||
var historyPath = docManager.historyPath(fileName, userAddress);
|
||||
changes = null;
|
||||
var changes = null;
|
||||
var keyVersion = key;
|
||||
|
||||
if (historyPath != '') {
|
||||
|
||||
countVersion = docManager.countVersion(historyPath) + 1;
|
||||
var prevPath = docManager.getlocalFileUri(fileName, 1) + "/prev" + fileUtility.getFileExtension(fileName);
|
||||
var diffPath = null;
|
||||
for (var i = 1; i < countVersion; i++) {
|
||||
var keyPath = docManager.keyPath(fileName, userAddress, i);
|
||||
var keyVersion = "" + fileSystem.readFileSync(keyPath);
|
||||
for (var i = 1; i <= countVersion; i++) {
|
||||
if (i < countVersion) {
|
||||
var keyPath = docManager.keyPath(fileName, userAddress, i);
|
||||
keyVersion = "" + fileSystem.readFileSync(keyPath);
|
||||
} else {
|
||||
keyVersion = key;
|
||||
}
|
||||
history.push(docManager.getHistory(fileName, changes, keyVersion, i));
|
||||
|
||||
prevUrl.push(prevPath);
|
||||
prevPath = docManager.getlocalFileUri(fileName, i) + "/prev" + fileUtility.getFileExtension(fileName);
|
||||
|
||||
diff.push(diffPath);
|
||||
diffPath = docManager.getlocalFileUri(fileName, i) + "/diff.zip";
|
||||
|
||||
var changesFile = docManager.changesPath(fileName, userAddress, i);
|
||||
var changes = docManager.getChanges(changesFile);
|
||||
var historyD = {
|
||||
version: i,
|
||||
key: keyVersion,
|
||||
url: i == countVersion ? url : (docManager.getlocalFileUri(fileName, i, true) + "/prev" + fileUtility.getFileExtension(fileName)),
|
||||
};
|
||||
if (i > 1) {
|
||||
historyD.previous = {
|
||||
key: historyData[i-2].key,
|
||||
url: historyData[i-2].url,
|
||||
|
||||
};
|
||||
historyD.changesUrl = docManager.getlocalFileUri(fileName, i-1) + "/diff.zip";
|
||||
}
|
||||
historyData.push(historyD);
|
||||
|
||||
if (i < countVersion) {
|
||||
var changesFile = docManager.changesPath(fileName, userAddress, i);
|
||||
changes = docManager.getChanges(changesFile);
|
||||
}
|
||||
}
|
||||
prevUrl.push(prevPath);
|
||||
diff.push(diffPath);
|
||||
} else {
|
||||
prevUrl.push(url);
|
||||
history.push(docManager.getHistory(fileName, changes, keyVersion, countVersion));
|
||||
historyData.push({
|
||||
version: countVersion,
|
||||
key: key,
|
||||
url: url
|
||||
});
|
||||
}
|
||||
|
||||
if (cfgSignatureEnable) {
|
||||
for (var i = 0; i < historyData.length; i++) {
|
||||
historyData[i].token = jwt.sign(historyData[i], cfgSignatureSecret, {expiresIn: cfgSignatureSecretExpiresIn});
|
||||
}
|
||||
}
|
||||
history.push(docManager.getHistory(fileName, changes, key, countVersion));
|
||||
|
||||
var argss = {
|
||||
apiUrl: siteUrl + configServer.get('apiUrl'),
|
||||
@ -465,32 +585,42 @@ app.get("/editor", function (req, res) {
|
||||
name: fileName,
|
||||
ext: fileUtility.getFileExtension(fileName, true),
|
||||
uri: url,
|
||||
version: countVersion
|
||||
version: countVersion,
|
||||
created: new Date().toDateString()
|
||||
},
|
||||
editor: {
|
||||
type: type,
|
||||
documentType: fileUtility.getFileType(fileName),
|
||||
key: key,
|
||||
token: "",
|
||||
callbackUrl: docManager.getCallback(fileName),
|
||||
isEdit: canEdit && mode != "review",
|
||||
mode: canEdit && mode != "view" ? "edit" : "view",
|
||||
canBackToFolder: type != "embedded",
|
||||
getServerUrl: docManager.getServerUrl(),
|
||||
backUrl: docManager.getServerUrl(),
|
||||
curUserHostAddress: docManager.curUserHostAddress(),
|
||||
lang: lang,
|
||||
userid: userid,
|
||||
name: name,
|
||||
fileChoiceUrl: fileChoiceUrl,
|
||||
plugins: plugins
|
||||
plugins: JSON.stringify(plugins)
|
||||
},
|
||||
history: history,
|
||||
setHistoryData: {
|
||||
url: prevUrl,
|
||||
changesUrl: diff
|
||||
}
|
||||
historyData: historyData
|
||||
};
|
||||
|
||||
res.render("editor", argss);
|
||||
if (cfgSignatureEnable) {
|
||||
app.render('config', argss, function(err, html){
|
||||
if (err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
argss.editor.token = jwt.sign(JSON.parse("{"+html+"}"), cfgSignatureSecret, {expiresIn: cfgSignatureSecretExpiresIn});
|
||||
}
|
||||
res.render("editor", argss);
|
||||
});
|
||||
} else {
|
||||
res.render("editor", argss);
|
||||
}
|
||||
}
|
||||
catch (ex) {
|
||||
console.log(ex);
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
"tempStorageUrl": "ResourceService.ashx",
|
||||
"apiUrl": "web-apps/apps/api/documents/api.js",
|
||||
"preloaderUrl": "web-apps/apps/api/documents/cache-scripts.html",
|
||||
"exampleUrl": null,
|
||||
"viewedDocs": [".ppt", ".pps", ".odp", ".pdf", ".djvu", ".epub", ".xps"],
|
||||
"editedDocs": [".docx", ".doc", ".odt", ".xlsx", ".xls", ".ods", ".csv", ".pptx", ".ppsx", ".rtf", ".txt", ".mht", ".html", ".htm"],
|
||||
"convertedDocs": [".doc", ".odt", ".xls", ".ods", ".ppt", ".pps", ".odp", ".rtf", ".mht", ".html", ".htm", ".epub"],
|
||||
@ -30,18 +31,18 @@
|
||||
"name": "/public",
|
||||
"path": "public"
|
||||
}
|
||||
]
|
||||
],
|
||||
"token": {
|
||||
"enable": false,
|
||||
"useforrequest": true,
|
||||
"algorithmRequest": "HS256",
|
||||
"authorizationHeader": "Authorization",
|
||||
"authorizationHeaderPrefix": "Bearer ",
|
||||
"secret": "secret",
|
||||
"expiresIn": "5m"
|
||||
}
|
||||
},
|
||||
"plugins": {
|
||||
"url": "",
|
||||
"pluginsData": [
|
||||
"../../../../sdkjs-plugins/helloworld/config.json",
|
||||
"../../../../sdkjs-plugins/chess/config.json",
|
||||
"../../../../sdkjs-plugins/speech/config.json",
|
||||
"../../../../sdkjs-plugins/youtube/config.json",
|
||||
"../../../../sdkjs-plugins/cbr/config.json",
|
||||
"../../../../sdkjs-plugins/ocr/config.json",
|
||||
"../../../../sdkjs-plugins/clipart/config.json"
|
||||
]
|
||||
"pluginsData": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,24 +2,5 @@
|
||||
"server": {
|
||||
"port": 80,
|
||||
"siteUrl": "http://127.0.0.1:8001/"
|
||||
},
|
||||
"plugins": {
|
||||
"pluginsData": [
|
||||
"../../../../sdkjs-plugins/helloworld/config.json",
|
||||
"../../../../sdkjs-plugins/chess/config.json",
|
||||
"../../../../sdkjs-plugins/glavred/config.json",
|
||||
"../../../../sdkjs-plugins/speech/config.json",
|
||||
"../../../../sdkjs-plugins/youtube/config.json",
|
||||
"../../../../sdkjs-plugins/cbr/config.json",
|
||||
"../../../../sdkjs-plugins/num2word/config.json",
|
||||
"../../../../sdkjs-plugins/ocr/config.json",
|
||||
"../../../../sdkjs-plugins/yandextranslaterus/config.json",
|
||||
"../../../../sdkjs-plugins/clipart/config.json",
|
||||
"../../../../sdkjs-plugins/translate/config.json",
|
||||
"../../../../sdkjs-plugins/templates/config.json",
|
||||
"../../../../sdkjs-plugins/telegram/config.json",
|
||||
"../../../../sdkjs-plugins/invoices/config.json"
|
||||
],
|
||||
"UIpluginsData": []
|
||||
}
|
||||
}
|
||||
@ -2,8 +2,5 @@
|
||||
"server": {
|
||||
"siteUrl": "/",
|
||||
"maxFileSize": 104857600
|
||||
},
|
||||
"plugins": {
|
||||
"url": "/sdkjs-plugins/"
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,15 +7,7 @@
|
||||
"name": "/public",
|
||||
"path": "public",
|
||||
"options": {"maxAge": "7d"}
|
||||
},
|
||||
{
|
||||
"name": "/sdkjs-plugins",
|
||||
"path": "sdkjs-plugins",
|
||||
"options": {"maxAge": "7d"}
|
||||
}
|
||||
]
|
||||
},
|
||||
"plugins": {
|
||||
"url": "/sdkjs-plugins/"
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,12 +32,6 @@ const guidManager = require("./guidManager");
|
||||
const configServer = require('config').get('server');
|
||||
const storageFolder = configServer.get('storageFolder');
|
||||
const os = require("os");
|
||||
const readline = require('readline');
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
let docManager = {};
|
||||
|
||||
@ -79,30 +73,30 @@ docManager.getLang = function () {
|
||||
docManager.getCustomParams = function () {
|
||||
let params = "";
|
||||
|
||||
const userid = docManager.req.query.userid;
|
||||
const userid = docManager.req.query.userid;
|
||||
params += (userid ? "&userid=" + userid : "");
|
||||
|
||||
const name = docManager.req.query.name;
|
||||
const name = docManager.req.query.name;
|
||||
params += (name ? "&name=" + name : "");
|
||||
|
||||
const lang = docManager.req.query.lang;
|
||||
const lang = docManager.req.query.lang;
|
||||
params += (lang ? "&lang=" + docManager.getLang() : "");
|
||||
|
||||
const fileName = docManager.req.query.fileName;
|
||||
const fileName = docManager.req.query.fileName;
|
||||
params += (fileName ? "&fileName=" + fileName : "");
|
||||
|
||||
const mode = docManager.req.query.mode;
|
||||
const mode = docManager.req.query.mode;
|
||||
params += (mode ? "&mode=" + mode : "");
|
||||
|
||||
const type = docManager.req.query.type;
|
||||
const type = docManager.req.query.type;
|
||||
params += (type ? "&type=" + type : "");
|
||||
|
||||
return params;
|
||||
};
|
||||
|
||||
docManager.getCorrectName = function (fileName, userAddress) {
|
||||
const baseName = fileUtility.getFileName(fileName, true);
|
||||
const ext = fileUtility.getFileExtension(fileName);
|
||||
const baseName = fileUtility.getFileName(fileName, true);
|
||||
const ext = fileUtility.getFileExtension(fileName);
|
||||
let name = baseName + ext;
|
||||
let index = 1;
|
||||
|
||||
@ -125,14 +119,14 @@ docManager.createDemo = function (demoName, userid, username) {
|
||||
};
|
||||
|
||||
docManager.saveFileData = function (fileName, userid, username) {
|
||||
const userAddress = docManager.curUserHostAddress();
|
||||
const date_create = fileSystem.statSync(docManager.storagePath(fileName)).mtime;
|
||||
const minutes = (date_create.getMinutes() < 10 ? '0' : '') + date_create.getMinutes().toString();
|
||||
const month = (date_create.getMonth() < 10 ? '0' : '') + (parseInt(date_create.getMonth().toString()) + 1);
|
||||
const sec = (date_create.getSeconds() < 10 ? '0' : '') + date_create.getSeconds().toString();
|
||||
const date_format = date_create.getFullYear() + "-" + month + "-" + date_create.getDate() + " " + date_create.getHours() + ":" + minutes + ":" + sec;
|
||||
const userAddress = docManager.curUserHostAddress();
|
||||
const date_create = fileSystem.statSync(docManager.storagePath(fileName)).mtime;
|
||||
const minutes = (date_create.getMinutes() < 10 ? '0' : '') + date_create.getMinutes().toString();
|
||||
const month = (date_create.getMonth() < 10 ? '0' : '') + (parseInt(date_create.getMonth().toString()) + 1);
|
||||
const sec = (date_create.getSeconds() < 10 ? '0' : '') + date_create.getSeconds().toString();
|
||||
const date_format = date_create.getFullYear() + "-" + month + "-" + date_create.getDate() + " " + date_create.getHours() + ":" + minutes + ":" + sec;
|
||||
|
||||
const file_info = docManager.historyPath(fileName, userAddress, true);
|
||||
const file_info = docManager.historyPath(fileName, userAddress, true);
|
||||
this.createDirectory(file_info);
|
||||
|
||||
fileSystem.writeFileSync(path.join(file_info, fileName + ".txt"), date_format + "," + userid + "," + username);
|
||||
@ -148,28 +142,28 @@ docManager.getFileData = function (fileName, userAddress) {
|
||||
};
|
||||
|
||||
docManager.getFileUri = function (fileName) {
|
||||
return docManager.getlocalFileUri(fileName);
|
||||
return docManager.getlocalFileUri(fileName, 0, true);
|
||||
};
|
||||
|
||||
docManager.getlocalFileUri = function (fileName, version) {
|
||||
const serverPath = docManager.getServerUrl();
|
||||
const storagePath = storageFolder.length ? storageFolder + "/" : "";
|
||||
const hostAddress = docManager.curUserHostAddress();
|
||||
const url = serverPath + "/" + storagePath + hostAddress + "/" + encodeURIComponent(fileName);
|
||||
docManager.getlocalFileUri = function (fileName, version, forDocumentServer) {
|
||||
const serverPath = docManager.getServerUrl(forDocumentServer);
|
||||
const storagePath = storageFolder.length ? storageFolder + "/" : "";
|
||||
const hostAddress = docManager.curUserHostAddress();
|
||||
const url = serverPath + "/" + storagePath + hostAddress + "/" + encodeURIComponent(fileName);
|
||||
if (!version) {
|
||||
return url;
|
||||
}
|
||||
return url + "-history/" + version;
|
||||
};
|
||||
|
||||
docManager.getServerUrl = function () {
|
||||
return docManager.getProtocol() + "://" + docManager.req.get("host");
|
||||
docManager.getServerUrl = function (forDocumentServer) {
|
||||
return (forDocumentServer && !!configServer.get("exampleUrl")) ? configServer.get("exampleUrl") : (docManager.getProtocol() + "://" + docManager.req.get("host"));
|
||||
};
|
||||
|
||||
docManager.getCallback = function (fileName) {
|
||||
const server = docManager.getServerUrl();
|
||||
const hostAddress = docManager.curUserHostAddress();
|
||||
const handler = "/track?filename=" + encodeURIComponent(fileName) + "&useraddress=" + encodeURIComponent(hostAddress);
|
||||
const server = docManager.getServerUrl(true);
|
||||
const hostAddress = docManager.curUserHostAddress();
|
||||
const handler = "/track?filename=" + encodeURIComponent(fileName) + "&useraddress=" + encodeURIComponent(hostAddress);
|
||||
|
||||
return server + handler;
|
||||
};
|
||||
@ -181,6 +175,23 @@ docManager.storagePath = function (fileName, userAddress) {
|
||||
return path.join(directory, fileName);
|
||||
};
|
||||
|
||||
docManager.forcesavePath = function (fileName, userAddress, create) {
|
||||
let directory = path.join(docManager.dir, "public", storageFolder, docManager.curUserHostAddress(userAddress));
|
||||
if (!this.existsSync(directory)) {
|
||||
return "";
|
||||
}
|
||||
directory = path.join(directory, fileName + "-history");
|
||||
if (!create && !this.existsSync(directory)) {
|
||||
return "";
|
||||
}
|
||||
this.createDirectory(directory);
|
||||
directory = path.join(directory, fileName);
|
||||
if (!create && !this.existsSync(directory)) {
|
||||
return "";
|
||||
}
|
||||
return directory;
|
||||
};
|
||||
|
||||
docManager.historyPath = function (fileName, userAddress, create) {
|
||||
let directory = path.join(docManager.dir, "public", storageFolder, docManager.curUserHostAddress(userAddress));
|
||||
if (!this.existsSync(directory)) {
|
||||
@ -194,7 +205,7 @@ docManager.historyPath = function (fileName, userAddress, create) {
|
||||
};
|
||||
|
||||
docManager.versionPath = function (fileName, userAddress, version) {
|
||||
const historyPath = docManager.historyPath(fileName, userAddress, true);
|
||||
const historyPath = docManager.historyPath(fileName, userAddress, true);
|
||||
return path.join(historyPath, "" + version);
|
||||
};
|
||||
|
||||
@ -219,20 +230,19 @@ docManager.changesUser = function (fileName, userAddress, version) {
|
||||
};
|
||||
|
||||
docManager.getStoredFiles = function () {
|
||||
const directory = path.join(docManager.dir, "public", storageFolder, docManager.curUserHostAddress());
|
||||
const directory = path.join(docManager.dir, "public", storageFolder, docManager.curUserHostAddress());
|
||||
this.createDirectory(directory);
|
||||
const result = [];
|
||||
const storedFiles = fileSystem.readdirSync(directory);
|
||||
const result = [];
|
||||
const storedFiles = fileSystem.readdirSync(directory);
|
||||
for (let i = 0; i < storedFiles.length; i++) {
|
||||
const stats = fileSystem.lstatSync(path.join(directory, storedFiles[i]));
|
||||
const stats = fileSystem.lstatSync(path.join(directory, storedFiles[i]));
|
||||
|
||||
if (!stats.isDirectory()) {
|
||||
|
||||
const time = stats.mtime.getTime();
|
||||
const item = {
|
||||
const time = stats.mtime.getTime();
|
||||
const item = {
|
||||
time: time,
|
||||
name: storedFiles[i],
|
||||
url: docManager.getlocalFileUri(storedFiles[i]),
|
||||
documentType: fileUtility.getFileType(storedFiles[i])
|
||||
};
|
||||
|
||||
@ -281,16 +291,16 @@ docManager.getInternalExtension = function (fileType) {
|
||||
};
|
||||
|
||||
docManager.getKey = function (fileName) {
|
||||
const userAddress = docManager.curUserHostAddress();
|
||||
const userAddress = docManager.curUserHostAddress();
|
||||
let key = userAddress + docManager.getlocalFileUri(fileName);
|
||||
|
||||
let historyPath = docManager.historyPath(fileName, userAddress);
|
||||
let historyPath = docManager.historyPath(fileName, userAddress);
|
||||
if (historyPath != ""){
|
||||
key += docManager.countVersion(historyPath);
|
||||
}
|
||||
|
||||
historyPath = docManager.historyPath(fileName, userAddress, true);
|
||||
const stat = fileSystem.statSync(historyPath);
|
||||
let storagePath = docManager.storagePath(fileName, userAddress);
|
||||
const stat = fileSystem.statSync(storagePath);
|
||||
key += stat.mtime.toString();
|
||||
|
||||
return documentService.generateRevisionId(key);
|
||||
@ -327,8 +337,8 @@ docManager.getHistory = function (fileName, content, keyVersion, version) {
|
||||
|
||||
const userAddress = docManager.curUserHostAddress();
|
||||
const username = content ? (oldVersion ? contentJson.username : contentJson.user.name) : (docManager.getFileData(fileName, userAddress))[2];
|
||||
const userid = content ? (oldVersion ? contentJson.userid : contentJson.user.id) : (docManager.getFileData(fileName, userAddress))[1];
|
||||
const created = content ? (oldVersion ? contentJson.date : contentJson.created) : (docManager.getFileData(fileName, userAddress))[0];
|
||||
const userid = content ? (oldVersion ? contentJson.userid : contentJson.user.id) : (docManager.getFileData(fileName, userAddress))[1];
|
||||
const created = content ? (oldVersion ? contentJson.date : contentJson.created) : (docManager.getFileData(fileName, userAddress))[0];
|
||||
const res = (content && !oldVersion) ? content : {changes: content};
|
||||
res.key = keyVersion;
|
||||
res.version = version;
|
||||
@ -342,20 +352,20 @@ docManager.getHistory = function (fileName, content, keyVersion, version) {
|
||||
};
|
||||
|
||||
docManager.cleanFolderRecursive = function (folder, me) {
|
||||
if (fileSystem.existsSync(folder)) {
|
||||
const files = fileSystem.readdirSync(folder);
|
||||
files.forEach((file) => {
|
||||
const curPath = path.join(folder, file);
|
||||
if (fileSystem.lstatSync(curPath).isDirectory()) {
|
||||
this.cleanFolderRecursive(curPath, true);
|
||||
} else {
|
||||
fileSystem.unlinkSync(curPath);
|
||||
}
|
||||
});
|
||||
if (me) {
|
||||
fileSystem.rmdirSync(folder);
|
||||
}
|
||||
}
|
||||
if (fileSystem.existsSync(folder)) {
|
||||
const files = fileSystem.readdirSync(folder);
|
||||
files.forEach((file) => {
|
||||
const curPath = path.join(folder, file);
|
||||
if (fileSystem.lstatSync(curPath).isDirectory()) {
|
||||
this.cleanFolderRecursive(curPath, true);
|
||||
} else {
|
||||
fileSystem.unlinkSync(curPath);
|
||||
}
|
||||
});
|
||||
if (me) {
|
||||
fileSystem.rmdirSync(folder);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = docManager;
|
||||
|
||||
@ -24,12 +24,22 @@
|
||||
*/
|
||||
|
||||
var path = require("path");
|
||||
var urlModule = require("url");
|
||||
var urllib = require("urllib");
|
||||
var xml2js = require("xml2js");
|
||||
var jwt = require("jsonwebtoken");
|
||||
var jwa = require("jwa");
|
||||
var fileUtility = require("./fileUtility");
|
||||
var guidManager = require("./guidManager");
|
||||
var configServer = require('config').get('server');
|
||||
var siteUrl = configServer.get('siteUrl');
|
||||
var cfgSignatureEnable = configServer.get('token.enable');
|
||||
var cfgSignatureUseForRequest = configServer.get('token.useforrequest');
|
||||
var cfgSignatureAuthorizationHeader = configServer.get('token.authorizationHeader');
|
||||
var cfgSignatureAuthorizationHeaderPrefix = configServer.get('token.authorizationHeaderPrefix');
|
||||
var cfgSignatureSecretExpiresIn = configServer.get('token.expiresIn');
|
||||
var cfgSignatureSecret = configServer.get('token.secret');
|
||||
var cfgSignatureSecretAlgorithmRequest = configServer.get('token.algorithmRequest');
|
||||
|
||||
var documentService = {};
|
||||
|
||||
@ -64,12 +74,19 @@ documentService.getConvertedUri = function (documentUri, fromExtension, toExtens
|
||||
key: documentRevisionId
|
||||
};
|
||||
|
||||
urllib.request(siteUrl + configServer.get('converterUrl'),
|
||||
var uri = siteUrl + configServer.get('converterUrl');
|
||||
var headers = {
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
|
||||
if (cfgSignatureEnable && cfgSignatureUseForRequest) {
|
||||
headers[cfgSignatureAuthorizationHeader] = cfgSignatureAuthorizationHeaderPrefix + this.fillJwtByUrl(uri, params);
|
||||
}
|
||||
|
||||
urllib.request(uri,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
headers: headers,
|
||||
data: params
|
||||
},
|
||||
callback);
|
||||
@ -79,15 +96,22 @@ documentService.getExternalUri = function (fileStream, contentLength, contentTyp
|
||||
documentRevisionId = documentService.generateRevisionId(documentRevisionId);
|
||||
|
||||
var urlTostorage = siteUrl + configServer.get('storageUrl') + "?key=" + documentRevisionId;
|
||||
var headers = {
|
||||
"Content-Type": contentType == null ? "application/octet-stream" : contentType,
|
||||
"Content-Length": contentLength.toString(),
|
||||
"charset": "utf-8"
|
||||
};
|
||||
|
||||
if (cfgSignatureEnable && cfgSignatureUseForRequest) {
|
||||
const hmac = jwa(cfgSignatureSecretAlgorithmRequest);
|
||||
var payloadhash = hmac.sign(fileStream, cfgSignatureSecret);
|
||||
headers[cfgSignatureAuthorizationHeader] = cfgSignatureAuthorizationHeaderPrefix + this.fillJwtByUrl(urlTostorage, undefined, undefined, payloadhash);
|
||||
}
|
||||
|
||||
urllib.request(urlTostorage,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": contentType == null ? "application/octet-stream" : contentType,
|
||||
"Content-Length": contentLength.toString(),
|
||||
"charset": "utf-8"
|
||||
},
|
||||
headers: headers,
|
||||
data: fileStream
|
||||
},
|
||||
function (err, data) {
|
||||
@ -116,10 +140,10 @@ documentService.processConvertServiceResponceError = function (errorCode) {
|
||||
|
||||
switch (errorCode) {
|
||||
case -20:
|
||||
errorMessage = errorMessageTemplate + "vkey deciphering error";
|
||||
errorMessage = errorMessageTemplate + "Error encrypt signature";
|
||||
break;
|
||||
case -8:
|
||||
errorMessage = errorMessageTemplate + "Error document VKey";
|
||||
errorMessage = errorMessageTemplate + "Error document signature";
|
||||
break;
|
||||
case -7:
|
||||
errorMessage = errorMessageTemplate + "Error document request";
|
||||
@ -207,15 +231,43 @@ documentService.commandRequest = function (method, documentRevisionId, callback)
|
||||
key: documentRevisionId
|
||||
};
|
||||
|
||||
urllib.request(siteUrl + configServer.get('commandUrl'),
|
||||
var uri = siteUrl + configServer.get('commandUrl');
|
||||
var headers = {
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
if (cfgSignatureEnable && cfgSignatureUseForRequest) {
|
||||
headers[cfgSignatureAuthorizationHeader] = cfgSignatureAuthorizationHeaderPrefix + this.fillJwtByUrl(uri, params);
|
||||
}
|
||||
|
||||
urllib.request(uri,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
headers: headers,
|
||||
data: params
|
||||
},
|
||||
callback);
|
||||
};
|
||||
|
||||
documentService.checkJwtHeader = function (req) {
|
||||
var decoded = null;
|
||||
var authorization = req.get(cfgSignatureAuthorizationHeader);
|
||||
if (authorization && authorization.startsWith(cfgSignatureAuthorizationHeaderPrefix)) {
|
||||
var token = authorization.substring(cfgSignatureAuthorizationHeaderPrefix.length);
|
||||
try {
|
||||
decoded = jwt.verify(token, cfgSignatureSecret);
|
||||
} catch (err) {
|
||||
console.log('checkJwtHeader error: name = ' + err.name + ' message = ' + err.message + ' token = ' + token)
|
||||
}
|
||||
}
|
||||
return decoded;
|
||||
}
|
||||
|
||||
documentService.fillJwtByUrl = function (uri, opt_dataObject, opt_iss, opt_payloadhash) {
|
||||
var parseObject = urlModule.parse(uri, true);
|
||||
var payload = {query: parseObject.query, payload: opt_dataObject, payloadhash: opt_payloadhash};
|
||||
|
||||
var options = {algorithm: cfgSignatureSecretAlgorithmRequest, expiresIn: cfgSignatureSecretExpiresIn, issuer: opt_iss};
|
||||
return jwt.sign(payload, cfgSignatureSecret, options);
|
||||
}
|
||||
|
||||
module.exports = documentService;
|
||||
|
||||
@ -20,7 +20,10 @@
|
||||
"ejs": "~2.5.1",
|
||||
"express": "^4.14.1",
|
||||
"formidable": "^1.1.1",
|
||||
"jsonwebtoken": "^7.1.9",
|
||||
"jwa": "^1.1.4",
|
||||
"log4js": "^0.6.38",
|
||||
"mime": "^1.3.4",
|
||||
"serve-favicon": "~2.3.0",
|
||||
"sync-request": "^4.0.1",
|
||||
"urllib": "^2.20.0",
|
||||
|
||||
@ -116,6 +116,7 @@ label .checkbox {
|
||||
background-image: url("../images/file_pptx.png");
|
||||
}
|
||||
.create-sample {
|
||||
display: inline-block;
|
||||
margin-left: 75px;
|
||||
}
|
||||
.button, .button:visited, .button:hover, .button:active {
|
||||
|
||||
47
web/documentserver-example/nodejs/views/config.ejs
Normal file
47
web/documentserver-example/nodejs/views/config.ejs
Normal file
@ -0,0 +1,47 @@
|
||||
"width": "100%",
|
||||
"height": "100%",
|
||||
"type": "<%- editor.type %>",
|
||||
"documentType": "<%- editor.documentType %>",
|
||||
"token": "<%- editor.token %>",
|
||||
"document": {
|
||||
"title": "<%- file.name %>",
|
||||
"url": "<%- file.uri %>",
|
||||
"fileType": "<%- file.ext %>",
|
||||
"key": "<%- editor.key %>",
|
||||
"info": {
|
||||
"author": "Me",
|
||||
"created": "<%- file.created %>"
|
||||
},
|
||||
"permissions": {
|
||||
"download": true,
|
||||
"edit": "<%- editor.isEdit %>",
|
||||
"review": true
|
||||
}
|
||||
},
|
||||
"editorConfig": {
|
||||
"mode": "<%- editor.mode %>",
|
||||
"lang": "<%- editor.lang %>",
|
||||
"callbackUrl": "<%- editor.callbackUrl %>",
|
||||
"user": {
|
||||
"id": "<%- editor.userid %>",
|
||||
"name": "<%- editor.name %>"
|
||||
},
|
||||
"embedded": {
|
||||
"saveUrl": "<%- file.uri %>",
|
||||
"embedUrl": "<%- file.uri %>",
|
||||
"shareUrl": "<%- file.uri %>",
|
||||
"toolbarDocked": "top"
|
||||
},
|
||||
"customization": {
|
||||
"about": true,
|
||||
"chat": true,
|
||||
"comments": true,
|
||||
"feedback": true,
|
||||
"forcesave": false,
|
||||
"goback": {
|
||||
"url": "<%- editor.backUrl %>"
|
||||
}
|
||||
},
|
||||
"fileChoiceUrl": "<%- editor.fileChoiceUrl %>",
|
||||
"plugins": <%- editor.plugins %>
|
||||
}
|
||||
@ -44,8 +44,6 @@
|
||||
<script type="text/javascript" language="javascript">
|
||||
|
||||
var docEditor;
|
||||
var fileName = "<%= file.name %>";
|
||||
var fileType = "<%= file.ext %>";
|
||||
|
||||
var innerAlert = function (message) {
|
||||
if (console && console.log)
|
||||
@ -70,21 +68,16 @@
|
||||
|
||||
docEditor.refreshHistory(
|
||||
{
|
||||
currentVersion: "<%= file.version %>",
|
||||
currentVersion: "<%- file.version %>",
|
||||
history: historyObj
|
||||
});
|
||||
};
|
||||
|
||||
var onRequestHistoryData = function (data) {
|
||||
var version = data.data;
|
||||
var url_arr = "<%= setHistoryData.url %>".split(",");
|
||||
var changesUrl_arr = "<%= setHistoryData.changesUrl %>".split(",");
|
||||
var historyData = <%- JSON.stringify(historyData) %> || null;
|
||||
|
||||
docEditor.setHistoryData({
|
||||
version: version,
|
||||
url: url_arr[version - 1] != "" ? url_arr[version - 1] : null,
|
||||
changesUrl: changesUrl_arr[version - 1] != "" ? changesUrl_arr[version - 1] : null
|
||||
});
|
||||
docEditor.setHistoryData(historyData[version-1]);
|
||||
};
|
||||
|
||||
var onRequestHistoryClose = function (event){
|
||||
@ -102,53 +95,7 @@
|
||||
|
||||
var connectEditor = function () {
|
||||
|
||||
docEditor = new DocsAPI.DocEditor("iframeEditor",
|
||||
{
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
type: "<%= editor.type %>",
|
||||
documentType: "<%= editor.documentType %>",
|
||||
document: {
|
||||
title: fileName,
|
||||
url: "<%= file.uri %>",
|
||||
fileType: fileType,
|
||||
key: "<%= editor.key %>",
|
||||
info: {
|
||||
author: "Me",
|
||||
created: new Date().toDateString()
|
||||
},
|
||||
permissions: {
|
||||
download: true,
|
||||
edit: "<%= editor.isEdit %>" == "true",
|
||||
review: true,
|
||||
}
|
||||
},
|
||||
editorConfig: {
|
||||
mode: "<%= editor.mode %>",
|
||||
lang: "<%= editor.lang %>",
|
||||
callbackUrl: "<%- editor.callbackUrl %>",
|
||||
user: {
|
||||
id: "<%= editor.userid %>",
|
||||
name: "<%= editor.name %>",
|
||||
},
|
||||
embedded: {
|
||||
saveUrl: "<%= file.uri %>",
|
||||
embedUrl: "<%= file.uri %>",
|
||||
shareUrl: "<%= file.uri %>",
|
||||
toolbarDocked: "top"
|
||||
},
|
||||
customization: {
|
||||
about: true,
|
||||
chat: true,
|
||||
comments: true,
|
||||
feedback: true,
|
||||
goback: {
|
||||
url: "<%= editor.getServerUrl %>"
|
||||
}
|
||||
},
|
||||
fileChoiceUrl: "<%= editor.fileChoiceUrl %>",
|
||||
plugins: <%- JSON.stringify(editor.plugins) %>
|
||||
},
|
||||
docEditor = new DocsAPI.DocEditor("iframeEditor", {<% include config %>,
|
||||
events: {
|
||||
"onReady": onReady,
|
||||
"onDocumentStateChange": onDocumentStateChange,
|
||||
@ -160,12 +107,25 @@
|
||||
"onOutdatedVersion": onOutdatedVersion,
|
||||
}
|
||||
});
|
||||
|
||||
fixSize();
|
||||
};
|
||||
|
||||
var fixSize = function () {
|
||||
var wrapEl = document.getElementsByClassName("form");
|
||||
if (wrapEl.length) {
|
||||
wrapEl[0].style.height = screen.availHeight + "px";
|
||||
window.scrollTo(0, -1);
|
||||
wrapEl[0].style.height = window.innerHeight + "px";
|
||||
}
|
||||
};
|
||||
|
||||
if (window.addEventListener) {
|
||||
window.addEventListener("load", connectEditor);
|
||||
window.addEventListener("resize", fixSize);
|
||||
} else if (window.attachEvent) {
|
||||
window.attachEvent("onload", connectEditor);
|
||||
window.attachEvent("onresize", fixSize);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
@ -138,8 +138,8 @@
|
||||
<tr class="tableRow" title="<%=storedFiles[i].name%>">
|
||||
<td class="contentCells">
|
||||
<a class="stored-edit <%= storedFiles[i].documentType %>" href="editor?fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
|
||||
<span title="<%= storedFiles[i].url %>"><%= storedFiles[i].name %></span></a>
|
||||
<a href="<%= storedFiles[i].url %>">
|
||||
<span title="<%= storedFiles[i].name %>"><%= storedFiles[i].name %></span></a>
|
||||
<a href="download?fileName=<%= encodeURIComponent(storedFiles[i].name) %>">
|
||||
<img class="icon-download" src="images/download-24.png" alt="Download" title="Download" /></a>
|
||||
<a class="delete-file" data="<%= encodeURIComponent(storedFiles[i].name) %>">
|
||||
<img class="icon-delete" src="images/delete-24.png" alt="Delete" title="Delete" /></a>
|
||||
|
||||
@ -232,7 +232,6 @@ function getStoredFiles() {
|
||||
$dat = filemtime($directory . DIRECTORY_SEPARATOR . $fileName);
|
||||
$result[$dat] = (object) array(
|
||||
"name" => $fileName,
|
||||
"url" => FileUri($fileName),
|
||||
"documentType" => getDocumentType($fileName)
|
||||
);
|
||||
}
|
||||
|
||||
@ -176,7 +176,7 @@
|
||||
echo ' <a class="stored-edit '.$storeFile->documentType.'" href="doceditor.php?fileID='.urlencode($storeFile->name).'&user='.$user.'" target="_blank">';
|
||||
echo ' <span title="'.$storeFile->name.'">'.$storeFile->name.'</span>';
|
||||
echo ' </a>';
|
||||
echo ' <a href="'.$storeFile->url.'">';
|
||||
echo ' <a href="webeditor-ajax.php?type=download&filename='.$storeFile->name.'">';
|
||||
echo ' <img class="icon-download" src="css/images/download-24.png" alt="Download" title="Download" /></a>';
|
||||
echo ' </a>';
|
||||
echo ' <a class="delete-file" data="'.$storeFile->name.'">';
|
||||
|
||||
@ -60,6 +60,9 @@ if (isset($_GET["type"]) && !empty($_GET["type"])) { //Checks if type value exis
|
||||
$response_array = upload();
|
||||
$response_array['status'] = isset($response_array['error']) ? 'error' : 'success';
|
||||
die (json_encode($response_array));
|
||||
case "download":
|
||||
download();
|
||||
exit;
|
||||
case "convert":
|
||||
$response_array = convert();
|
||||
$response_array['status'] = 'success';
|
||||
@ -124,6 +127,21 @@ function upload() {
|
||||
return $result;
|
||||
}
|
||||
|
||||
function download() {
|
||||
$fileName = $_GET["filename"];
|
||||
|
||||
$filePath = getStoragePath($fileName);
|
||||
if (!file_exists($filePath)) {
|
||||
http_response_code(404);
|
||||
return;
|
||||
}
|
||||
header("Content-Length: " . filesize($filePath));
|
||||
header("Content-Type: " . mime_content_type($fileName));
|
||||
|
||||
header("Content-Disposition: attachment; filename=\"".basename($filePath)."\"");
|
||||
readfile($filePath);
|
||||
}
|
||||
|
||||
function track() {
|
||||
sendlog("Track START", "logs/webedior-ajax.log");
|
||||
sendlog("_GET params: " . serialize( $_GET ), "logs/webedior-ajax.log");
|
||||
|
||||
Reference in New Issue
Block a user