Spaces:
Runtime error
Runtime error
File size: 1,539 Bytes
986c3be 8789f29 986c3be 8789f29 986c3be 816d02c 986c3be 8789f29 986c3be 8789f29 986c3be 8789f29 986c3be 8789f29 986c3be | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import json
import os
from pathlib import Path
from http.server import BaseHTTPRequestHandler, HTTPServer
# ĐẶT biến này đúng bằng mount path bạn chọn trong Space Settings
MOUNT_PATH = os.getenv("BUCKET_MOUNT_PATH", "/data")
def scan(base: str):
p = Path(base)
if not p.exists():
return {
"exists": False,
"path": base,
"count": 0,
"files": []
}
files = []
for x in sorted(p.rglob("*")):
if x.is_file():
st = x.stat()
files.append({
"path": str(x.relative_to(p)),
"size": st.st_size
})
return {
"exists": True,
"path": base,
"count": len(files),
"files": files
}
class Handler(BaseHTTPRequestHandler):
def do_GET(self):
data = scan(MOUNT_PATH)
body = json.dumps(data, ensure_ascii=False, indent=2).encode("utf-8")
self.send_response(200)
self.send_header("Content-Type", "application/json; charset=utf-8")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, fmt, *args):
print(fmt % args, flush=True)
if __name__ == "__main__":
data = scan(MOUNT_PATH)
print("=== BUCKET_SCAN_START ===", flush=True)
print(json.dumps(data, ensure_ascii=False, indent=2), flush=True)
print("=== BUCKET_SCAN_END ===", flush=True)
HTTPServer(("0.0.0.0", 7860), Handler).serve_forever() |