Skip to content

Commit

Permalink
Allow plugin bundle uploads via websocket
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <[email protected]>
  • Loading branch information
falkTX committed Sep 4, 2023
1 parent 1b6ad23 commit 14f34f1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
2 changes: 1 addition & 1 deletion html/js/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $('document').ready(function() {
}
}

ws.onclose = function (evt) {
ws.onclose = function () {
desktop && desktop.blockUI()
}

Expand Down
54 changes: 51 additions & 3 deletions mod/webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,18 @@ def get(self):
self.write(data)

class SDKEffectInstaller(EffectInstaller):
def set_default_headers(self):
if 'Origin' not in self.request.headers.keys():
return
origin = self.request.headers['Origin']
match = re.match(r'^(\w+)://([^/]*)/?', origin)
if match is None:
return
protocol, domain = match.groups()
if protocol != "http" and not domain.endswith(":9000") and not domain.endswith(".mod.audio"):
return
self.set_header("Access-Control-Allow-Origin", origin)

@web.asynchronous
@gen.engine
def post(self):
Expand All @@ -777,7 +789,7 @@ def set_default_headers(self):
if match is None:
return
protocol, domain = match.groups()
if protocol != "http" or not domain.endswith(":9000"):
if protocol != "http" and not domain.endswith(":9000") and not domain.endswith(".mod.audio"):
return
self.set_header("Access-Control-Allow-Origin", origin)

Expand Down Expand Up @@ -1096,7 +1108,7 @@ def get(self, instance):
logging.exception(e)
self.write(ok)

class RemoteWebSocket(websocket.WebSocketHandler):
class RemotePedalboardWebSocket(websocket.WebSocketHandler):
def check_origin(self, origin):
match = re.match(r'^(\w+)://([^/]*)/?', origin)
if match is None:
Expand All @@ -1117,6 +1129,41 @@ def on_message(self, pedalboard_id):
self.write_message("true")
self.close()

class RemotePluginWebSocket(websocket.WebSocketHandler):
def check_origin(self, origin):
match = re.match(r'^(\w+)://([^/]*)/?', origin)
if match is None:
return False
protocol, domain = match.groups()
if protocol not in ("http", "https"):
return False
if domain != "mod.audio" and not domain.endswith(".mod.audio"):
return False
return True

@gen.coroutine
def on_message(self, package):
if not package:
hwdesc = get_hardware_descriptor()
self.write_message(json.dumps({
'bin-compat': hwdesc.get('bin-compat', "Unknown"),
'platform': hwdesc.get('platform', "Unknown"),
'version': IMAGE_VERSION,
}))
return

filename = os.path.join(DOWNLOAD_TMP_DIR, "remote.tar.gz")

with open(filename, 'wb') as fh:
fh.write(b64decode(package))

resp = yield gen.Task(install_package, filename)

if resp['ok']:
SESSION.msg_callback("rescan " + b64encode(json.dumps(resp).encode("utf-8")).decode("utf-8"))

self.write_message(json.dumps(resp))

class ServerWebSocket(websocket.WebSocketHandler):
@gen.coroutine
def open(self):
Expand Down Expand Up @@ -2324,7 +2371,8 @@ def get(self):
(r"/js/templates.js$", BulkTemplateLoader),

(r"/websocket/?$", ServerWebSocket),
(r"/rpbsocket/?$", RemoteWebSocket),
(r"/rpbsocket/?$", RemotePedalboardWebSocket),
(r"/rplsocket/?$", RemotePluginWebSocket),

(r"/(.*)", TimelessStaticFileHandler, {"path": HTML_DIR}),
],
Expand Down

0 comments on commit 14f34f1

Please sign in to comment.