"""
零壹学堂 - 公开下载服务器（通过VM104 + Tailscale Funnel对外暴露）
放在 VM104 (192.168.9.59) 上运行，端口 8765
"""
import http.server
import os

PORT = 8765
PDF_DIR = "/home/lsh/lingyi-downloads"

# 直接继承SimpleHTTPRequestHandler，用目录列表功能
class DownloadHandler(http.server.SimpleHTTPRequestHandler):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, directory=PDF_DIR, **kwargs)

if __name__ == "__main__":
    server = http.server.HTTPServer(("0.0.0.0", PORT), DownloadHandler)
    print(f"Download server running on http://0.0.0.0:{PORT}")
    print(f"Serving files from: {PDF_DIR}")
    print(f"Available files:")
    for f in sorted(os.listdir(PDF_DIR)):
        if f.endswith(".pdf"):
            print(f"  http://localhost:{PORT}/{f}")
    server.serve_forever()
