From e74e6b17116a1092fb283f9ce93ace1603cf204d Mon Sep 17 00:00:00 2001 From: flashwave Date: Thu, 9 Mar 2023 21:04:43 +0000 Subject: [PATCH] Adjustments for Misuzu support. --- public/index.php | 12 +++++++++++- public/js/eeprom-v1.0.js | 9 ++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/public/index.php b/public/index.php index 88eba66..dd6f3ea 100644 --- a/public/index.php +++ b/public/index.php @@ -39,8 +39,12 @@ $router->use('/', function($response, $request) { if($isApiDomain) { $router->use('/', function($response, $request) { - if($request->getMethod() === 'OPTIONS') { + if($request->hasHeader('Origin')) $response->setHeader('Access-Control-Allow-Credentials', 'true'); + }); + + $router->use('/', function($response, $request) { + if($request->getMethod() === 'OPTIONS') { $response->setHeader('Access-Control-Allow-Headers', 'Authorization'); $response->setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET, POST, DELETE'); return 204; @@ -49,6 +53,12 @@ if($isApiDomain) { $router->use('/', function($response, $request) use ($db) { $auth = $request->getHeaderLine('Authorization'); + if(empty($auth)) { + $mszAuth = (string)$request->getCookie('msz_auth'); + if(!empty($mszAuth)) + $auth = 'Misuzu ' . $mszAuth; + } + if(!empty($auth)) { $authParts = explode(' ', $auth, 2); $authMethod = strval($authParts[0] ?? ''); diff --git a/public/js/eeprom-v1.0.js b/public/js/eeprom-v1.0.js index 5e3ad6b..6a62ba0 100644 --- a/public/js/eeprom-v1.0.js +++ b/public/js/eeprom-v1.0.js @@ -59,8 +59,9 @@ EEPROM.EEPROMFile = function(fileInfo) { }; obj.isImage = function() { return obj.type.indexOf('image/') === 0; }; - obj.isAudio = function() { return obj.type.indexOf('audio/') === 0; }; + obj.isAudio = function() { return obj.type === 'application/x-font-gdos' || obj.type.indexOf('audio/') === 0; }; obj.isVideo = function() { return obj.type.indexOf('video/') === 0; }; + obj.isMedia = function() { return obj.isImage() || obj.isAudio() || obj.isVideo(); }; return obj; }; @@ -109,7 +110,8 @@ EEPROM.EEPROMDeleteTask = function(authorization, fileInfo) { obj.start = function() { xhr.open('DELETE', obj.fileInfo.urlf); - xhr.setRequestHeader('Authorization', obj.authorization); + if(obj.authorization) xhr.setRequestHeader('Authorization', obj.authorization); + else xhr.withCredentials = true; xhr.send(); }; @@ -202,7 +204,8 @@ EEPROM.EEPROMUploadTask = function(srcId, endpoint, authorization, file) { obj.start = function() { xhr.open('POST', obj.endpoint); - xhr.setRequestHeader('Authorization', obj.authorization); + if(obj.authorization) xhr.setRequestHeader('Authorization', obj.authorization); + else xhr.withCredentials = true; xhr.send(fd); };