Compare commits
2 Commits
2fcc9c97f2
...
9c1397b46f
Author | SHA1 | Date |
---|---|---|
shoaib | 9c1397b46f | 4 years ago |
shoaib | 78d2bc06e9 | 4 years ago |
4 changed files with 52 additions and 17 deletions
After Width: | Height: | Size: 32 KiB |
Binary file not shown.
@ -1,16 +1,47 @@ |
||||
const exec = require('child-process-promise').exec; |
||||
const fsPromises = require('fs').promises; |
||||
const path = require('path') |
||||
|
||||
module.exports = function (docxFile, image){ |
||||
return new Promise ((resolve, reject)=>{ |
||||
exec('mkdir word/media') |
||||
.then(function (result) { |
||||
var stdout = result.stdout; |
||||
var stderr = result.stderr; |
||||
console.log('stdout: ', stdout); |
||||
console.log('stderr: ', stderr); |
||||
module.exports = function (docxFile, image) { |
||||
return new Promise((resolve, reject) => { |
||||
let zipName = docxFile.slice(0, -5) + '.zip' |
||||
let filePath = path.join(__dirname + '/../public/files') |
||||
exec('mkdir -p word/media') |
||||
.then(function (result) { |
||||
|
||||
return Promise.all([ |
||||
fsPromises.copyFile(path.join(__dirname + '/../public/images/resized/' + image), |
||||
path.join(__dirname + '/../public/files/word/media/image2.png')), |
||||
|
||||
fsPromises.rename(path.join(__dirname + '/../public/files/' + docxFile), |
||||
path.join(__dirname + '/../public/files/' + zipName)) |
||||
|
||||
]) |
||||
|
||||
}).then((result) => { |
||||
|
||||
return exec(`zip -d ${zipName} ./word/media/image2.png`, { |
||||
cwd: filePath |
||||
}) |
||||
}).then((result) => { |
||||
return exec(`zip -u ${zipName} ./word/media/image2.png`, { |
||||
cwd: filePath |
||||
}) |
||||
}).then((result) => { |
||||
|
||||
return fsPromises.rename(path.join(__dirname + '/../public/files/' + zipName), |
||||
path.join(__dirname + '/../public/files/' + docxFile)) |
||||
}).then(() => { |
||||
resolve(docxFile) |
||||
}) |
||||
|
||||
.catch(function (err) { |
||||
|
||||
reject({ |
||||
eCode: 500, |
||||
eText: err |
||||
}) |
||||
|
||||
}); |
||||
}) |
||||
.catch(function (err) { |
||||
console.error('ERROR: ', err); |
||||
}); |
||||
} |
||||
)} |
||||
} |
Loading…
Reference in new issue