feat: Add web version check
This commit is contained in:
@@ -8,6 +8,9 @@ from .py import utils
|
||||
config.extension_uri = os.path.dirname(__file__)
|
||||
utils.resolve_model_base_paths()
|
||||
|
||||
version = utils.get_current_version()
|
||||
utils.download_web_distribution(version)
|
||||
|
||||
|
||||
import logging
|
||||
from aiohttp import web
|
||||
|
||||
68
py/utils.py
68
py/utils.py
@@ -1,13 +1,79 @@
|
||||
import os
|
||||
import comfy.utils
|
||||
import json
|
||||
import yaml
|
||||
import shutil
|
||||
import tarfile
|
||||
import logging
|
||||
import requests
|
||||
import configparser
|
||||
|
||||
import comfy.utils
|
||||
import folder_paths
|
||||
|
||||
from aiohttp import web
|
||||
from typing import Any
|
||||
from . import config
|
||||
|
||||
|
||||
def get_current_version():
|
||||
try:
|
||||
pyproject_path = os.path.join(config.extension_uri, "pyproject.toml")
|
||||
config_parser = configparser.ConfigParser()
|
||||
config_parser.read(pyproject_path)
|
||||
version = config_parser.get("project", "version")
|
||||
return version.strip("'\"")
|
||||
except:
|
||||
return "0.0.0"
|
||||
|
||||
|
||||
def download_web_distribution(version: str):
|
||||
web_path = os.path.join(config.extension_uri, "web")
|
||||
dev_web_file = os.path.join(web_path, "manager-dev.js")
|
||||
if os.path.exists(dev_web_file):
|
||||
return
|
||||
|
||||
web_version = "0.0.0"
|
||||
version_file = os.path.join(web_path, "version.yaml")
|
||||
if os.path.exists(version_file):
|
||||
with open(version_file, "r") as f:
|
||||
version_content = yaml.safe_load(f)
|
||||
web_version = version_content.get("version", web_version)
|
||||
|
||||
if version == web_version:
|
||||
return
|
||||
|
||||
try:
|
||||
logging.info(f"current version {version}, web version {web_version}")
|
||||
logging.info("Downloading web distribution...")
|
||||
download_url = f"https://github.com/hayden-fr/ComfyUI-Model-Manager/releases/download/v{version}/dist.tar.gz"
|
||||
response = requests.get(download_url, stream=True)
|
||||
response.raise_for_status()
|
||||
|
||||
temp_file = os.path.join(config.extension_uri, "temp.tar.gz")
|
||||
with open(temp_file, "wb") as f:
|
||||
for chunk in response.iter_content(chunk_size=8192):
|
||||
f.write(chunk)
|
||||
|
||||
if os.path.exists(web_path):
|
||||
shutil.rmtree(web_path)
|
||||
|
||||
logging.info("Extracting web distribution...")
|
||||
with tarfile.open(temp_file, "r:gz") as tar:
|
||||
members = [
|
||||
member for member in tar.getmembers() if member.name.startswith("web/")
|
||||
]
|
||||
tar.extractall(path=config.extension_uri, members=members)
|
||||
|
||||
os.remove(temp_file)
|
||||
logging.info("Web distribution downloaded successfully.")
|
||||
except requests.exceptions.RequestException as e:
|
||||
logging.error(f"Failed to download web distribution: {e}")
|
||||
except tarfile.TarError as e:
|
||||
logging.error(f"Failed to extract web distribution: {e}")
|
||||
except Exception as e:
|
||||
logging.error(f"An unexpected error occurred: {e}")
|
||||
|
||||
|
||||
def resolve_model_base_paths():
|
||||
folders = list(folder_paths.folder_names_and_paths.keys())
|
||||
config.model_base_paths = {}
|
||||
|
||||
@@ -86,8 +86,29 @@ function dev(): Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
function createWebVersion(): Plugin {
|
||||
return {
|
||||
name: 'vite-plugin-web-version',
|
||||
apply: 'build',
|
||||
enforce: 'post',
|
||||
writeBundle() {
|
||||
const pyProjectContent = fs.readFileSync('pyproject.toml', 'utf8')
|
||||
const [, version] = pyProjectContent.match(/version = "(.*)"/) ?? []
|
||||
|
||||
const metadata = [
|
||||
`version: ${version}`,
|
||||
`build_time: ${new Date().toISOString()}`,
|
||||
'',
|
||||
].join('\n')
|
||||
|
||||
const metadataFilePath = path.join(__dirname, 'web', 'version.yaml')
|
||||
fs.writeFileSync(metadataFilePath, metadata, 'utf-8')
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [vue(), css(), output(), dev()],
|
||||
plugins: [vue(), css(), output(), dev(), createWebVersion()],
|
||||
|
||||
build: {
|
||||
outDir: 'web',
|
||||
|
||||
Reference in New Issue
Block a user