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
+43 -26
+43 -26
View File
@@ -214,32 +214,50 @@ def normalize_components(raw_components: list) -> list:
# getrennt von SkillSpectors eigenem Scan, nur um der KI echten Kontext für # 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. # 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:
context_dir = Path(work_dir) / "context_extract" if target.startswith("http://") or target.startswith("https://"):
try: context_dir = Path(work_dir) / "context_extract"
context_dir.mkdir(exist_ok=True) try:
if is_zip: context_dir.mkdir(exist_ok=True)
with zipfile.ZipFile(target) as zf:
zf.extractall(context_dir)
else:
subprocess.run( subprocess.run(
["git", "clone", "--depth", "1", target, str(context_dir / "repo")], ["git", "clone", "--depth", "1", target, str(context_dir / "repo")],
timeout=60, timeout=60,
capture_output=True, capture_output=True,
text=True, text=True,
) )
candidates = ( candidates = (
list(context_dir.rglob("SKILL.md")) list(context_dir.rglob("SKILL.md"))
or list(context_dir.rglob("skill.md")) or list(context_dir.rglob("skill.md"))
or list(context_dir.rglob("README.md")) or list(context_dir.rglob("README.md"))
) )
if not candidates: return candidates[0].read_text(errors="ignore")[:3000] if candidates else ""
except Exception:
return "" return ""
return candidates[0].read_text(errors="ignore")[:3000] 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: except Exception:
return "" return ""
finally:
shutil.rmtree(context_dir, ignore_errors=True)
# --------------------------------------------------------------------------- # # --------------------------------------------------------------------------- #
@@ -437,8 +455,8 @@ a{color:var(--orange)}
<form method="post" enctype="multipart/form-data"> <form method="post" enctype="multipart/form-data">
<label>Git-Repository-URL</label> <label>Git-Repository-URL</label>
<input type="text" name="git_url" placeholder="https://git.obraasch.de/olli1986/mein-skill"> <input type="text" name="git_url" placeholder="https://git.obraasch.de/olli1986/mein-skill">
<label>...oder ZIP-Datei hochladen (max. 50&nbsp;MB)</label> <label>...oder Datei hochladen (ZIP-Archiv oder einzelne SKILL.md, max. 50&nbsp;MB)</label>
<input type="file" name="zip_file" accept=".zip"> <input type="file" name="zip_file" accept=".zip,.md">
<label>Wie ausführlich soll das Ergebnis sein?</label> <label>Wie ausführlich soll das Ergebnis sein?</label>
<select name="report_level"> <select name="report_level">
<option value="quick">Nur Einschätzung (Score, Empfehlung, Fund-Anzahl – am schnellsten)</option> <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) work_dir = tempfile.mkdtemp(dir=SCAN_TMP_DIR)
try: try:
if zip_file and zip_file.filename: if zip_file and zip_file.filename:
zip_path = Path(work_dir) / "upload.zip" safe_name = Path(zip_file.filename).name or "upload"
zip_file.save(zip_path) upload_path = Path(work_dir) / safe_name
target = str(zip_path) zip_file.save(upload_path)
target = str(upload_path)
elif git_url: elif git_url:
if not is_public_target(git_url): if not is_public_target(git_url):
return render_template_string( return render_template_string(
@@ -594,7 +613,7 @@ def index():
PAGE, PAGE,
allow_llm=ALLOW_LLM, allow_llm=ALLOW_LLM,
result=None, 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" report_path = Path(work_dir) / "report.json"
@@ -617,9 +636,7 @@ def index():
summary_text = None summary_text = None
summary_failed = False summary_failed = False
if use_llm: if use_llm:
skill_context = extract_skill_context( skill_context = extract_skill_context(target, work_dir=work_dir)
target, is_zip=bool(zip_file and zip_file.filename), work_dir=work_dir
)
summary_text = generate_report_summary(result, skill_context) summary_text = generate_report_summary(result, skill_context)
summary_failed = summary_text is None summary_failed = summary_text is None