Dateien nach "/" hochladen
This commit is contained in:
1 parent
d304b93207
commit
69436dac11
1 file changed
+43
-26
@@ -214,32 +214,50 @@ 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:
|
||||
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:
|
||||
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)
|
||||
subprocess.run(
|
||||
["git", "clone", "--depth", "1", target, str(context_dir / "repo")],
|
||||
timeout=60,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
candidates = (
|
||||
list(context_dir.rglob("SKILL.md"))
|
||||
or list(context_dir.rglob("skill.md"))
|
||||
or list(context_dir.rglob("README.md"))
|
||||
)
|
||||
if not candidates:
|
||||
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 ""
|
||||
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:
|
||||
return ""
|
||||
finally:
|
||||
shutil.rmtree(context_dir, ignore_errors=True)
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
@@ -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 MB)</label>
|
||||
<input type="file" name="zip_file" accept=".zip">
|
||||
<label>...oder Datei hochladen (ZIP-Archiv oder einzelne SKILL.md, max. 50 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
|
||||
|
||||
|
||||
Reference in new issue
Block a user