Separate stable API profile IDs from display names with legacy aliases

This commit is contained in:
Mikei386 committed 2026-10-03 23:35:30 +02:00
1 parent 0cffcf4295
commit a908313c8f
7 files changed
+88 -11

No files matched your search

+11 -2
View File
@@ -36,11 +36,17 @@ def validate(doc):
repo_id(source['repo'])
if not re.fullmatch('[a-f0-9]{40}',source['revision']) or source['file'].startswith('/') or '..' in PurePosixPath(source['file']).parts or '\\' in source['file'] or any(ord(c)<32 for c in source['file']):raise ValueError('Ungültige Ersatzquelle.')
ids.add(m['id'])
pids=set();names=set()
pids=set();names=set();api_names=set()
for p in profiles:
if not isinstance(p,dict) or not re.fullmatch('[a-f0-9]{32}',p.get('id','')) or p['id'] in pids or p.get('name') in names:raise ValueError('Ungültige oder doppelte Profil-ID.')
name=p.get('name','');kind=p.get('kind');params=p.get('parameters')
if not isinstance(name,str) or not 2<=len(name)<=64 or not re.fullmatch(r'[\w .-]+',name) or not name[0].isalnum() or not name[-1].isalnum() or kind not in SCHEMAS or p.get('model_id') not in ids:raise ValueError('Ungültiges Profil oder Modellreferenz.')
api_id=p.get('api_id');aliases=p.get('api_aliases',[])
if api_id is not None and (not isinstance(api_id,str) or not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9_-]{0,63}',api_id)):raise ValueError('Ungültige API-ID im Backup.')
if not isinstance(aliases,list) or len(aliases)>100 or any(not isinstance(a,str) or not 1<=len(a)<=64 or any(ord(c)<32 for c in a) for a in aliases):raise ValueError('Ungültige API-Aliase im Backup.')
identities=set([name,*aliases]+([api_id] if api_id else []))
if identities & api_names:raise ValueError('Doppelte API-ID oder Alias im Backup.')
api_names.update(identities)
if type(p.get('revision')) is not int or not 1<=p['revision']<=1000000:raise ValueError('Ungültige Profilrevision.')
if not isinstance(params,dict):raise ValueError('Ungültige Profilparameter.')
params=chat_parameters(params) if kind=='chat' else params
@@ -393,7 +399,10 @@ class Backup:
if name=='video/comfy-client-token':
path=self.root/name;path.parent.mkdir(parents=True,exist_ok=True);path.write_text(value+'\n');path.chmod(0o600)
else:atomic_write(self.root/name,value)
with s.profiles.lock:s.profiles.rows=copy.deepcopy(doc['settings'].get('profiles.json',[]))
with s.profiles.lock:
from profiles import migrate_api_ids
s.profiles.rows=copy.deepcopy(doc['settings'].get('profiles.json',[]));migrate_api_ids(s.profiles.rows)
s.profiles.path.write_text(json.dumps(s.profiles.rows))
with s.endpoint.lock:s.endpoint.config=copy.deepcopy(doc['settings'].get('endpoint.json',dict(port=8120,enabled_profiles=[],autostart=False)))
s.video.selection=copy.deepcopy(doc['settings'].get('video/comfy-selection.json',{}))
policy=doc['settings'].get('audio-policy.json',{k:{'mode':'auto','profile_id':None} for k in ('tts','stt')})