mirror of
https://github.com/kevachat/webapp.git
synced 2025-01-22 12:34:25 +00:00
rollback key format
This commit is contained in:
parent
650f311caa
commit
a99d5e5be4
2
.env
2
.env
@ -104,7 +104,7 @@ APP_ADD_POST_REMOTE_IP_DENIED=
|
||||
|
||||
# Post ID rules (for kevacoin key)
|
||||
# do not change to keep external KevaChat nodes compatibility
|
||||
APP_ADD_POST_KEY_REGEX=/^[A-z0-9-]{1,520}$/
|
||||
APP_ADD_POST_KEY_REGEX=/^([\d]{1,260})@([A-z0-9-_]{1,260})$/
|
||||
|
||||
# Post content rules (for kevacoin value, max length is 3072)
|
||||
# do not change to keep external KevaChat nodes compatibility
|
||||
|
@ -227,7 +227,7 @@ class RoomController extends AbstractController
|
||||
}
|
||||
|
||||
// Require valid kevachat meta
|
||||
if ($data = $this->_post($client, $pending))
|
||||
if ($data = $this->_post($pending))
|
||||
{
|
||||
// Detect parent post
|
||||
preg_match(self::PARENT_REGEX, $data->message, $mention);
|
||||
@ -260,7 +260,7 @@ class RoomController extends AbstractController
|
||||
}
|
||||
|
||||
// Require valid kevachat meta
|
||||
if ($data = $this->_post($client, $post))
|
||||
if ($data = $this->_post($post))
|
||||
{
|
||||
// Detect parent post
|
||||
preg_match(self::PARENT_REGEX, $data->message, $mention);
|
||||
@ -614,7 +614,11 @@ class RoomController extends AbstractController
|
||||
if (
|
||||
$client->kevaPut(
|
||||
$request->get('namespace'),
|
||||
$username,
|
||||
sprintf(
|
||||
'%d@%s',
|
||||
time(),
|
||||
$username
|
||||
),
|
||||
$request->get('message')
|
||||
)
|
||||
) {
|
||||
@ -681,7 +685,11 @@ class RoomController extends AbstractController
|
||||
);
|
||||
|
||||
$pool->setKey(
|
||||
$username
|
||||
sprintf(
|
||||
'%d@%s',
|
||||
time(),
|
||||
$username
|
||||
),
|
||||
);
|
||||
|
||||
$pool->setValue(
|
||||
@ -731,7 +739,11 @@ class RoomController extends AbstractController
|
||||
if (
|
||||
$client->kevaPut(
|
||||
$request->get('namespace'),
|
||||
$username,
|
||||
sprintf(
|
||||
'%d@%s',
|
||||
time(),
|
||||
$username
|
||||
),
|
||||
$request->get('message')
|
||||
)
|
||||
)
|
||||
@ -1092,10 +1104,7 @@ class RoomController extends AbstractController
|
||||
);
|
||||
}
|
||||
|
||||
private function _post(
|
||||
\Kevachat\Kevacoin\Client $client,
|
||||
array $data
|
||||
): ?object
|
||||
private function _post(array $data): ?object
|
||||
{
|
||||
// Validate required data
|
||||
if (empty($data['txid']))
|
||||
@ -1113,23 +1122,8 @@ class RoomController extends AbstractController
|
||||
return null;
|
||||
}
|
||||
|
||||
// Skip values with meta keys
|
||||
if (str_starts_with($data['key'], '_'))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Legacy key format support (protocol v1 contain timestamp in prefix)
|
||||
if (preg_match('/^([\d]+)@([A-z0-9\.\:\[\]]+)/', $data['key'], $matches))
|
||||
{
|
||||
if (!empty($matches[2]))
|
||||
{
|
||||
$data['key'] = $matches[2];
|
||||
}
|
||||
}
|
||||
|
||||
// Validate key format allowed in settings
|
||||
if (!preg_match((string) $this->getParameter('app.add.post.key.regex'), $data['key']))
|
||||
if (!preg_match((string) $this->getParameter('app.add.post.key.regex'), $data['key'], $key))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -1140,8 +1134,8 @@ class RoomController extends AbstractController
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get time from raw transaction
|
||||
if (!$transaction = $client->getRawTransaction($data['txid']))
|
||||
// Validate timestamp@username
|
||||
if (empty($key[1]) || empty($key[2]))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -1155,9 +1149,9 @@ class RoomController extends AbstractController
|
||||
return (object)
|
||||
[
|
||||
'id' => $data['txid'],
|
||||
'user' => $data['key'],
|
||||
'message' => $data['value'],
|
||||
'time' => $transaction['time']
|
||||
'time' => $key[1],
|
||||
'user' => $key[2],
|
||||
'message' => $data['value']
|
||||
];
|
||||
}
|
||||
|
||||
@ -1224,7 +1218,7 @@ class RoomController extends AbstractController
|
||||
foreach ($raw as $data)
|
||||
{
|
||||
// Is valid post
|
||||
if ($this->_post($client, $data))
|
||||
if ($this->_post($data))
|
||||
{
|
||||
$total++;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user