Updated RPCii + offset -> index.
This commit is contained in:
parent
790de26f8a
commit
894a8c2982
5 changed files with 63 additions and 58 deletions
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"require": {
|
||||
"flashwave/index": "^0.2410",
|
||||
"flashii/rpcii": "^2.0",
|
||||
"flashii/rpcii": "^3.0",
|
||||
"flashii/apii": "^0.3",
|
||||
"sentry/sdk": "^4.0",
|
||||
"nesbot/carbon": "^3.7"
|
||||
|
|
88
composer.lock
generated
88
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "e0f4f136fd5f294da46e13de674e9a2b",
|
||||
"content-hash": "7009c2a98d8882c938653f4455f52a82",
|
||||
"packages": [
|
||||
{
|
||||
"name": "carbonphp/carbon-doctrine-types",
|
||||
|
@ -114,20 +114,20 @@
|
|||
},
|
||||
{
|
||||
"name": "flashii/rpcii",
|
||||
"version": "v2.0.1",
|
||||
"version": "v3.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://patchii.net/flashii/rpcii-php.git",
|
||||
"reference": "1cbc1edb061612dc1d014a82e24b741d2a0bc11a"
|
||||
"reference": "25ac46d5dee60027032e175107e638dfb0b8f7f9"
|
||||
},
|
||||
"require": {
|
||||
"ext-msgpack": ">=2.2",
|
||||
"flashwave/index": "^0.2410",
|
||||
"php": ">=8.3"
|
||||
"php": ">=8.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpstan/phpstan": "^2.0",
|
||||
"phpunit/phpunit": "^11.4"
|
||||
"phpstan/phpstan": "^2.1",
|
||||
"phpunit/phpunit": "^11.5"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
|
@ -149,7 +149,7 @@
|
|||
],
|
||||
"description": "HTTP RPC client/server library.",
|
||||
"homepage": "https://railgun.sh/rpcii",
|
||||
"time": "2024-11-14T02:22:09+00:00"
|
||||
"time": "2025-01-17T00:05:22+00:00"
|
||||
},
|
||||
{
|
||||
"name": "flashwave/index",
|
||||
|
@ -383,16 +383,16 @@
|
|||
},
|
||||
{
|
||||
"name": "nesbot/carbon",
|
||||
"version": "3.8.3",
|
||||
"version": "3.8.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/briannesbitt/Carbon.git",
|
||||
"reference": "f01cfa96468f4c38325f507ab81a4f1d2cd93cfe"
|
||||
"url": "https://github.com/CarbonPHP/carbon.git",
|
||||
"reference": "129700ed449b1f02d70272d2ac802357c8c30c58"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/f01cfa96468f4c38325f507ab81a4f1d2cd93cfe",
|
||||
"reference": "f01cfa96468f4c38325f507ab81a4f1d2cd93cfe",
|
||||
"url": "https://api.github.com/repos/CarbonPHP/carbon/zipball/129700ed449b1f02d70272d2ac802357c8c30c58",
|
||||
"reference": "129700ed449b1f02d70272d2ac802357c8c30c58",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -485,7 +485,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-12-21T18:03:19+00:00"
|
||||
"time": "2024-12-27T09:25:35+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/clock",
|
||||
|
@ -974,12 +974,12 @@
|
|||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"url": "https://github.com/symfony/contracts",
|
||||
"name": "symfony/contracts"
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-main": "3.5-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
"url": "https://github.com/symfony/contracts"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -1650,16 +1650,16 @@
|
|||
},
|
||||
{
|
||||
"name": "symfony/translation",
|
||||
"version": "v7.2.0",
|
||||
"version": "v7.2.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/translation.git",
|
||||
"reference": "dc89e16b44048ceecc879054e5b7f38326ab6cc5"
|
||||
"reference": "e2674a30132b7cc4d74540d6c2573aa363f05923"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/translation/zipball/dc89e16b44048ceecc879054e5b7f38326ab6cc5",
|
||||
"reference": "dc89e16b44048ceecc879054e5b7f38326ab6cc5",
|
||||
"url": "https://api.github.com/repos/symfony/translation/zipball/e2674a30132b7cc4d74540d6c2573aa363f05923",
|
||||
"reference": "e2674a30132b7cc4d74540d6c2573aa363f05923",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1725,7 +1725,7 @@
|
|||
"description": "Provides tools to internationalize your application",
|
||||
"homepage": "https://symfony.com",
|
||||
"support": {
|
||||
"source": "https://github.com/symfony/translation/tree/v7.2.0"
|
||||
"source": "https://github.com/symfony/translation/tree/v7.2.2"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -1741,7 +1741,7 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-11-12T20:47:56+00:00"
|
||||
"time": "2024-12-07T08:18:10+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/translation-contracts",
|
||||
|
@ -1762,12 +1762,12 @@
|
|||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"thanks": {
|
||||
"url": "https://github.com/symfony/contracts",
|
||||
"name": "symfony/contracts"
|
||||
},
|
||||
"branch-alias": {
|
||||
"dev-main": "3.5-dev"
|
||||
},
|
||||
"thanks": {
|
||||
"name": "symfony/contracts",
|
||||
"url": "https://github.com/symfony/contracts"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -1823,16 +1823,16 @@
|
|||
},
|
||||
{
|
||||
"name": "twig/html-extra",
|
||||
"version": "v3.17.0",
|
||||
"version": "v3.18.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/twigphp/html-extra.git",
|
||||
"reference": "2086023d3ffc4bae2b1115f715d17f97fd013665"
|
||||
"reference": "c63b28e192c1b7c15bb60f81d2e48b140846239a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/twigphp/html-extra/zipball/2086023d3ffc4bae2b1115f715d17f97fd013665",
|
||||
"reference": "2086023d3ffc4bae2b1115f715d17f97fd013665",
|
||||
"url": "https://api.github.com/repos/twigphp/html-extra/zipball/c63b28e192c1b7c15bb60f81d2e48b140846239a",
|
||||
"reference": "c63b28e192c1b7c15bb60f81d2e48b140846239a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1875,7 +1875,7 @@
|
|||
"twig"
|
||||
],
|
||||
"support": {
|
||||
"source": "https://github.com/twigphp/html-extra/tree/v3.17.0"
|
||||
"source": "https://github.com/twigphp/html-extra/tree/v3.18.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -1887,20 +1887,20 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-09-30T06:41:48+00:00"
|
||||
"time": "2024-12-29T10:29:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "twig/twig",
|
||||
"version": "v3.17.1",
|
||||
"version": "v3.18.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/twigphp/Twig.git",
|
||||
"reference": "677ef8da6497a03048192aeeb5aa3018e379ac71"
|
||||
"reference": "acffa88cc2b40dbe42eaf3a5025d6c0d4600cc50"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/677ef8da6497a03048192aeeb5aa3018e379ac71",
|
||||
"reference": "677ef8da6497a03048192aeeb5aa3018e379ac71",
|
||||
"url": "https://api.github.com/repos/twigphp/Twig/zipball/acffa88cc2b40dbe42eaf3a5025d6c0d4600cc50",
|
||||
"reference": "acffa88cc2b40dbe42eaf3a5025d6c0d4600cc50",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -1955,7 +1955,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/twigphp/Twig/issues",
|
||||
"source": "https://github.com/twigphp/Twig/tree/v3.17.1"
|
||||
"source": "https://github.com/twigphp/Twig/tree/v3.18.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -1967,22 +1967,22 @@
|
|||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2024-12-12T09:58:10+00:00"
|
||||
"time": "2024-12-29T10:51:50+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
{
|
||||
"name": "phpstan/phpstan",
|
||||
"version": "2.0.4",
|
||||
"version": "2.1.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/phpstan/phpstan.git",
|
||||
"reference": "50d276fc3bf1430ec315f2f109bbde2769821524"
|
||||
"reference": "cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/50d276fc3bf1430ec315f2f109bbde2769821524",
|
||||
"reference": "50d276fc3bf1430ec315f2f109bbde2769821524",
|
||||
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7",
|
||||
"reference": "cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -2027,7 +2027,7 @@
|
|||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2024-12-17T17:14:01+00:00"
|
||||
"time": "2025-01-05T16:43:48+00:00"
|
||||
}
|
||||
],
|
||||
"aliases": [],
|
||||
|
|
|
@ -6,6 +6,8 @@ use Index\Config\Config;
|
|||
use Index\Db\DbConnection;
|
||||
|
||||
class TasksContext {
|
||||
public const int CHUNK_SIZE = 4 * 1024 * 1024;
|
||||
|
||||
public private(set) TasksData $tasks;
|
||||
|
||||
public function __construct(
|
||||
|
|
|
@ -9,8 +9,6 @@ use Index\Http\Routing\{HttpPut,RouteHandler,RouteHandlerTrait};
|
|||
class TasksRoutes implements RouteHandler {
|
||||
use RouteHandlerTrait;
|
||||
|
||||
public const int MAX_SIZE = 4 * 1024 * 1024;
|
||||
|
||||
public function __construct(
|
||||
private TasksContext $tasksCtx,
|
||||
) {}
|
||||
|
@ -70,26 +68,26 @@ class TasksRoutes implements RouteHandler {
|
|||
];
|
||||
}
|
||||
|
||||
if($length > self::MAX_SIZE) {
|
||||
if($length > TasksContext::CHUNK_SIZE) {
|
||||
$response->setStatusCode(413);
|
||||
return [
|
||||
'error' => 'content_too_large',
|
||||
'english' => sprintf(
|
||||
'Chunks may not larger than %s, the given chunk was %s.',
|
||||
ByteFormat::format(self::MAX_SIZE, false),
|
||||
ByteFormat::format(TasksContext::CHUNK_SIZE, false),
|
||||
ByteFormat::format($length, false)
|
||||
),
|
||||
'chunk_size' => $length,
|
||||
'max_size' => self::MAX_SIZE,
|
||||
'max_size' => TasksContext::CHUNK_SIZE,
|
||||
];
|
||||
}
|
||||
|
||||
$offset = (int)$request->getParam('offset', FILTER_SANITIZE_NUMBER_INT);
|
||||
if($offset < 0) {
|
||||
$index = (int)$request->getParam('index', FILTER_SANITIZE_NUMBER_INT);
|
||||
if($index < 0) {
|
||||
$response->setStatusCode(400);
|
||||
return [
|
||||
'error' => 'bad_offset',
|
||||
'english' => 'offset parameter must be greater than or equal to 0.',
|
||||
'error' => 'bad_index',
|
||||
'english' => 'index parameter must be greater than or equal to 0.',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -121,6 +119,7 @@ class TasksRoutes implements RouteHandler {
|
|||
];
|
||||
}
|
||||
|
||||
$offset = TasksContext::CHUNK_SIZE * $index;
|
||||
if($offset >= $taskInfo->size) {
|
||||
$response->setStatusCode(400);
|
||||
return [
|
||||
|
|
|
@ -40,7 +40,7 @@ final class TasksRpcHandler implements RpcHandler {
|
|||
return 'fsts';
|
||||
if(strlen($fileType) > 255)
|
||||
return 'fttl';
|
||||
if(substr_count($fileType, '/') !== 1)
|
||||
if(substr_count($fileType, '/') > 1)
|
||||
return 'ftiv';
|
||||
if(mb_strlen($fileName, 'UTF-8') > 255)
|
||||
return 'fntl';
|
||||
|
@ -281,13 +281,17 @@ final class TasksRpcHandler implements RpcHandler {
|
|||
return 'hnm';
|
||||
}
|
||||
|
||||
$storageInfo = $this->storageCtx->importFile($path, type: $taskInfo->type, hash: $hash);
|
||||
$fileType = trim($taskInfo->type, '/');
|
||||
if($fileType === '')
|
||||
$fileType = mime_content_type($path);
|
||||
|
||||
$storageInfo = $this->storageCtx->importFile($path, type: $fileType, hash: $hash);
|
||||
|
||||
try {
|
||||
$variantInfo = $this->uploadsCtx->uploads->resolveUploadVariant(
|
||||
$taskInfo->poolId, $taskInfo->userId, $storageInfo, ''
|
||||
);
|
||||
if(($variantInfo->type ?? $storageInfo->type) !== $taskInfo->type)
|
||||
if(($variantInfo->type ?? $storageInfo->type) !== $fileType)
|
||||
throw new RuntimeException;
|
||||
|
||||
$uploadInfo = $this->uploadsCtx->uploads->getUpload(uploadId: $variantInfo->uploadId);
|
||||
|
@ -307,7 +311,7 @@ final class TasksRpcHandler implements RpcHandler {
|
|||
$taskInfo->createdTime
|
||||
);
|
||||
$variantInfo = $this->uploadsCtx->uploads->createUploadVariant(
|
||||
$uploadInfo, '', $storageInfo, $taskInfo->type
|
||||
$uploadInfo, '', $storageInfo, $fileType
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue