mirror of
https://github.com/ONLYOFFICE/document-server-integration.git
synced 2026-02-10 18:05:10 +08:00
feat(nodejs): opening and saving document from buffer
This commit is contained in:
@ -87,6 +87,7 @@ app.use(favicon(`${__dirname}/public/images/favicon.ico`)); // use favicon
|
||||
|
||||
app.use(bodyParser.json()); // connect middleware that parses json
|
||||
app.use(bodyParser.urlencoded({ extended: false })); // connect middleware that parses urlencoded bodies
|
||||
app.use(bodyParser.raw({ type: '*/*' }));
|
||||
|
||||
app.get('/', (req, res) => { // define a handler for default page
|
||||
try {
|
||||
@ -715,6 +716,11 @@ app.post('/track', async (req, res) => { // define a handler for tracking file c
|
||||
let fName = fileUtility.getFileName(req.query.filename);
|
||||
let version = 0;
|
||||
|
||||
if (req.headers['content-type'] === 'application/octet-stream') {
|
||||
fileSystem.writeFileSync(req.DocManager.storagePath(fName, uAddress), req.body);
|
||||
return;
|
||||
}
|
||||
|
||||
// track file changes
|
||||
const processTrack = async function processTrack(response, bodyTrack, fileNameTrack, userAddressTrack) {
|
||||
// callback file saving process
|
||||
@ -1204,11 +1210,12 @@ app.get('/editor', (req, res) => { // define a handler for editing document
|
||||
|
||||
// file config data
|
||||
const argss = {
|
||||
documentData: fileSystem.readFileSync(req.DocManager.storagePath(fileName, userAddress)).toString('base64'),
|
||||
apiUrl: siteUrl + configServer.get('apiUrl'),
|
||||
file: {
|
||||
name: fileName,
|
||||
ext: fileUtility.getFileExtension(fileName, true),
|
||||
uri: url,
|
||||
uri: '_data_',
|
||||
directUrl: !userDirectUrl ? null : directUrl,
|
||||
uriUser: directUrl,
|
||||
created: new Date().toDateString(),
|
||||
|
||||
@ -77,8 +77,17 @@
|
||||
|
||||
var onAppReady = function () { // the application is loaded into the browser
|
||||
innerAlert("Document editor ready");
|
||||
const b64ToBuffer = (b64) => Uint8Array.from(atob(b64), c => c.charCodeAt(0));
|
||||
if (config.document.url === "_data_") docEditor.openDocument(b64ToBuffer("<%= documentData %>"));
|
||||
};
|
||||
|
||||
var onSaveDocument = function (event) {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", config.editorConfig.callbackUrl);
|
||||
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
|
||||
xhr.send(event.data);
|
||||
}
|
||||
|
||||
var onDocumentStateChange = function (event) { // the document is modified
|
||||
var title = document.title.replace(/^\*/g, "");
|
||||
document.title = (event.data ? "*" : "") + title;
|
||||
@ -454,6 +463,7 @@
|
||||
"onRequestSelectDocument": onRequestSelectDocument,
|
||||
"onRequestSelectSpreadsheet": onRequestSelectSpreadsheet,
|
||||
"onRequestOpen": onRequestOpen,
|
||||
"onSaveDocument": onSaveDocument,
|
||||
};
|
||||
|
||||
if (<%- JSON.stringify(editor.userid) %> != null) {
|
||||
|
||||
Reference in New Issue
Block a user