Dateien nach "/" hochladen

This commit is contained in:
Oliver Braasch committed 2026-09-23 23:12:22 +02:00
1 parent d304b93207
commit 69436dac11
1 file changed
+34 -17
+34 -17
View File
@@ -214,14 +214,11 @@ def normalize_components(raw_components: list) -> list:
# getrennt von SkillSpectors eigenem Scan, nur um der KI echten Kontext für
# den "Wofür ist das?"-Absatz zu geben statt nur der Sicherheitsfunde.
# --------------------------------------------------------------------------- #
def extract_skill_context(target: str, is_zip: bool, work_dir: str) -> str:
def extract_skill_context(target: str, work_dir: str) -> str:
if target.startswith("http://") or target.startswith("https://"):
context_dir = Path(work_dir) / "context_extract"
try:
context_dir.mkdir(exist_ok=True)
if is_zip:
with zipfile.ZipFile(target) as zf:
zf.extractall(context_dir)
else:
subprocess.run(
["git", "clone", "--depth", "1", target, str(context_dir / "repo")],
timeout=60,
@@ -233,14 +230,35 @@ def extract_skill_context(target: str, is_zip: bool, work_dir: str) -> str:
or list(context_dir.rglob("skill.md"))
or list(context_dir.rglob("README.md"))
)
if not candidates:
return ""
return candidates[0].read_text(errors="ignore")[:3000]
return candidates[0].read_text(errors="ignore")[:3000] if candidates else ""
except Exception:
return ""
finally:
shutil.rmtree(context_dir, ignore_errors=True)
if target.lower().endswith(".zip"):
context_dir = Path(work_dir) / "context_extract"
try:
context_dir.mkdir(exist_ok=True)
with zipfile.ZipFile(target) as zf:
zf.extractall(context_dir)
candidates = (
list(context_dir.rglob("SKILL.md"))
or list(context_dir.rglob("skill.md"))
or list(context_dir.rglob("README.md"))
)
return candidates[0].read_text(errors="ignore")[:3000] if candidates else ""
except Exception:
return ""
finally:
shutil.rmtree(context_dir, ignore_errors=True)
# Einzeln hochgeladene Datei (z. B. eine reine SKILL.md ohne ZIP)
try:
return Path(target).read_text(errors="ignore")[:3000]
except Exception:
return ""
# --------------------------------------------------------------------------- #
# Deutsche Klartext-Zusammenfassung des Reports per LLM (OpenRouter-kompatibel)
@@ -437,8 +455,8 @@ a{color:var(--orange)}
<form method="post" enctype="multipart/form-data">
<label>Git-Repository-URL</label>
<input type="text" name="git_url" placeholder="https://git.obraasch.de/olli1986/mein-skill">
<label>...oder ZIP-Datei hochladen (max. 50&nbsp;MB)</label>
<input type="file" name="zip_file" accept=".zip">
<label>...oder Datei hochladen (ZIP-Archiv oder einzelne SKILL.md, max. 50&nbsp;MB)</label>
<input type="file" name="zip_file" accept=".zip,.md">
<label>Wie ausführlich soll das Ergebnis sein?</label>
<select name="report_level">
<option value="quick">Nur Einschätzung (Score, Empfehlung, Fund-Anzahl – am schnellsten)</option>
@@ -577,9 +595,10 @@ def index():
work_dir = tempfile.mkdtemp(dir=SCAN_TMP_DIR)
try:
if zip_file and zip_file.filename:
zip_path = Path(work_dir) / "upload.zip"
zip_file.save(zip_path)
target = str(zip_path)
safe_name = Path(zip_file.filename).name or "upload"
upload_path = Path(work_dir) / safe_name
zip_file.save(upload_path)
target = str(upload_path)
elif git_url:
if not is_public_target(git_url):
return render_template_string(
@@ -594,7 +613,7 @@ def index():
PAGE,
allow_llm=ALLOW_LLM,
result=None,
error="Bitte eine Git-URL angeben oder eine ZIP-Datei hochladen.",
error="Bitte eine Git-URL angeben oder eine Datei hochladen.",
)
report_path = Path(work_dir) / "report.json"
@@ -617,9 +636,7 @@ def index():
summary_text = None
summary_failed = False
if use_llm:
skill_context = extract_skill_context(
target, is_zip=bool(zip_file and zip_file.filename), work_dir=work_dir
)
skill_context = extract_skill_context(target, work_dir=work_dir)
summary_text = generate_report_summary(result, skill_context)
summary_failed = summary_text is None