@@ -194,6 +194,8 @@ func (u *DeviceService) Clean(req []dto.Clean) {
194194 _ , _ = dropVolumes ()
195195 case "build_cache" :
196196 _ , _ = dropBuildCache ()
197+ case "app_tmp_download_version" :
198+ dropFileOrDir (path .Join (global .Dir .RemoteAppResourceDir , item .Name ))
197199 }
198200 }
199201
@@ -612,6 +614,22 @@ func loadDownloadTree(fileOp fileUtils.FileOp) []dto.CleanTree {
612614 uploadTreeData := loadTreeWithAllFile (true , path5 , "download" , path5 , fileOp )
613615 treeData = append (treeData , uploadTreeData ... )
614616
617+ appTmpDownloadTree := loadAppTmpDownloadTree (fileOp )
618+ if len (appTmpDownloadTree ) > 0 {
619+ parentTree := dto.CleanTree {
620+ ID : uuid .NewString (),
621+ Label : "app_tmp_download" ,
622+ IsCheck : true ,
623+ IsRecommend : true ,
624+ Type : "app_tmp_download" ,
625+ Name : "apps" ,
626+ }
627+ for _ , child := range appTmpDownloadTree {
628+ parentTree .Size += child .Size
629+ }
630+ parentTree .Children = appTmpDownloadTree
631+ treeData = append (treeData , parentTree )
632+ }
615633 return treeData
616634}
617635
@@ -665,6 +683,70 @@ func loadWebsiteLogTree(fileOp fileUtils.FileOp) []dto.CleanTree {
665683 return res
666684}
667685
686+ func loadAppTmpDownloadTree (fileOp fileUtils.FileOp ) []dto.CleanTree {
687+ appDirs , err := os .ReadDir (global .Dir .RemoteAppResourceDir )
688+ if err != nil {
689+ return nil
690+ }
691+ var res []dto.CleanTree
692+ for _ , appDir := range appDirs {
693+ if ! appDir .IsDir () {
694+ continue
695+ }
696+ appKey := appDir .Name ()
697+ app , _ := appRepo .GetFirst (appRepo .WithKey (appKey ))
698+ if app .ID == 0 {
699+ continue
700+ }
701+ appPath := filepath .Join (global .Dir .RemoteAppResourceDir , appKey )
702+ versionDirs , err := os .ReadDir (appPath )
703+ if err != nil {
704+ continue
705+ }
706+ appDetails , _ := appDetailRepo .GetBy (appDetailRepo .WithAppId (app .ID ))
707+ existingVersions := make (map [string ]bool )
708+ for _ , appDetail := range appDetails {
709+ existingVersions [appDetail .Version ] = true
710+ }
711+ var missingVersions []string
712+ for _ , versionDir := range versionDirs {
713+ if ! versionDir .IsDir () {
714+ continue
715+ }
716+
717+ version := versionDir .Name ()
718+ if ! existingVersions [version ] {
719+ missingVersions = append (missingVersions , version )
720+ }
721+ }
722+ if len (missingVersions ) > 0 {
723+ var appTree dto.CleanTree
724+ appTree .ID = uuid .NewString ()
725+ appTree .Label = app .Name
726+ appTree .Type = "app_tmp_download"
727+ appTree .Name = appKey
728+ appTree .IsRecommend = true
729+ appTree .IsCheck = true
730+ for _ , version := range missingVersions {
731+ versionPath := filepath .Join (appPath , version )
732+ size , _ := fileOp .GetDirSize (versionPath )
733+ appTree .Size += uint64 (size )
734+ appTree .Children = append (appTree .Children , dto.CleanTree {
735+ ID : uuid .NewString (),
736+ Label : version ,
737+ Size : uint64 (size ),
738+ IsCheck : true ,
739+ IsRecommend : true ,
740+ Type : "app_tmp_download_version" ,
741+ Name : path .Join (appKey , version ),
742+ })
743+ }
744+ res = append (res , appTree )
745+ }
746+ }
747+ return res
748+ }
749+
668750func loadContainerTree () []dto.CleanTree {
669751 var treeData []dto.CleanTree
670752 client , err := docker .NewDockerClient ()
@@ -786,7 +868,7 @@ func loadTreeWithAllFile(isCheck bool, originalPath, treeType, pathItem string,
786868 ID : uuid .NewString (),
787869 Label : file .Name (),
788870 Type : treeType ,
789- Size : uint64 ( size ) ,
871+ Size : size ,
790872 Name : name ,
791873 IsCheck : isCheck ,
792874 IsRecommend : isCheck ,
0 commit comments