Compare commits

..

2 Commits

  1. BIN
      public/images/resized/sampleImage.png
  2. 12
      services/user.js
  3. BIN
      template/Hform4.docx
  4. 51
      tools/addImageToWord.js

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

@ -3,7 +3,8 @@ const jalali = require("jalali-moment");
const persianjs = require('persianjs') const persianjs = require('persianjs')
const docxTemp = require('../tools/docxtemp') const docxTemp = require('../tools/docxtemp')
const imageResizer = require('../tools/imageResizer') const imageResizer = require('../tools/imageResizer')
const addImageToWord = require('../tools/addImageToWord') const addImageToWord = require('../tools/addImageToWord');
const { result } = require('lodash');
let methods = {} let methods = {}
@ -43,7 +44,7 @@ methods.addUser = (userInfo,imgOriginalName) => {
imageResizer(imgOriginalName) imageResizer(imgOriginalName)
.then(()=>{ .then(()=>{
models.User.create(userInfo) return models.User.create(userInfo)
}).then((user) => { }).then((user) => {
resolve(user) resolve(user)
@ -60,10 +61,11 @@ methods.addUser = (userInfo,imgOriginalName) => {
methods.completeForm =(userId)=>{ methods.completeForm =(userId)=>{
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let userInfo;
privates.findUser(userId) privates.findUser(userId)
.then(user=>{ .then(user=>{
let userInfo = user userInfo = user
userInfo.fullName = user.firstName + ' ' + user.lastName userInfo.fullName = user.firstName + ' ' + user.lastName
@ -88,7 +90,9 @@ methods.completeForm =(userId)=>{
return docxTemp(userInfo, userInfo.fileName) return docxTemp(userInfo, userInfo.fileName)
}).then(docxFileName=>{ }).then(docxFileName=>{
addImageToWord(docxFileName, userInfo.fileName + '.png') return addImageToWord(docxFileName, userInfo.imageFileName + '.png')
}).then(result=>{
resolve(`localhost:3000/users/download/${result}`)
}).catch(err => { }).catch(err => {
if (err.eText) { if (err.eText) {

Binary file not shown.

@ -1,16 +1,47 @@
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) => {
exec('mkdir word/media') let zipName = docxFile.slice(0, -5) + '.zip'
let filePath = path.join(__dirname + '/../public/files')
exec('mkdir -p word/media')
.then(function (result) { .then(function (result) {
var stdout = result.stdout;
var stderr = result.stderr; return Promise.all([
console.log('stdout: ', stdout); fsPromises.copyFile(path.join(__dirname + '/../public/images/resized/' + image),
console.log('stderr: ', stderr); 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) { .catch(function (err) {
console.error('ERROR: ', err);
reject({
eCode: 500,
eText: err
})
}); });
} })
)} }
Loading…
Cancel
Save