feat: Remove migration functionality (#89)

This commit is contained in:
Hayden
2025-01-10 17:11:15 +08:00
committed by GitHub
parent e75275dfff
commit 97b26549ce
4 changed files with 0 additions and 145 deletions

View File

@@ -65,4 +65,3 @@ There are three installation methods, choose one
<img src="demo/scan-model-info.png" alt="Model Manager Demo Screenshot" style="max-width: 100%; max-height: 300px"/>
- Scan models and try to download information & preview.
- Support migration from `cdb-boop/ComfyUI-Model-Manager/main`

View File

@@ -294,20 +294,6 @@ async def read_download_preview(request):
return web.FileResponse(preview_path)
@routes.post("/model-manager/migrate")
async def migrate_legacy_information(request):
"""
Migrate legacy information.
"""
try:
await services.migrate_legacy_information(request)
return web.json_response({"success": True})
except Exception as e:
error_msg = f"Migrate model info failed: {str(e)}"
utils.print_error(error_msg)
return web.json_response({"success": False, "error": error_msg})
WEB_DIRECTORY = "web"
NODE_CLASS_MAPPINGS = {}
__all__ = ["WEB_DIRECTORY", "NODE_CLASS_MAPPINGS"]

View File

@@ -2,7 +2,6 @@ import os
import folder_paths
from . import config
from . import utils
from . import download
from . import searcher
@@ -189,86 +188,3 @@ async def download_model_info(scan_mode: str, request):
utils.print_error(f"Failed to download model info for {abs_model_path}: {e}")
utils.print_debug("Completed scan model information.")
async def migrate_legacy_information(request):
import json
import yaml
from PIL import Image
utils.print_info(f"Migrating legacy information...")
model_base_paths = utils.resolve_model_base_paths()
for model_type in model_base_paths:
folders, extensions = folder_paths.folder_names_and_paths[model_type]
for path_index, base_path in enumerate(folders):
files = utils.recursive_search_files(base_path, request)
models = folder_paths.filter_files_extensions(files, folder_paths.supported_pt_extensions)
for fullname in models:
fullname = utils.normalize_path(fullname)
abs_model_path = utils.join_path(base_path, fullname)
base_file_name = os.path.splitext(abs_model_path)[0]
utils.print_debug(f"Try to migrate legacy info for {abs_model_path}")
preview_path = utils.join_path(
os.path.dirname(abs_model_path),
utils.get_model_preview_name(abs_model_path),
)
new_preview_path = f"{base_file_name}.webp"
if os.path.isfile(preview_path) and preview_path != new_preview_path:
utils.print_info(f"Migrate preview image from {fullname}")
with Image.open(preview_path) as image:
image.save(new_preview_path, format="WEBP")
description_path = f"{base_file_name}.md"
metadata_info = {
"website": "Civitai",
}
url_info_path = f"{base_file_name}.url"
if os.path.isfile(url_info_path):
with open(url_info_path, "r", encoding="utf-8") as f:
for line in f:
if line.startswith("URL="):
model_page_url = line[len("URL=") :].strip()
metadata_info.update({"modelPage": model_page_url})
json_info_path = f"{base_file_name}.json"
if os.path.isfile(json_info_path):
with open(json_info_path, "r", encoding="utf-8") as f:
version = json.load(f)
metadata_info.update(
{
"baseModel": version.get("baseModel"),
"preview": [i["url"] for i in version["images"]],
}
)
description_parts: list[str] = [
"---",
yaml.dump(metadata_info).strip(),
"---",
"",
]
text_info_path = f"{base_file_name}.txt"
if os.path.isfile(text_info_path):
with open(text_info_path, "r", encoding="utf-8") as f:
description_parts.append(f.read())
description_path = f"{base_file_name}.md"
if os.path.isfile(text_info_path):
utils.print_info(f"Migrate description from {fullname}")
with open(description_path, "w", encoding="utf-8", newline="") as f:
f.write("\n".join(description_parts))
utils.print_debug("Completed migrate model information.")

View File

@@ -91,52 +91,6 @@ function useAddConfigSettings(store: import('hooks/store').StoreProvider) {
defaultValue: undefined,
})
// Migrate
app.ui?.settings.addSetting({
id: 'ModelManager.Migrate.Migrate',
name: 'Migrate information from cdb-boop/main',
defaultValue: '',
type: () => {
return $el('button.p-button.p-component.p-button-secondary', {
textContent: 'Migrate',
onclick: () => {
confirm({
message: [
'This operation will delete old files and override current files if it exists.',
// 'This may take a while and generate MANY server requests!',
'Continue?',
].join('\n'),
accept: () => {
store.loading.loading.value = true
request('/migrate', {
method: 'POST',
})
.then(() => {
toast.add({
severity: 'success',
summary: 'Complete migration',
life: 2000,
})
store.models.refresh()
})
.catch((err) => {
toast.add({
severity: 'error',
summary: 'Error',
detail: err.message ?? 'Failed to migrate information',
life: 15000,
})
})
.finally(() => {
store.loading.loading.value = false
})
},
})
},
})
},
})
// Scan information
app.ui?.settings.addSetting({
id: 'ModelManager.ScanFiles.Full',