@@ -50,35 +50,35 @@ proto.parseReqFile = function (req) {
5050 } ) ;
5151} ;
5252
53- proto . getDeploymentsVersions = function ( deploymentId , appVersion ) {
54- return models . DeploymentsVersions . findOne ( {
55- where : { deployment_id : deploymentId , app_version : appVersion }
53+ proto . createDeploymentsVersionIfNotExist = function ( deploymentId , appVersion , t ) {
54+ return models . DeploymentsVersions . findOrCreate ( {
55+ where : { deployment_id : deploymentId , app_version : appVersion } ,
56+ defaults : { current_package_id : 0 } ,
57+ transaction : t
58+ } )
59+ . spread ( ( data , created ) => {
60+ if ( created ) {
61+ log . debug ( `createDeploymentsVersionIfNotExist findOrCreate version ${ appVersion } ` ) ;
62+ }
63+ log . debug ( `createDeploymentsVersionIfNotExist version data:` , data . get ( ) ) ;
64+ return data ;
5665 } ) ;
5766} ;
5867
59- proto . existPackageHashAndCreateVersions = function ( deploymentId , appVersion , packageHash ) {
60- return this . getDeploymentsVersions ( deploymentId , appVersion )
68+ proto . isMatchPackageHash = function ( packageId , packageHash ) {
69+ if ( _ . lt ( packageId , 0 ) ) {
70+ log . debug ( `isMatchPackageHash packageId is 0` ) ;
71+ return Promise . resolve ( false ) ;
72+ }
73+ return models . Packages . findById ( packageId )
6174 . then ( ( data ) => {
62- if ( _ . isEmpty ( data ) ) {
63- return models . DeploymentsVersions . create ( {
64- deployment_id : deploymentId ,
65- app_version : appVersion ,
66- } )
67- . then ( ( ) => false ) ;
68- } else {
69- var packageId = data . current_package_id ;
70- if ( _ . gt ( packageId , 0 ) ) {
71- return models . Packages . findById ( packageId )
72- . then ( ( data ) => {
73- if ( _ . eq ( _ . get ( data , "package_hash" ) , packageHash ) ) {
74- return true ;
75- } else {
76- return false ;
77- }
78- } ) ;
79- } else {
80- return false
81- }
75+ if ( data && _ . eq ( data . get ( 'package_hash' ) , packageHash ) ) {
76+ log . debug ( `isMatchPackageHash data:` , data . get ( ) ) ;
77+ log . debug ( `isMatchPackageHash packageHash exist` ) ;
78+ return true ;
79+ } else {
80+ log . debug ( `isMatchPackageHash package is null` ) ;
81+ return false ;
8282 }
8383 } ) ;
8484} ;
@@ -91,20 +91,11 @@ proto.createPackage = function (deploymentId, appVersion, packageHash, manifestH
9191 var description = params . description || "" ;
9292 var originalLabel = params . originalLabel || "" ;
9393 var originalDeployment = params . originalDeployment || "" ;
94+ var self = this ;
9495 return models . Deployments . generateLabelId ( deploymentId )
9596 . then ( ( labelId ) => {
9697 return models . sequelize . transaction ( ( t ) => {
97- return models . DeploymentsVersions . findOne ( { where : { deployment_id : deploymentId , app_version : appVersion } } )
98- . then ( ( deploymentsVersions ) => {
99- if ( ! deploymentsVersions ) {
100- return models . DeploymentsVersions . create ( {
101- current_package_id : 0 ,
102- deployment_id : deploymentId ,
103- app_version : appVersion
104- } , { transaction : t } ) ;
105- }
106- return deploymentsVersions ;
107- } )
98+ return self . createDeploymentsVersionIfNotExist ( deploymentId , appVersion , t )
10899 . then ( ( deploymentsVersions ) => {
109100 return models . Packages . create ( {
110101 deployment_version_id : deploymentsVersions . id ,
@@ -216,6 +207,7 @@ proto.generateOneDiffPackage = function (workDirectoryPath, packageId, dataCente
216207 . then ( ( data ) => {
217208 return security . qetag ( data . path )
218209 . then ( ( diffHash ) => {
210+ log . debug ( 'diff' ) ;
219211 return common . uploadFileToStorage ( diffHash , fileName )
220212 . then ( ( ) => {
221213 var stats = fs . statSync ( fileName ) ;
@@ -303,39 +295,50 @@ proto.releasePackage = function (deploymentId, packageInfo, fileType, filePath,
303295 if ( fileType == "application/zip" ) {
304296 return common . unzipFile ( filePath , directoryPath )
305297 } else {
298+ log . debug ( `上传的文件格式不对` ) ;
306299 throw new AppError . AppError ( "上传的文件格式不对" ) ;
307300 }
308301 } )
309302 ] )
310303 . spread ( ( blobHash ) => {
311- return security . isAndroidPackage ( directoryPath )
304+ return security . uploadPackageType ( directoryPath )
312305 . then ( ( type ) => {
313306 if ( type === 1 ) {
314307 //android
315308 if ( pubType == 'ios' ) {
316- throw new AppError . AppError ( "it must be publish it by ios type" ) ;
309+ var e = new AppError . AppError ( "it must be publish it by ios type" ) ;
310+ log . debug ( e ) ;
311+ throw e ;
317312 }
318313 } else if ( type === 2 ) {
319314 //ios
320315 if ( pubType == 'android' ) {
321- throw new AppError . AppError ( "it must be publish it by android type" ) ;
316+ var e = new AppError . AppError ( "it must be publish it by android type" ) ;
317+ log . debug ( e ) ;
318+ throw e ;
322319 }
323320 } else {
324321 //不验证
322+ log . debug ( `Unknown package type` ) ;
325323 }
326- } )
327- . then ( ( ) => blobHash )
324+ return blobHash ;
325+ } ) ;
328326 } )
329327 . then ( ( blobHash ) => {
330328 var dataCenterManager = require ( './datacenter-manager' ) ( ) ;
331329 return dataCenterManager . storePackage ( directoryPath )
332330 . then ( ( dataCenter ) => {
333331 var packageHash = dataCenter . packageHash ;
334332 var manifestFile = dataCenter . manifestFilePath ;
335- return self . existPackageHashAndCreateVersions ( deploymentId , appVersion , packageHash )
333+ return self . createDeploymentsVersionIfNotExist ( deploymentId , appVersion )
334+ . then ( ( deploymentsVersions ) => {
335+ return self . isMatchPackageHash ( deploymentsVersions . get ( 'current_package_id' ) , packageHash ) ;
336+ } )
336337 . then ( ( isExist ) => {
337338 if ( isExist ) {
338- throw new AppError . AppError ( "The uploaded package is identical to the contents of the specified deployment's current release." ) ;
339+ var e = new AppError . AppError ( "The uploaded package is identical to the contents of the specified deployment's current release." ) ;
340+ log . debug ( e . message ) ;
341+ throw e ;
339342 }
340343 return security . qetag ( manifestFile ) ;
341344 } )
@@ -345,7 +348,7 @@ proto.releasePackage = function (deploymentId, packageInfo, fileType, filePath,
345348 common . uploadFileToStorage ( blobHash , filePath )
346349 ] )
347350 . then ( ( ) => [ packageHash , manifestHash , blobHash ] ) ;
348- } ) ;
351+ } )
349352 } ) ;
350353 } )
351354 . spread ( ( packageHash , manifestHash , blobHash ) => {
@@ -411,7 +414,10 @@ proto.promotePackage = function (sourceDeploymentId, destDeploymentId, promoteUi
411414 if ( ! packages ) {
412415 throw new AppError . AppError ( 'does not exist packages.' ) ;
413416 }
414- return self . existPackageHashAndCreateVersions ( destDeploymentId , deploymentsVersions . app_version , packages . package_hash )
417+ return self . createDeploymentsVersionIfNotExist ( destDeploymentId , deploymentsVersions . app_version )
418+ . then ( ( deploymentsVersions ) => {
419+ return self . isMatchPackageHash ( deploymentsVersions . get ( 'current_package_id' ) , packages . package_hash ) ;
420+ } )
415421 . then ( ( isExist ) => {
416422 if ( isExist ) {
417423 throw new AppError . AppError ( "The uploaded package is identical to the contents of the specified deployment's current release." ) ;
0 commit comments