Fix source import parsing and AI settings UI
This commit is contained in:
@@ -897,6 +897,22 @@ def parse_source_line(line: str) -> dict[str, str]:
|
||||
raw = (line or "").strip()
|
||||
if not raw:
|
||||
return {"name": "", "tag": "", "url": "", "error": "Пустая строка"}
|
||||
delimiter = next((sep for sep in ("\t", "|", ";") if sep in raw), "")
|
||||
if delimiter:
|
||||
fields = [part.strip() for part in raw.split(delimiter)]
|
||||
fields = [part for part in fields if part]
|
||||
if len(fields) == 2:
|
||||
name, url = fields
|
||||
tag = name
|
||||
elif len(fields) == 3:
|
||||
name, tag, url = fields
|
||||
else:
|
||||
return {"name": "", "tag": "", "url": "", "error": "Формат: Название | тэг | ссылка"}
|
||||
if url.startswith(("vk.com/", "vk.ru/", "m.vk.com/")):
|
||||
url = f"https://{url}"
|
||||
url = url.replace("https://vk.ru/", "https://vk.com/", 1).replace("https://m.vk.com/", "https://vk.com/", 1)
|
||||
return {"name": name, "tag": normalize_hash_tag(tag, ""), "url": url, "error": ""}
|
||||
|
||||
parts = re.split(r"\s+", raw)
|
||||
url_index = next(
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user