mirror of
https://github.com/twisterarmy/cloud-server.git
synced 2025-03-12 13:31:04 +00:00
implement DHT data cache
This commit is contained in:
parent
e7311b038c
commit
72949e0834
Binary file not shown.
@ -1,21 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
if (isset($_GET['hash'])) {
|
|
||||||
|
|
||||||
$fileName = md5($_GET['hash']);
|
|
||||||
$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);
|
|
||||||
|
|
||||||
header("Content-Type: image/jpeg");
|
|
||||||
|
|
||||||
echo $image;
|
|
||||||
}
|
|
@ -10,7 +10,15 @@ if (isset($_SESSION['userName'])) {
|
|||||||
|
|
||||||
$userName = isset($_GET['userName']) ? Filter::userName($_GET['userName']) : $_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
|
// Check avatar exists
|
||||||
if ($userId = $_modelUser->getUserId($userName)) {
|
if ($userId = $_modelUser->getUserId($userName)) {
|
||||||
@ -36,10 +44,12 @@ if (isset($_SESSION['userName'])) {
|
|||||||
|
|
||||||
$response = [
|
$response = [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'message' => _('Avatar successfully received'),
|
'message' => _('Avatar successfully received from DHT'),
|
||||||
'avatar' => $avatarInfo['data']
|
'avatar' => $avatarInfo['data']
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$_memcache->set('api.user.avatar.' . $userName, $avatarInfo['data'], MEMCACHE_COMPRESS, MEMCACHE_DHT_AVATAR_TIMEOUT);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$response = [
|
$response = [
|
||||||
@ -49,12 +59,26 @@ if (isset($_SESSION['userName'])) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate identity icon
|
||||||
} else {
|
} 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 = [
|
$response = [
|
||||||
'success' => false,
|
'success' => true,
|
||||||
'message' => _('Could not receive avatar details'),
|
'message' => _('Avatar successfully received from Identity'),
|
||||||
'avatar' => false
|
'avatar' => 'data:image/jpeg;base64,' . base64_encode($image)
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,15 @@ if (isset($_SESSION['userName'])) {
|
|||||||
|
|
||||||
$userName = isset($_GET['userName']) ? Filter::userName($_GET['userName']) : $_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
|
// Check user exists
|
||||||
if ($userId = $_modelUser->getUserId($userName)) {
|
if ($userId = $_modelUser->getUserId($userName)) {
|
||||||
@ -43,20 +51,24 @@ if (isset($_SESSION['userName'])) {
|
|||||||
// Get latest version available
|
// Get latest version available
|
||||||
if ($profileInfo = $_modelProfile->get($userId)) {
|
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 = [
|
$response = [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'message' => _('Profile successfully received'),
|
'message' => _('Profile successfully received from DHT'),
|
||||||
'profile' => [
|
'profile' => $profile
|
||||||
'userName' => $userName,
|
|
||||||
'fullName' => $profileInfo['fullName'],
|
|
||||||
'location' => $profileInfo['location'],
|
|
||||||
'url' => $profileInfo['url'],
|
|
||||||
'bitMessage' => $profileInfo['bitMessage'],
|
|
||||||
'tox' => $profileInfo['tox'],
|
|
||||||
'bio' => nl2br($profileInfo['bio']),
|
|
||||||
]
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$_memcache->set('api.user.profile.' . $userName, $profile, MEMCACHE_COMPRESS, MEMCACHE_DHT_PROFILE_TIMEOUT);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$response = [
|
$response = [
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<div class="modulePost" id="modulePost">
|
<div class="modulePost" id="modulePost">
|
||||||
<form action="/" method="POST" name="post">
|
<form action="/" method="POST" name="post">
|
||||||
<div class="avatar">
|
<div class="avatar">
|
||||||
<img src="<?php echo PROJECT_HOST ?>/api/image?hash=<?php echo $_SESSION['userName'] ?>" alt="" />
|
<img src="" alt="" />
|
||||||
</div>
|
</div>
|
||||||
<div class="message">
|
<div class="message">
|
||||||
<textarea name="post" placeholder="<?php echo _('Enter your post...') ?>"></textarea>
|
<textarea name="post" placeholder="<?php echo _('Enter your post...') ?>"></textarea>
|
||||||
|
@ -25,6 +25,9 @@ define('TWISTER_PASSWORD', '');
|
|||||||
// MEMCACHE
|
// MEMCACHE
|
||||||
define('MEMCACHE_HOST', 'localhost');
|
define('MEMCACHE_HOST', 'localhost');
|
||||||
define('MEMCACHE_PORT', 11211);
|
define('MEMCACHE_PORT', 11211);
|
||||||
|
define('MEMCACHE_COMPRESS', false);
|
||||||
|
define('MEMCACHE_DHT_AVATAR_TIMEOUT', 3600);
|
||||||
|
define('MEMCACHE_DHT_PROFILE_TIMEOUT', 3600);
|
||||||
|
|
||||||
// COMMON
|
// COMMON
|
||||||
define('APPLICATION_ALLOW_REGISTRATION', true);
|
define('APPLICATION_ALLOW_REGISTRATION', true);
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
border: 2px #fff solid;
|
border: 2px #fff solid;
|
||||||
width: 46px;
|
width: 46px;
|
||||||
height: 46px;
|
height: 46px;
|
||||||
|
display: none
|
||||||
}
|
}
|
||||||
|
|
||||||
.moduleFeed .item .message {
|
.moduleFeed .item .message {
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
border: 2px #fff solid;
|
border: 2px #fff solid;
|
||||||
width: 16px;
|
width: 16px;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
|
display: none
|
||||||
}
|
}
|
||||||
|
|
||||||
.moduleFollowing .item .action {
|
.moduleFollowing .item .action {
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
border: 2px #fff solid;
|
border: 2px #fff solid;
|
||||||
width: 46px;
|
width: 46px;
|
||||||
height: 46px;
|
height: 46px;
|
||||||
|
display: none
|
||||||
}
|
}
|
||||||
|
|
||||||
.modulePost .message {
|
.modulePost .message {
|
||||||
|
@ -38,7 +38,7 @@ var ModuleFeed = {
|
|||||||
'href': 'people/' + userName
|
'href': 'people/' + userName
|
||||||
}).append(
|
}).append(
|
||||||
$('<img/>', {
|
$('<img/>', {
|
||||||
'src': '/api/image?hash=' + userName,
|
'src': '',
|
||||||
'alt': '',
|
'alt': '',
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -83,7 +83,7 @@ var ModuleFeed = {
|
|||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
|
||||||
if (response.avatar) {
|
if (response.avatar) {
|
||||||
$(feed).find('div[data-username="' + userName + '"] .avatar img').attr('src', response.avatar);
|
$(feed).find('div[data-username="' + userName + '"] .avatar img').attr('src', response.avatar).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -15,7 +15,7 @@ var ModuleFollowing = {
|
|||||||
'href': 'people/' + userName
|
'href': 'people/' + userName
|
||||||
}).append(
|
}).append(
|
||||||
$('<img/>', {
|
$('<img/>', {
|
||||||
'src': '/api/image?hash=' + userName,
|
'src': '',
|
||||||
'alt': '',
|
'alt': '',
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -94,7 +94,7 @@ var ModuleFollowing = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function(jqXHR, textStatus, errorThrown) {
|
error: function(jqXHR, textStatus, errorThrown) {
|
||||||
console.log(textStatus, errorThrown);
|
console.log(textStatus, errorThrown);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -110,7 +110,7 @@ var ModuleFollowing = {
|
|||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
|
||||||
if (response.avatar) {
|
if (response.avatar) {
|
||||||
$(list).find('div[data-username="' + userName + '"] .avatar img').attr('src', response.avatar);
|
$(list).find('div[data-username="' + userName + '"] .avatar img').attr('src', response.avatar).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -120,7 +120,7 @@ var ModuleFollowing = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function(jqXHR, textStatus, errorThrown) {
|
error: function(jqXHR, textStatus, errorThrown) {
|
||||||
console.log(textStatus, errorThrown);
|
console.log(textStatus, errorThrown);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -149,7 +149,7 @@ var ModuleFollowing = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function(jqXHR, textStatus, errorThrown) {
|
error: function(jqXHR, textStatus, errorThrown) {
|
||||||
console.log(textStatus, errorThrown);
|
console.log(textStatus, errorThrown);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -176,7 +176,7 @@ var ModuleFollowing = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function(jqXHR, textStatus, errorThrown) {
|
error: function(jqXHR, textStatus, errorThrown) {
|
||||||
console.log(textStatus, errorThrown);
|
console.log(textStatus, errorThrown);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -11,7 +11,7 @@ var ModulePost = {
|
|||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
|
||||||
if (response.avatar) {
|
if (response.avatar) {
|
||||||
$(element).find('img').attr('src', response.avatar);
|
$(element).find('img').attr('src', response.avatar).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -27,7 +27,7 @@ var ModulePost = {
|
|||||||
},
|
},
|
||||||
add: function() {
|
add: function() {
|
||||||
|
|
||||||
var input = $('#modulePost > .message > textarea');
|
var input = $('#modulePost > .message > textarea');
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'api/post/add',
|
url: 'api/post/add',
|
||||||
|
@ -14,7 +14,7 @@ var ModuleUsers = {
|
|||||||
'href': 'people/' + userName
|
'href': 'people/' + userName
|
||||||
}).append(
|
}).append(
|
||||||
$('<img/>', {
|
$('<img/>', {
|
||||||
'src': '/api/image?hash=' + userName,
|
'src': '',
|
||||||
'alt': '',
|
'alt': '',
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user