Make entry autoban opt-in, bound PPTX unpacking, unify skin DB path, prune deploy examples
This commit is contained in:
+10
-2
@@ -12,6 +12,8 @@ TEXT_BUDGET = 24000
|
||||
_MAX_PDF_PAGES = 60
|
||||
_MAX_XLSX_ROWS = 400
|
||||
_MAX_ZIP_ENTRIES = 200
|
||||
_MAX_PPTX_SLIDES = 300
|
||||
_MAX_UNPACKED_BYTES = 64 * 1024 * 1024
|
||||
|
||||
TEXT_EXTS = {
|
||||
".txt", ".md", ".markdown", ".rst", ".log", ".csv", ".tsv", ".json", ".jsonl",
|
||||
@@ -117,11 +119,17 @@ def _from_pptx(zf: zipfile.ZipFile) -> str:
|
||||
(n for n in zf.namelist() if re.fullmatch(r"ppt/slides/slide\d+\.xml", n)),
|
||||
key=lambda n: _num(n),
|
||||
)
|
||||
out = []
|
||||
for n in slides:
|
||||
out, chars, unpacked = [], 0, 0
|
||||
for n in slides[:_MAX_PPTX_SLIDES]:
|
||||
unpacked += zf.getinfo(n).file_size
|
||||
if unpacked > _MAX_UNPACKED_BYTES:
|
||||
raise RuntimeError(f"слайды распаковываются больше чем в {_MAX_UNPACKED_BYTES // 1048576} МБ")
|
||||
if chars > TEXT_BUDGET:
|
||||
break # _finish() truncates anyway; don't decompress the rest
|
||||
xml = _read_entry(zf, n)
|
||||
xml = xml.replace("</a:p>", "\n")
|
||||
out.append(f"--- {n.rsplit('/', 1)[-1]} ---\n" + unescape(_TAG_RE.sub("", xml)))
|
||||
chars += len(out[-1])
|
||||
return "\n".join(out)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user