Compare commits
No commits in common. '9c1397b46f69eba2b458f5d2f8c42ffc4fcc1f82' and '2fcc9c97f2ef3773fd417e803b7a8ffbe0ab06c8' have entirely different histories.
9c1397b46f
...
2fcc9c97f2
4 changed files with 17 additions and 52 deletions
Before Width: | Height: | Size: 32 KiB |
Binary file not shown.
@ -1,47 +1,16 @@ |
|||||||
const exec = require('child-process-promise').exec; |
const exec = require('child-process-promise').exec; |
||||||
const fsPromises = require('fs').promises; |
|
||||||
const path = require('path') |
|
||||||
|
|
||||||
module.exports = function (docxFile, image) { |
module.exports = function (docxFile, image){ |
||||||
return new Promise((resolve, reject) => { |
return new Promise ((resolve, reject)=>{ |
||||||
let zipName = docxFile.slice(0, -5) + '.zip' |
exec('mkdir word/media') |
||||||
let filePath = path.join(__dirname + '/../public/files') |
|
||||||
exec('mkdir -p word/media') |
|
||||||
.then(function (result) { |
.then(function (result) { |
||||||
|
var stdout = result.stdout; |
||||||
return Promise.all([ |
var stderr = result.stderr; |
||||||
fsPromises.copyFile(path.join(__dirname + '/../public/images/resized/' + image), |
console.log('stdout: ', stdout); |
||||||
path.join(__dirname + '/../public/files/word/media/image2.png')), |
console.log('stderr: ', stderr); |
||||||
|
|
||||||
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) { |
.catch(function (err) { |
||||||
|
console.error('ERROR: ', err); |
||||||
reject({ |
|
||||||
eCode: 500, |
|
||||||
eText: err |
|
||||||
}) |
|
||||||
|
|
||||||
}); |
}); |
||||||
}) |
} |
||||||
} |
)} |
Loading…
Reference in new issue