diff --git a/server/config.js b/server/config.js index dd09e14e..872af340 100644 --- a/server/config.js +++ b/server/config.js @@ -11,7 +11,7 @@ const common = { dbUser: process.env.FABU_DBUSER || undefined, //数据库用户 (没有开启mongodb用户认证的可以不填写) dbPass: process.env.FABU_DBPWD || undefined, //数据库密码 (没有开启mongodb用户认证的可以不填写) dbName: process.env.FABU_DB_NAME || "fabulove", //数据库名称 - dbHost: process.env.FABU_DB_HOST || "localhost", //数据库地址 + dbHost: process.env.FABU_DB_HOST || "0.0.0.0", //数据库地址 dbPort: process.env.FABU_DB_PORT || "27017", //数据库端口 emailService: process.env.FABU_EMAIL_SERVICE || "qq", //邮件相关配置 用于找回密码和邀请团队成员发送邮件 diff --git a/server/controllers/upload.js b/server/controllers/upload.js index ddcea032..177a53f8 100644 --- a/server/controllers/upload.js +++ b/server/controllers/upload.js @@ -240,6 +240,8 @@ async function extractIpaIcon(filename, guid, team) { .on('finish', resolve) } }) + }).catch({ + }) if (!found) { @@ -276,37 +278,68 @@ async function extractIpaIcon(filename, guid, team) { } ///解析apk -function parseApk(filename) { +function parseApk(filename) { + + const parser = new AppInfoParser(filename) + + return new Promise((resolve, reject) => { - apkParser3(filename, (err, data) => { - var apkPackage = parseText(data.package) - console.log(data) - console.log("----------------") - console.log(data['application-label']) + parser.parse().then(result => { + // console.log('app info ----> ', result) + // console.log('icon base64 ----> ', result.icon) + // console.log('====================================', JSON.stringify(result)); var label = undefined - data['launchable-activity'] - .split(' ') - .filter(s => s.length != 0) - .map(element => { return element.split('=') }) - .forEach(element => { - if (element && element.length > 2 && element[0] == 'label') { - label = element[1] - } - }) + + if(result.application && result.application.label && result.application.label.length > 0) { + label = result.application.label[0] + } + if (label) { label = label.replace(/'/g, '') } - var appName = (data['application-label'] || data['application-label-zh-CN'] || data['application-label-es-US'] || - data['application-label-zh_CN'] || data['application-label-es_US'] || label || 'unknown') + var appName = (result['application-label'] || result['application-label-zh-CN'] || result['application-label-es-US'] || + result['application-label-zh_CN'] || result['application-label-es_US'] || label || 'unknown') + var info = { 'appName': appName.replace(/'/g, ''), - 'versionCode': Number(apkPackage.versionCode), - 'bundleId': apkPackage.name, - 'versionStr': apkPackage.versionName, + 'versionCode': Number(result.versionCode), + 'bundleId': result.package, + 'versionStr': result.versionName, 'platform': 'android' } resolve(info) - }) + }).catch(err => { + console.log('err ----> ', err) + }) + // apkParser3(filename, (err, data) => { + // var apkPackage = parseText(data.package) + // console.log(data) + // console.log("----------------") + // console.log(data['application-label']) + // var label = undefined + // data['launchable-activity'] + // .split(' ') + // .filter(s => s.length != 0) + // .map(element => { return element.split('=') }) + // .forEach(element => { + // if (element && element.length > 2 && element[0] == 'label') { + // label = element[1] + // } + // }) + // if (label) { + // label = label.replace(/'/g, '') + // } + // var appName = (data['application-label'] || data['application-label-zh-CN'] || data['application-label-es-US'] || + // data['application-label-zh_CN'] || data['application-label-es_US'] || label || 'unknown') + // var info = { + // 'appName': appName.replace(/'/g, ''), + // 'versionCode': Number(apkPackage.versionCode), + // 'bundleId': apkPackage.name, + // 'versionStr': apkPackage.versionName, + // 'platform': 'android' + // } + // resolve(info) + // }) }) } @@ -335,6 +368,25 @@ function extractApkIcon(filepath, guid, team) { var { ext, dir } = path.parse(iconPath); // 获取到最大的png的路径 let maxSizePath; + // if (ext === '.xml') { + + // } else { + // fs.createReadStream(filepath) + // .pipe(unzip.Parse()) + // .pipe(etl.map(entry => { + // // 适配iconPath为ic_launcher.xml的情况 + // const entryPath = entry.path + // // const isXml = entryPath.indexOf('.xml') >= 0 + // // if ( (!isXml && entryPath.indexOf(iconPath) != -1) || (isXml && entry.path.indexOf(maxSizePath) != -1)) { + // // console.log(entry.path) + // entry.pipe(etl.toFile(tempOut)) + // resolve({ 'success': true, fileName: realPath }) + // // } else { + // // entry.autodrain() + // // } + // })) + // } + const initialPromise = ext === '.xml' ? unzip.Open.file(filepath).then(directory => { const getMaxSizeImagePath = compose(get('path'), maxBy('compressedSize'), @@ -353,6 +405,7 @@ function extractApkIcon(filepath, guid, team) { entry.pipe(etl.toFile(tempOut)) resolve({ 'success': true, fileName: realPath }) } else { + resolve({ 'success': true, fileName: realPath }) entry.autodrain() } })) diff --git a/server/package-lock.json b/server/package-lock.json index f6d8dfd2..6d2f81b2 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -7605,6 +7605,15 @@ } } }, + "unzip-stream": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/unzip-stream/-/unzip-stream-0.3.0.tgz", + "integrity": "sha512-NG1h/MdGIX3HzyqMjyj1laBCmlPYhcO4xEy7gEqqzGiSLw7XqDQCnY4nYSn5XSaH8mQ6TFkaujrO8d/PIZN85A==", + "requires": { + "binary": "^0.3.0", + "mkdirp": "^0.5.1" + } + }, "unzipper": { "version": "0.9.11", "resolved": "https://registry.npmjs.org/unzipper/-/unzipper-0.9.11.tgz", diff --git a/server/package.json b/server/package.json index 3e955e25..cfdd5680 100644 --- a/server/package.json +++ b/server/package.json @@ -34,6 +34,7 @@ "mongoose": "^5.4.19", "jsonwebtoken": "^8.5.0", "unzipper": "^0.9.3", + "unzip-stream": "^0.3.0", "lodash": "^4.17.4", "pm2": "^2.9.3", "uuid": "^3.2.1",