From 2bccbc14ef515b024d196e20e3bd5e471f2cf552 Mon Sep 17 00:00:00 2001 From: Nik Afiq Date: Mon, 13 Apr 2026 00:06:08 +0900 Subject: [PATCH] feat: implement cnl-bridge service for handling crawljob requests in JDownloader --- manifests/media/jdownloader.yaml | 39 +++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/manifests/media/jdownloader.yaml b/manifests/media/jdownloader.yaml index 9c7fc0d..7c8f06a 100644 --- a/manifests/media/jdownloader.yaml +++ b/manifests/media/jdownloader.yaml @@ -23,7 +23,6 @@ spec: image: jlesage/jdownloader-2:latest ports: - containerPort: 5800 - - containerPort: 9666 env: - name: USER_ID value: "1000" @@ -36,6 +35,40 @@ spec: mountPath: /config - name: dl mountPath: /output + - name: cnl-bridge + image: python:3.12-alpine + ports: + - containerPort: 9666 + volumeMounts: + - name: config + mountPath: /config + command: + - python3 + - -c + - | + import http.server, urllib.parse, os, time + + WATCH_DIR = '/config/folderwatch' + os.makedirs(WATCH_DIR, exist_ok=True) + + class Handler(http.server.BaseHTTPRequestHandler): + def do_POST(self): + if self.path != '/add': + self.send_response(404); self.end_headers(); return + length = int(self.headers.get('Content-Length', 0)) + body = self.rfile.read(length).decode() + params = urllib.parse.parse_qs(body) + urls = params.get('urls', []) + if not urls: + self.send_response(400); self.end_headers(); return + fname = f'{WATCH_DIR}/{int(time.time()*1000)}.crawljob' + with open(fname, 'w') as f: + f.write(f'url={urls[0]}\nautoStart=TRUE\npackageName=subyshare\n') + self.send_response(200); self.end_headers() + self.wfile.write(b'Ok.') + def log_message(self, *a): pass + + http.server.HTTPServer(('0.0.0.0', 9666), Handler).serve_forever() volumes: - name: config hostPath: @@ -58,7 +91,7 @@ spec: - name: web port: 80 targetPort: 5800 - - name: clicknload + - name: cnl-bridge port: 9666 targetPort: 9666 --- @@ -111,7 +144,7 @@ spec: entryPoints: - websecure routes: - - match: Host(`jdownloader.home.arpa`) && PathPrefix(`/flash`) + - match: Host(`jdownloader.home.arpa`) && PathPrefix(`/add`) kind: Rule services: - name: jdownloader