feat: add app temporary download file cleanup option to cache cleaning (#11460)

This commit is contained in:
CityFun 2025-12-25 18:33:03 +08:00 committed by GitHub
parent aa1bc6fa8e
commit 099896dc96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 108 additions and 2 deletions

View file

@ -194,6 +194,8 @@ func (u *DeviceService) Clean(req []dto.Clean) {
_, _ = dropVolumes()
case "build_cache":
_, _ = dropBuildCache()
case "app_tmp_download_version":
dropFileOrDir(path.Join(global.Dir.RemoteAppResourceDir, item.Name))
}
}
@ -612,6 +614,22 @@ func loadDownloadTree(fileOp fileUtils.FileOp) []dto.CleanTree {
uploadTreeData := loadTreeWithAllFile(true, path5, "download", path5, fileOp)
treeData = append(treeData, uploadTreeData...)
appTmpDownloadTree := loadAppTmpDownloadTree(fileOp)
if len(appTmpDownloadTree) > 0 {
parentTree := dto.CleanTree{
ID: uuid.NewString(),
Label: "app_tmp_download",
IsCheck: true,
IsRecommend: true,
Type: "app_tmp_download",
Name: "apps",
}
for _, child := range appTmpDownloadTree {
parentTree.Size += child.Size
}
parentTree.Children = appTmpDownloadTree
treeData = append(treeData, parentTree)
}
return treeData
}
@ -665,6 +683,70 @@ func loadWebsiteLogTree(fileOp fileUtils.FileOp) []dto.CleanTree {
return res
}
func loadAppTmpDownloadTree(fileOp fileUtils.FileOp) []dto.CleanTree {
appDirs, err := os.ReadDir(global.Dir.RemoteAppResourceDir)
if err != nil {
return nil
}
var res []dto.CleanTree
for _, appDir := range appDirs {
if !appDir.IsDir() {
continue
}
appKey := appDir.Name()
app, _ := appRepo.GetFirst(appRepo.WithKey(appKey))
if app.ID == 0 {
continue
}
appPath := filepath.Join(global.Dir.RemoteAppResourceDir, appKey)
versionDirs, err := os.ReadDir(appPath)
if err != nil {
continue
}
appDetails, _ := appDetailRepo.GetBy(appDetailRepo.WithAppId(app.ID))
existingVersions := make(map[string]bool)
for _, appDetail := range appDetails {
existingVersions[appDetail.Version] = true
}
var missingVersions []string
for _, versionDir := range versionDirs {
if !versionDir.IsDir() {
continue
}
version := versionDir.Name()
if !existingVersions[version] {
missingVersions = append(missingVersions, version)
}
}
if len(missingVersions) > 0 {
var appTree dto.CleanTree
appTree.ID = uuid.NewString()
appTree.Label = app.Name
appTree.Type = "app_tmp_download"
appTree.Name = appKey
appTree.IsRecommend = true
appTree.IsCheck = true
for _, version := range missingVersions {
versionPath := filepath.Join(appPath, version)
size, _ := fileOp.GetDirSize(versionPath)
appTree.Size += uint64(size)
appTree.Children = append(appTree.Children, dto.CleanTree{
ID: uuid.NewString(),
Label: version,
Size: uint64(size),
IsCheck: true,
IsRecommend: true,
Type: "app_tmp_download_version",
Name: path.Join(appKey, version),
})
}
res = append(res, appTree)
}
}
return res
}
func loadContainerTree() []dto.CleanTree {
var treeData []dto.CleanTree
client, err := docker.NewDockerClient()
@ -786,7 +868,7 @@ func loadTreeWithAllFile(isCheck bool, originalPath, treeType, pathItem string,
ID: uuid.NewString(),
Label: file.Name(),
Type: treeType,
Size: uint64(size),
Size: size,
Name: name,
IsCheck: isCheck,
IsRecommend: isCheck,

View file

@ -2233,6 +2233,8 @@ const message = {
dockerHelper: 'Files such as containers, images, volumes, build cache, etc.',
volumes: 'Volumes',
buildCache: 'Container Build Cache',
appTmpDownload: 'App temporary download file',
},
app: {
app: 'Application | Applications',

View file

@ -2246,6 +2246,8 @@ const message = {
dockerHelper: 'Archivos como contenedores, imágenes, volúmenes, caché de construcción, etc.',
volumes: 'Volúmenes',
buildCache: 'Caché de build de contenedores',
appTmpDownload: 'Archivo de descarga temporal de la aplicación',
},
app: {
app: 'Aplicación | Aplicaciones',

View file

@ -2153,6 +2153,8 @@ const message = {
dockerHelper: 'コンテナイメージボリュームビルドキャッシュなどのファイル',
volumes: 'ボリューム',
buildCache: 'コンテナビルドキャッシュ',
appTmpDownload: 'Archivo de descarga temporal de la aplicación',
},
app: {
app: 'アプリケーション|アプリケーション',

View file

@ -2117,6 +2117,8 @@ const message = {
dockerHelper: '컨테이너, 이미지, 볼륨, 빌드 캐시 등의 파일',
volumes: '볼륨',
buildCache: '컨테이너 빌드 캐시',
appTmpDownload: ' 임시 다운로드 파일',
},
app: {
app: '애플리케이션 | 애플리케이션들',

View file

@ -2212,6 +2212,8 @@ const message = {
dockerHelper: 'Fail seperti bekas, imej, isipadu, cache binaan, dsb.',
volumes: 'Isipadu',
buildCache: 'Cache Pembinaan Kontena',
appTmpDownload: 'Fail muat turun sementara aplikasi',
},
app: {
app: 'Aplikasi | Aplikasi',

View file

@ -2206,6 +2206,8 @@ const message = {
dockerHelper: 'Arquivos como contêineres, imagens, volumes, cache de compilação, etc.',
volumes: 'Volumes',
buildCache: 'Cache de construção do container',
appTmpDownload: 'Arquivo de download temporário do aplicativo',
},
app: {
app: 'Aplicativo | Aplicativos',

View file

@ -2201,6 +2201,8 @@ const message = {
dockerHelper: 'Файлы, такие как контейнеры, образы, тома, кэш сборки и т.д.',
volumes: 'Тома',
buildCache: 'Кэш сборки контейнеров',
appTmpDownload: 'Временный файл загрузки приложения',
},
app: {
app: 'Приложение | Приложения',

View file

@ -2258,6 +2258,8 @@ const message = {
dockerHelper: 'Konteynerler, görüntüler, hacimler, derleme önbelleği vb. dosyalar',
volumes: 'Birimler',
buildCache: 'Konteyner Oluşturma Önbelleği',
appTmpDownload: 'Uygulama geçici indirme dosyası',
},
app: {
app: 'Uygulama | Uygulamalar',

View file

@ -2082,6 +2082,8 @@ const message = {
dockerHelper: '容器映像儲存卷建置快取等檔案',
volumes: '磁碟區',
buildCache: '容器建置快取',
appTmpDownload: '應用程式暫存下載檔案',
},
app: {
app: '應用',

View file

@ -2079,6 +2079,8 @@ const message = {
dockerHelper: '容器镜像存储卷构建缓存等文件',
volumes: '存储卷',
buildCache: '构建缓存',
appTmpDownload: '应用临时下载文件',
},
app: {
app: '应用',

View file

@ -422,13 +422,15 @@ const loadSubmitCheck = (data: any) => {
}
return;
}
for (const item of data) {
if (
item.isCheck &&
item.label !== 'unknown_app' &&
item.label !== 'unknown_database' &&
item.label !== 'unknown_website' &&
item.label !== 'unknown_snapshot'
item.label !== 'unknown_snapshot' &&
item.type !== 'app_tmp_download'
) {
submitCleans.value.push({ treeType: item.type, name: item.name, size: item.size });
continue;
@ -632,6 +634,8 @@ function load18n(label: string) {
return i18n.global.t('clean.buildCache');
case 'website_log':
return i18n.global.t('logs.websiteLog');
case 'app_tmp_download':
return i18n.global.t('clean.appTmpDownload');
default:
return label;
}