Loading app/main.py +14 −12 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ import logging import sys import json import shlex from threading import Thread ch = logging.StreamHandler(sys.stdout) ch.setLevel(logging.DEBUG) Loading Loading @@ -72,6 +73,19 @@ class MyHandler(BaseHTTPRequestHandler): self.respond(500, data) return self.respond(200, json.dumps({'success': True})) # Run Nextcloud API call in seperate thread. Needed because the API calls take 50+ seconds # each for unknown reasons. Instead we just run them in the background. Thread(target=self.call_nextcloud_api, args=(target_email, password, fallback_email, nextcloud_quota)).start() def respond(self, status: int, message: str): print(f'sending response status {status}, message {message}') self.send_response(status) self.end_headers() self.wfile.write(message.encode()) def call_nextcloud_api(self, target_email: str, password: str, fallback_email: str, nextcloud_quota: str): # Nextcloud only creates external accounts after the first login. We login through the API # to trigger the account creation. headers = {'OCS-APIRequest': 'true'} Loading @@ -88,18 +102,6 @@ class MyHandler(BaseHTTPRequestHandler): print(f'status code: {r1.status_code}') print(r2.text) print(f'status code: {r2.status_code}') if r1.status_code != 200 or r2.status_code != 200: data = json.dumps({'success': False, 'message': 'internal_error'}) self.respond(403, data) return self.respond(200, json.dumps({'success': True})) def respond(self, status: int, message: str): print(f'sending response status {status}, message {message}') self.send_response(status) self.end_headers() self.wfile.write(message.encode()) if __name__ == '__main__': Loading Loading
app/main.py +14 −12 Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ import logging import sys import json import shlex from threading import Thread ch = logging.StreamHandler(sys.stdout) ch.setLevel(logging.DEBUG) Loading Loading @@ -72,6 +73,19 @@ class MyHandler(BaseHTTPRequestHandler): self.respond(500, data) return self.respond(200, json.dumps({'success': True})) # Run Nextcloud API call in seperate thread. Needed because the API calls take 50+ seconds # each for unknown reasons. Instead we just run them in the background. Thread(target=self.call_nextcloud_api, args=(target_email, password, fallback_email, nextcloud_quota)).start() def respond(self, status: int, message: str): print(f'sending response status {status}, message {message}') self.send_response(status) self.end_headers() self.wfile.write(message.encode()) def call_nextcloud_api(self, target_email: str, password: str, fallback_email: str, nextcloud_quota: str): # Nextcloud only creates external accounts after the first login. We login through the API # to trigger the account creation. headers = {'OCS-APIRequest': 'true'} Loading @@ -88,18 +102,6 @@ class MyHandler(BaseHTTPRequestHandler): print(f'status code: {r1.status_code}') print(r2.text) print(f'status code: {r2.status_code}') if r1.status_code != 200 or r2.status_code != 200: data = json.dumps({'success': False, 'message': 'internal_error'}) self.respond(403, data) return self.respond(200, json.dumps({'success': True})) def respond(self, status: int, message: str): print(f'sending response status {status}, message {message}') self.send_response(status) self.end_headers() self.wfile.write(message.encode()) if __name__ == '__main__': Loading