76 lines
2.1 KiB
Python
76 lines
2.1 KiB
Python
|
|
import io
|
||
|
|
import os
|
||
|
|
from pathlib import Path
|
||
|
|
from fastapi.testclient import TestClient
|
||
|
|
import sys
|
||
|
|
from pathlib import Path as _Path
|
||
|
|
base = _Path(__file__).resolve().parents[2]
|
||
|
|
sys.path.insert(0, str(base))
|
||
|
|
sys.path.insert(0, str(base / "docling"))
|
||
|
|
import app.server as server
|
||
|
|
|
||
|
|
|
||
|
|
class FakeMinio:
|
||
|
|
def __init__(self):
|
||
|
|
self.objs = {}
|
||
|
|
|
||
|
|
def put_object(self, bucket_name: str, object_name: str, data: io.BytesIO, length: int, content_type: str):
|
||
|
|
self.objs[(bucket_name, object_name)] = data.read(length)
|
||
|
|
|
||
|
|
def get_presigned_url(self, method: str, bucket: str, obj: str, expires: int):
|
||
|
|
return f"http://minio.test/presigned/{bucket}/{obj}"
|
||
|
|
|
||
|
|
def presigned_get_object(self, bucket: str, obj: str, expires: int):
|
||
|
|
return f"http://minio.test/presigned/{bucket}/{obj}"
|
||
|
|
|
||
|
|
|
||
|
|
def setup():
|
||
|
|
server.RUNTIME_CONFIG["minio"].update({
|
||
|
|
"endpoint": "127.0.0.1:9000",
|
||
|
|
"public": "http://127.0.0.1:9000",
|
||
|
|
"access": "ak",
|
||
|
|
"secret": "sk",
|
||
|
|
"bucket": "test",
|
||
|
|
"secure": "false",
|
||
|
|
"prefix": "assets",
|
||
|
|
"store_final": "true",
|
||
|
|
"public_read": "true",
|
||
|
|
})
|
||
|
|
fake = FakeMinio()
|
||
|
|
def _cur():
|
||
|
|
return fake, "test", "http://127.0.0.1:9000", "assets"
|
||
|
|
server._minio_current = _cur # type: ignore
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
setup()
|
||
|
|
app = server.app
|
||
|
|
c = TestClient(app)
|
||
|
|
tmp = Path("/tmp/run_convert_folder_debug")
|
||
|
|
if tmp.exists():
|
||
|
|
for p in tmp.rglob("*"):
|
||
|
|
try:
|
||
|
|
p.unlink()
|
||
|
|
except Exception:
|
||
|
|
pass
|
||
|
|
try:
|
||
|
|
tmp.rmdir()
|
||
|
|
except Exception:
|
||
|
|
pass
|
||
|
|
tmp.mkdir(parents=True, exist_ok=True)
|
||
|
|
|
||
|
|
root = tmp / "数+产品手册-MD源文件"
|
||
|
|
sub = root / "DMDRS_DRS_Language_User_Manual"
|
||
|
|
img = sub / "images"
|
||
|
|
img.mkdir(parents=True, exist_ok=True)
|
||
|
|
(img / "p.png").write_bytes(b"PNG")
|
||
|
|
(sub / "a.md").write_text("# Title\n\n", "utf-8")
|
||
|
|
|
||
|
|
r = c.post("/md/convert-folder", data={"folder_path": str(root), "prefix": "assets"})
|
||
|
|
print("convert-folder:", r.status_code)
|
||
|
|
print(r.json())
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|