Updated RPCii + offset -> index.

This commit is contained in:
flash 2025-01-17 06:48:57 +00:00
parent 790de26f8a
commit 894a8c2982
5 changed files with 63 additions and 58 deletions

View file

@ -1,7 +1,7 @@
{ {
"require": { "require": {
"flashwave/index": "^0.2410", "flashwave/index": "^0.2410",
"flashii/rpcii": "^2.0", "flashii/rpcii": "^3.0",
"flashii/apii": "^0.3", "flashii/apii": "^0.3",
"sentry/sdk": "^4.0", "sentry/sdk": "^4.0",
"nesbot/carbon": "^3.7" "nesbot/carbon": "^3.7"

88
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "e0f4f136fd5f294da46e13de674e9a2b", "content-hash": "7009c2a98d8882c938653f4455f52a82",
"packages": [ "packages": [
{ {
"name": "carbonphp/carbon-doctrine-types", "name": "carbonphp/carbon-doctrine-types",
@ -114,20 +114,20 @@
}, },
{ {
"name": "flashii/rpcii", "name": "flashii/rpcii",
"version": "v2.0.1", "version": "v3.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://patchii.net/flashii/rpcii-php.git", "url": "https://patchii.net/flashii/rpcii-php.git",
"reference": "1cbc1edb061612dc1d014a82e24b741d2a0bc11a" "reference": "25ac46d5dee60027032e175107e638dfb0b8f7f9"
}, },
"require": { "require": {
"ext-msgpack": ">=2.2", "ext-msgpack": ">=2.2",
"flashwave/index": "^0.2410", "flashwave/index": "^0.2410",
"php": ">=8.3" "php": ">=8.4"
}, },
"require-dev": { "require-dev": {
"phpstan/phpstan": "^2.0", "phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^11.4" "phpunit/phpunit": "^11.5"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -149,7 +149,7 @@
], ],
"description": "HTTP RPC client/server library.", "description": "HTTP RPC client/server library.",
"homepage": "https://railgun.sh/rpcii", "homepage": "https://railgun.sh/rpcii",
"time": "2024-11-14T02:22:09+00:00" "time": "2025-01-17T00:05:22+00:00"
}, },
{ {
"name": "flashwave/index", "name": "flashwave/index",
@ -383,16 +383,16 @@
}, },
{ {
"name": "nesbot/carbon", "name": "nesbot/carbon",
"version": "3.8.3", "version": "3.8.4",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/briannesbitt/Carbon.git", "url": "https://github.com/CarbonPHP/carbon.git",
"reference": "f01cfa96468f4c38325f507ab81a4f1d2cd93cfe" "reference": "129700ed449b1f02d70272d2ac802357c8c30c58"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/f01cfa96468f4c38325f507ab81a4f1d2cd93cfe", "url": "https://api.github.com/repos/CarbonPHP/carbon/zipball/129700ed449b1f02d70272d2ac802357c8c30c58",
"reference": "f01cfa96468f4c38325f507ab81a4f1d2cd93cfe", "reference": "129700ed449b1f02d70272d2ac802357c8c30c58",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -485,7 +485,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-12-21T18:03:19+00:00" "time": "2024-12-27T09:25:35+00:00"
}, },
{ {
"name": "psr/clock", "name": "psr/clock",
@ -974,12 +974,12 @@
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"thanks": {
"url": "https://github.com/symfony/contracts",
"name": "symfony/contracts"
},
"branch-alias": { "branch-alias": {
"dev-main": "3.5-dev" "dev-main": "3.5-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
} }
}, },
"autoload": { "autoload": {
@ -1650,16 +1650,16 @@
}, },
{ {
"name": "symfony/translation", "name": "symfony/translation",
"version": "v7.2.0", "version": "v7.2.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/translation.git", "url": "https://github.com/symfony/translation.git",
"reference": "dc89e16b44048ceecc879054e5b7f38326ab6cc5" "reference": "e2674a30132b7cc4d74540d6c2573aa363f05923"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/translation/zipball/dc89e16b44048ceecc879054e5b7f38326ab6cc5", "url": "https://api.github.com/repos/symfony/translation/zipball/e2674a30132b7cc4d74540d6c2573aa363f05923",
"reference": "dc89e16b44048ceecc879054e5b7f38326ab6cc5", "reference": "e2674a30132b7cc4d74540d6c2573aa363f05923",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1725,7 +1725,7 @@
"description": "Provides tools to internationalize your application", "description": "Provides tools to internationalize your application",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/translation/tree/v7.2.0" "source": "https://github.com/symfony/translation/tree/v7.2.2"
}, },
"funding": [ "funding": [
{ {
@ -1741,7 +1741,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-11-12T20:47:56+00:00" "time": "2024-12-07T08:18:10+00:00"
}, },
{ {
"name": "symfony/translation-contracts", "name": "symfony/translation-contracts",
@ -1762,12 +1762,12 @@
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"thanks": {
"url": "https://github.com/symfony/contracts",
"name": "symfony/contracts"
},
"branch-alias": { "branch-alias": {
"dev-main": "3.5-dev" "dev-main": "3.5-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
} }
}, },
"autoload": { "autoload": {
@ -1823,16 +1823,16 @@
}, },
{ {
"name": "twig/html-extra", "name": "twig/html-extra",
"version": "v3.17.0", "version": "v3.18.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/twigphp/html-extra.git", "url": "https://github.com/twigphp/html-extra.git",
"reference": "2086023d3ffc4bae2b1115f715d17f97fd013665" "reference": "c63b28e192c1b7c15bb60f81d2e48b140846239a"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/twigphp/html-extra/zipball/2086023d3ffc4bae2b1115f715d17f97fd013665", "url": "https://api.github.com/repos/twigphp/html-extra/zipball/c63b28e192c1b7c15bb60f81d2e48b140846239a",
"reference": "2086023d3ffc4bae2b1115f715d17f97fd013665", "reference": "c63b28e192c1b7c15bb60f81d2e48b140846239a",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1875,7 +1875,7 @@
"twig" "twig"
], ],
"support": { "support": {
"source": "https://github.com/twigphp/html-extra/tree/v3.17.0" "source": "https://github.com/twigphp/html-extra/tree/v3.18.0"
}, },
"funding": [ "funding": [
{ {
@ -1887,20 +1887,20 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-09-30T06:41:48+00:00" "time": "2024-12-29T10:29:59+00:00"
}, },
{ {
"name": "twig/twig", "name": "twig/twig",
"version": "v3.17.1", "version": "v3.18.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/twigphp/Twig.git", "url": "https://github.com/twigphp/Twig.git",
"reference": "677ef8da6497a03048192aeeb5aa3018e379ac71" "reference": "acffa88cc2b40dbe42eaf3a5025d6c0d4600cc50"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/twigphp/Twig/zipball/677ef8da6497a03048192aeeb5aa3018e379ac71", "url": "https://api.github.com/repos/twigphp/Twig/zipball/acffa88cc2b40dbe42eaf3a5025d6c0d4600cc50",
"reference": "677ef8da6497a03048192aeeb5aa3018e379ac71", "reference": "acffa88cc2b40dbe42eaf3a5025d6c0d4600cc50",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1955,7 +1955,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/twigphp/Twig/issues", "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": [ "funding": [
{ {
@ -1967,22 +1967,22 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-12-12T09:58:10+00:00" "time": "2024-12-29T10:51:50+00:00"
} }
], ],
"packages-dev": [ "packages-dev": [
{ {
"name": "phpstan/phpstan", "name": "phpstan/phpstan",
"version": "2.0.4", "version": "2.1.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpstan.git", "url": "https://github.com/phpstan/phpstan.git",
"reference": "50d276fc3bf1430ec315f2f109bbde2769821524" "reference": "cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/50d276fc3bf1430ec315f2f109bbde2769821524", "url": "https://api.github.com/repos/phpstan/phpstan/zipball/cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7",
"reference": "50d276fc3bf1430ec315f2f109bbde2769821524", "reference": "cd6e973e04b4c2b94c86e8612b5a65f0da0e08e7",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2027,7 +2027,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2024-12-17T17:14:01+00:00" "time": "2025-01-05T16:43:48+00:00"
} }
], ],
"aliases": [], "aliases": [],

View file

@ -6,6 +6,8 @@ use Index\Config\Config;
use Index\Db\DbConnection; use Index\Db\DbConnection;
class TasksContext { class TasksContext {
public const int CHUNK_SIZE = 4 * 1024 * 1024;
public private(set) TasksData $tasks; public private(set) TasksData $tasks;
public function __construct( public function __construct(

View file

@ -9,8 +9,6 @@ use Index\Http\Routing\{HttpPut,RouteHandler,RouteHandlerTrait};
class TasksRoutes implements RouteHandler { class TasksRoutes implements RouteHandler {
use RouteHandlerTrait; use RouteHandlerTrait;
public const int MAX_SIZE = 4 * 1024 * 1024;
public function __construct( public function __construct(
private TasksContext $tasksCtx, private TasksContext $tasksCtx,
) {} ) {}
@ -70,26 +68,26 @@ class TasksRoutes implements RouteHandler {
]; ];
} }
if($length > self::MAX_SIZE) { if($length > TasksContext::CHUNK_SIZE) {
$response->setStatusCode(413); $response->setStatusCode(413);
return [ return [
'error' => 'content_too_large', 'error' => 'content_too_large',
'english' => sprintf( 'english' => sprintf(
'Chunks may not larger than %s, the given chunk was %s.', '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) ByteFormat::format($length, false)
), ),
'chunk_size' => $length, 'chunk_size' => $length,
'max_size' => self::MAX_SIZE, 'max_size' => TasksContext::CHUNK_SIZE,
]; ];
} }
$offset = (int)$request->getParam('offset', FILTER_SANITIZE_NUMBER_INT); $index = (int)$request->getParam('index', FILTER_SANITIZE_NUMBER_INT);
if($offset < 0) { if($index < 0) {
$response->setStatusCode(400); $response->setStatusCode(400);
return [ return [
'error' => 'bad_offset', 'error' => 'bad_index',
'english' => 'offset parameter must be greater than or equal to 0.', '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) { if($offset >= $taskInfo->size) {
$response->setStatusCode(400); $response->setStatusCode(400);
return [ return [

View file

@ -40,7 +40,7 @@ final class TasksRpcHandler implements RpcHandler {
return 'fsts'; return 'fsts';
if(strlen($fileType) > 255) if(strlen($fileType) > 255)
return 'fttl'; return 'fttl';
if(substr_count($fileType, '/') !== 1) if(substr_count($fileType, '/') > 1)
return 'ftiv'; return 'ftiv';
if(mb_strlen($fileName, 'UTF-8') > 255) if(mb_strlen($fileName, 'UTF-8') > 255)
return 'fntl'; return 'fntl';
@ -281,13 +281,17 @@ final class TasksRpcHandler implements RpcHandler {
return 'hnm'; 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 { try {
$variantInfo = $this->uploadsCtx->uploads->resolveUploadVariant( $variantInfo = $this->uploadsCtx->uploads->resolveUploadVariant(
$taskInfo->poolId, $taskInfo->userId, $storageInfo, '' $taskInfo->poolId, $taskInfo->userId, $storageInfo, ''
); );
if(($variantInfo->type ?? $storageInfo->type) !== $taskInfo->type) if(($variantInfo->type ?? $storageInfo->type) !== $fileType)
throw new RuntimeException; throw new RuntimeException;
$uploadInfo = $this->uploadsCtx->uploads->getUpload(uploadId: $variantInfo->uploadId); $uploadInfo = $this->uploadsCtx->uploads->getUpload(uploadId: $variantInfo->uploadId);
@ -307,7 +311,7 @@ final class TasksRpcHandler implements RpcHandler {
$taskInfo->createdTime $taskInfo->createdTime
); );
$variantInfo = $this->uploadsCtx->uploads->createUploadVariant( $variantInfo = $this->uploadsCtx->uploads->createUploadVariant(
$uploadInfo, '', $storageInfo, $taskInfo->type $uploadInfo, '', $storageInfo, $fileType
); );
} }