diff --git a/database/cloud-server.mwb b/database/cloud-server.mwb index 0a1d08b..3a536bb 100644 Binary files a/database/cloud-server.mwb and b/database/cloud-server.mwb differ diff --git a/src/application/controller/api/image.php b/src/application/controller/api/image.php deleted file mode 100755 index 01f9bb4..0000000 --- a/src/application/controller/api/image.php +++ /dev/null @@ -1,21 +0,0 @@ -generateImageResource($fileName, 42, 42, false); - - file_put_contents($filePath, $image); - } - - $image = file_get_contents($filePath); - - header("Content-Type: image/jpeg"); - - echo $image; -} diff --git a/src/application/controller/api/user/avatar.php b/src/application/controller/api/user/avatar.php index ac2aaf0..259b2d0 100644 --- a/src/application/controller/api/user/avatar.php +++ b/src/application/controller/api/user/avatar.php @@ -10,7 +10,15 @@ if (isset($_SESSION['userName'])) { $userName = isset($_GET['userName']) ? Filter::userName($_GET['userName']) : $_SESSION['userName']; - if ($avatarVersions = $_twister->getDHT($userName, 'avatar', 's')) { + if ($avatar = $_memcache->get('api.user.avatar.' . $userName)) { + + $response = [ + 'success' => true, + 'message' => _('Avatar successfully received from Cache'), + 'avatar' => $avatar + ]; + + } else if ($avatarVersions = $_twister->getDHT($userName, 'avatar', 's')) { // Check avatar exists if ($userId = $_modelUser->getUserId($userName)) { @@ -36,10 +44,12 @@ if (isset($_SESSION['userName'])) { $response = [ 'success' => true, - 'message' => _('Avatar successfully received'), + 'message' => _('Avatar successfully received from DHT'), 'avatar' => $avatarInfo['data'] ]; + $_memcache->set('api.user.avatar.' . $userName, $avatarInfo['data'], MEMCACHE_COMPRESS, MEMCACHE_DHT_AVATAR_TIMEOUT); + } else { $response = [ @@ -49,12 +59,26 @@ if (isset($_SESSION['userName'])) { ]; } + // Generate identity icon } else { + $fileName = md5($userName); + $filePath = PROJECT_DIR . '/cache/image/' . $fileName . '.jpeg'; + + if (!file_exists($filePath)) { + + $icon = new Icon(); + $image = $icon->generateImageResource($fileName, 42, 42, false); + + file_put_contents($filePath, $image); + } + + $image = file_get_contents($filePath); + $response = [ - 'success' => false, - 'message' => _('Could not receive avatar details'), - 'avatar' => false + 'success' => true, + 'message' => _('Avatar successfully received from Identity'), + 'avatar' => 'data:image/jpeg;base64,' . base64_encode($image) ]; } diff --git a/src/application/controller/api/user/profile.php b/src/application/controller/api/user/profile.php index 2cbccc1..13c1a6e 100644 --- a/src/application/controller/api/user/profile.php +++ b/src/application/controller/api/user/profile.php @@ -10,7 +10,15 @@ if (isset($_SESSION['userName'])) { $userName = isset($_GET['userName']) ? Filter::userName($_GET['userName']) : $_SESSION['userName']; - if ($userProfileVersions = $_twister->getDHT($userName, 'profile', 's')) { + if ($profile = $_memcache->get('api.user.profile.' . $userName)) { + + $response = [ + 'success' => true, + 'message' => _('Profile successfully received from Cache'), + 'profile' => $profile + ]; + + } else if ($userProfileVersions = $_twister->getDHT($userName, 'profile', 's')) { // Check user exists if ($userId = $_modelUser->getUserId($userName)) { @@ -43,20 +51,24 @@ if (isset($_SESSION['userName'])) { // Get latest version available if ($profileInfo = $_modelProfile->get($userId)) { + $profile = [ + 'userName' => $userName, + 'fullName' => $profileInfo['fullName'], + 'location' => $profileInfo['location'], + 'url' => $profileInfo['url'], + 'bitMessage' => $profileInfo['bitMessage'], + 'tox' => $profileInfo['tox'], + 'bio' => nl2br($profileInfo['bio']), + ]; + $response = [ 'success' => true, - 'message' => _('Profile successfully received'), - 'profile' => [ - 'userName' => $userName, - 'fullName' => $profileInfo['fullName'], - 'location' => $profileInfo['location'], - 'url' => $profileInfo['url'], - 'bitMessage' => $profileInfo['bitMessage'], - 'tox' => $profileInfo['tox'], - 'bio' => nl2br($profileInfo['bio']), - ] + 'message' => _('Profile successfully received from DHT'), + 'profile' => $profile ]; + $_memcache->set('api.user.profile.' . $userName, $profile, MEMCACHE_COMPRESS, MEMCACHE_DHT_PROFILE_TIMEOUT); + } else { $response = [ diff --git a/src/application/view/common/module/post.phtml b/src/application/view/common/module/post.phtml index 62a9a07..963ab9b 100644 --- a/src/application/view/common/module/post.phtml +++ b/src/application/view/common/module/post.phtml @@ -1,7 +1,7 @@