소스 검색

feat: gen admin port randomly instead of a fixed value

M1Screw 2 년 전
부모
커밋
e8db3176e2

+ 1 - 1
composer.json

@@ -22,7 +22,7 @@
         "league/html-to-markdown": "^5.1",
         "league/omnipay": "^3.2.1",
         "mailgun/mailgun-php": "^3",
-        "openai-php/client": "^0.4.2",
+        "openai-php/client": "^0.5.1",
         "ozdemir/datatables": "^2",
         "phpmailer/phpmailer": "^6",
         "postal/postal": "^1.0",

+ 29 - 29
composer.lock

@@ -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": "25dc2e4f81c9c9a83663147e4ca74c70",
+    "content-hash": "2a8168eeedde7a53da86b9371da7afae",
     "packages": [
         {
             "name": "anankke/omnipay-alipay",
@@ -123,16 +123,16 @@
         },
         {
             "name": "aws/aws-sdk-php",
-            "version": "3.271.0",
+            "version": "3.271.3",
             "source": {
                 "type": "git",
                 "url": "https://github.com/aws/aws-sdk-php.git",
-                "reference": "4812b557b375e2d2c8107730c43dfff90c3cf103"
+                "reference": "f481134d37b8303fa2e82ca7fe2a3124144057f6"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/4812b557b375e2d2c8107730c43dfff90c3cf103",
-                "reference": "4812b557b375e2d2c8107730c43dfff90c3cf103",
+                "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/f481134d37b8303fa2e82ca7fe2a3124144057f6",
+                "reference": "f481134d37b8303fa2e82ca7fe2a3124144057f6",
                 "shasum": ""
             },
             "require": {
@@ -212,9 +212,9 @@
             "support": {
                 "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
                 "issues": "https://github.com/aws/aws-sdk-php/issues",
-                "source": "https://github.com/aws/aws-sdk-php/tree/3.271.0"
+                "source": "https://github.com/aws/aws-sdk-php/tree/3.271.3"
             },
-            "time": "2023-05-23T19:11:46+00:00"
+            "time": "2023-05-26T18:20:00+00:00"
         },
         {
             "name": "bacon/bacon-qr-code",
@@ -2584,38 +2584,38 @@
         },
         {
             "name": "openai-php/client",
-            "version": "v0.4.2",
+            "version": "v0.5.1",
             "source": {
                 "type": "git",
                 "url": "https://github.com/openai-php/client.git",
-                "reference": "bbfbc0a28872d679d6990712d7feaae2c9f96fc2"
+                "reference": "34e732f07eec089eb5791730f9f06e6d1669d968"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/openai-php/client/zipball/bbfbc0a28872d679d6990712d7feaae2c9f96fc2",
-                "reference": "bbfbc0a28872d679d6990712d7feaae2c9f96fc2",
+                "url": "https://api.github.com/repos/openai-php/client/zipball/34e732f07eec089eb5791730f9f06e6d1669d968",
+                "reference": "34e732f07eec089eb5791730f9f06e6d1669d968",
                 "shasum": ""
             },
             "require": {
                 "php": "^8.1.0",
-                "php-http/discovery": "^1.15.3",
-                "php-http/multipart-stream-builder": "^1.2.0",
+                "php-http/discovery": "^1.18.1",
+                "php-http/multipart-stream-builder": "^1.3.0",
                 "psr/http-client": "^1.0.2",
                 "psr/http-client-implementation": "^1.0.1",
                 "psr/http-factory-implementation": "*",
                 "psr/http-message": "^1.1.0"
             },
             "require-dev": {
-                "guzzlehttp/guzzle": "^7.5.0",
-                "guzzlehttp/psr7": "^2.4.4",
-                "laravel/pint": "^1.8.0",
-                "nunomaduro/collision": "^7.4.0",
-                "pestphp/pest": "^2.4.0",
-                "pestphp/pest-plugin-arch": "^2.1.1",
+                "guzzlehttp/guzzle": "^7.6.1",
+                "guzzlehttp/psr7": "^2.5.0",
+                "laravel/pint": "^1.10.0",
+                "nunomaduro/collision": "^7.5.2",
+                "pestphp/pest": "^2.6.1",
+                "pestphp/pest-plugin-arch": "^2.1.2",
                 "pestphp/pest-plugin-mock": "^2.0.0",
-                "phpstan/phpstan": "^1.10.11",
+                "phpstan/phpstan": "^1.10.15",
                 "rector/rector": "^0.14.8",
-                "symfony/var-dumper": "^6.2.8"
+                "symfony/var-dumper": "^6.2.10"
             },
             "type": "library",
             "autoload": {
@@ -2655,7 +2655,7 @@
             ],
             "support": {
                 "issues": "https://github.com/openai-php/client/issues",
-                "source": "https://github.com/openai-php/client/tree/v0.4.2"
+                "source": "https://github.com/openai-php/client/tree/v0.5.1"
             },
             "funding": [
                 {
@@ -2671,7 +2671,7 @@
                     "type": "github"
                 }
             ],
-            "time": "2023-04-12T04:26:02+00:00"
+            "time": "2023-05-24T15:57:04+00:00"
         },
         {
             "name": "ozdemir/datatables",
@@ -4766,16 +4766,16 @@
         },
         {
             "name": "stripe/stripe-php",
-            "version": "v10.13.0",
+            "version": "v10.14.0",
             "source": {
                 "type": "git",
                 "url": "https://github.com/stripe/stripe-php.git",
-                "reference": "4ad20dd0a95b2761aecea3d2b2354cc3a99abf9b"
+                "reference": "c88a80fa7f361c2d30d6c81fb71f2bb30be1001f"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/stripe/stripe-php/zipball/4ad20dd0a95b2761aecea3d2b2354cc3a99abf9b",
-                "reference": "4ad20dd0a95b2761aecea3d2b2354cc3a99abf9b",
+                "url": "https://api.github.com/repos/stripe/stripe-php/zipball/c88a80fa7f361c2d30d6c81fb71f2bb30be1001f",
+                "reference": "c88a80fa7f361c2d30d6c81fb71f2bb30be1001f",
                 "shasum": ""
             },
             "require": {
@@ -4821,9 +4821,9 @@
             ],
             "support": {
                 "issues": "https://github.com/stripe/stripe-php/issues",
-                "source": "https://github.com/stripe/stripe-php/tree/v10.13.0"
+                "source": "https://github.com/stripe/stripe-php/tree/v10.14.0"
             },
-            "time": "2023-05-11T19:07:49+00:00"
+            "time": "2023-05-25T18:09:32+00:00"
         },
         {
             "name": "symfony/console",

+ 4 - 4
resources/views/tabler/admin/coupon.tpl

@@ -182,8 +182,8 @@
                 },
                 success: function(data) {
                     if (data.ret === 1) {
-                        $('#success-message').text(data.msg);
-                        $('#success-dialog').modal('show');
+                        $('#success-noreload-message').text(data.msg);
+                        $('#success-noreload-dialog').modal('show');
                         reloadTableAjax();
                     } else {
                         $('#fail-message').text(data.msg);
@@ -225,8 +225,8 @@
                     dataType: "json",
                     success: function(data) {
                         if (data.ret === 1) {
-                            $('#success-message').text(data.msg);
-                            $('#success-dialog').modal('show');
+                            $('#success-noreload-dialog').text(data.msg);
+                            $('#success-noreload-message').modal('show');
                             reloadTableAjax();
                         } else {
                             $('#fail-message').text(data.msg);

+ 2 - 2
resources/views/tabler/user/order/create.tpl

@@ -165,8 +165,8 @@
                 },
                 success: function(data) {
                     if (data.ret === 1) {
-                        $('#success-message').text(data.msg);
-                        $('#success-dialog').modal('show');
+                        $('#success-noreload-message').text(data.msg);
+                        $('#success-noreload-dialog').modal('show');
                         setTimeout(function() {
                             $(location).attr('href', '/user/invoice/' + data.invoice_id + '/view');
                         }, 1500);

+ 1 - 1
src/Command/Tool.php

@@ -296,7 +296,7 @@ EOL;
             $user->passwd = Tools::genRandomChar(16);
             $user->uuid = Uuid::uuid4();
             $user->api_token = Uuid::uuid4();
-            $user->port = Tools::getLastPort() + 1;
+            $user->port = Tools::getAvPort();
             $user->t = 0;
             $user->u = 0;
             $user->d = 0;

+ 1 - 5
src/Controllers/UserController.php

@@ -562,11 +562,7 @@ final class UserController extends BaseController
     {
         $user = $this->user;
 
-        if ($user->is_dark_mode === 1) {
-            $user->is_dark_mode = 0;
-        } else {
-            $user->is_dark_mode = 1;
-        }
+        $user->is_dark_mode = $user->is_dark_mode === 1 ? 0 : 1;
 
         if (! $user->save()) {
             return ResponseHelper::error($response, '切换失败');

+ 1 - 0
src/Middleware/NodeToken.php

@@ -16,6 +16,7 @@ final class NodeToken implements MiddlewareInterface
     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
     {
         $key = $request->getQueryParams()['key'] ?? null;
+
         if ($key === null) {
             // 未提供 key
             return AppFactory::determineResponseFactory()->createResponse(401)->withJson([

+ 5 - 7
src/Utils/ResponseHelper.php

@@ -36,22 +36,20 @@ final class ResponseHelper
      * @param RequestInterface $request
      * @param ResponseInterface $response
      * @param mixed $data
-     * @param int $flags
      *
      * @return ResponseInterface
      */
     public static function etagJson(
         RequestInterface $request,
         ResponseInterface $response,
-        mixed $data,
-        int $flags = 0
+        mixed $data
     ): ResponseInterface {
-        $str = (string) json_encode($data, $flags);
-        $etag = hash('crc32c', $str);
+        $etag = 'W/"' . hash('xxh64', (string) json_encode($data)) . '"';
+
         if ($etag === $request->getHeaderLine('If-None-Match')) {
             return $response->withStatus(304);
         }
-        $response->getBody()->write($str);
-        return $response->withHeader('ETag', $etag)->withHeader('Content-Type', 'application/json');
+
+        return $response->withHeader('ETag', $etag)->withJson($data);
     }
 }

+ 0 - 11
src/Utils/Tools.php

@@ -150,17 +150,6 @@ final class Tools
         return date('Y-m-d H:i:s', $time);
     }
 
-    public static function getLastPort()
-    {
-        $user = User::orderBy('id', 'desc')->first();
-
-        if ($user === null) {
-            return 1024;
-        }
-
-        return $user->port;
-    }
-
     public static function getAvPort()
     {
         if (Setting::obtain('min_port') > 65535