feat: implement cnl-bridge service for handling crawljob requests in JDownloader

This commit is contained in:
Nik Afiq 2026-04-13 00:06:08 +09:00
parent 054d7470cf
commit 2bccbc14ef

View File

@ -23,7 +23,6 @@ spec:
image: jlesage/jdownloader-2:latest image: jlesage/jdownloader-2:latest
ports: ports:
- containerPort: 5800 - containerPort: 5800
- containerPort: 9666
env: env:
- name: USER_ID - name: USER_ID
value: "1000" value: "1000"
@ -36,6 +35,40 @@ spec:
mountPath: /config mountPath: /config
- name: dl - name: dl
mountPath: /output 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: volumes:
- name: config - name: config
hostPath: hostPath:
@ -58,7 +91,7 @@ spec:
- name: web - name: web
port: 80 port: 80
targetPort: 5800 targetPort: 5800
- name: clicknload - name: cnl-bridge
port: 9666 port: 9666
targetPort: 9666 targetPort: 9666
--- ---
@ -111,7 +144,7 @@ spec:
entryPoints: entryPoints:
- websecure - websecure
routes: routes:
- match: Host(`jdownloader.home.arpa`) && PathPrefix(`/flash`) - match: Host(`jdownloader.home.arpa`) && PathPrefix(`/add`)
kind: Rule kind: Rule
services: services:
- name: jdownloader - name: jdownloader