Skip to content

Commit

Permalink
fix upload image & file and origin wrong
Browse files Browse the repository at this point in the history
  • Loading branch information
brewlin committed May 18, 2019
1 parent 49d8ee7 commit 220cb23
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 60 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
*LICENSE
*phpunit.xml
*_CN.md
*.phpintel/
*.phpintel/
swoft-master
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Rpc 接口依赖
"repositories": {
"0":{
"type":"vcs",//git源
"url":"http://www.github.com/Lxido/service-components" //公用composer包
"url":"http://www.github.com/brewlin/service-components" //公用composer包
},
"packagist": {
"type": "composer",
Expand Down
1 change: 0 additions & 1 deletion gateway-api/app/Controllers/Api/InitController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* Class InitController
* @package App\Controllers\Api
* @Controller("api/im")
* @Middleware(TokenCheckMiddleware::class)
*/
class InitController
{
Expand Down
1 change: 1 addition & 0 deletions gateway-api/app/Controllers/Api/ToolController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function uploadImage()
$clientName = $file->getClientFilename();
$src = $this->getFullPath($file,$type , $clientName);
$file->moveTo('@upload'.$src);
chmod(App::getAlias('@upload').$src,0777);
return Message::success(compact('src'),'',0);
}

Expand Down
7 changes: 5 additions & 2 deletions gateway-api/app/Controllers/Api/UserRecordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

namespace App\Controllers\Api;
use App\Middlewares\ControllerMiddleware;
use ServiceComponents\Common\Message;
use ServiceComponents\Rpc\User\RecordServiceInterface;
use Swoft\Bean\Annotation\Strings;
Expand All @@ -16,11 +17,13 @@
use Swoft\Http\Server\Bean\Annotation\RequestMapping;
use Swoft\Http\Server\Bean\Annotation\RequestMethod;
use Swoft\Rpc\Client\Bean\Annotation\Reference;
use Swoft\Http\Message\Bean\Annotation\Middleware;

/**
* Class UserRecordControoler
* @package App\Controllers\Api
* @Controller(prefix="/api/im")
* @Middleware(ControllerMiddleware::class)
*/
class UserRecordController extends BaseController
{
Expand Down Expand Up @@ -54,9 +57,9 @@ public function getChatRecordByToken()
public function updateIsReadChatRecord($request)
{
$this->getCurrentUser();
$where = ['to_id' => $this->user['id'],'uid' => $request->post('uid'),'is_read' => 0];
$where = ['friend_id' => $this->user['id'],'user_id' => request()->post('uid'),'is_read' => 0];
$data = ['is_read' => 1];
$type = $request->post('type');
$type = request()->post('type');
$this->userRecordService->updateChatRecordIsRead($where,$data,$type);
return Message::success([],'收取消息成功');
}
Expand Down
28 changes: 21 additions & 7 deletions gateway-api/app/Exception/SwoftExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public function handlerException(Response $response, \Throwable $throwable)

$data = ['code' => $code,'msg' => $exception,'data' => $data,'statusCode' => $statusCode, 'file' => $file, 'line' => $line];
App::error(json_encode($data));
return $response->json($data);
$response->json($data);
return $this->handleOrigin($response);
}

/**
Expand All @@ -80,7 +81,8 @@ public function handlerRpcStatusException(Response $response,\Throwable $throwab
$status = $throwable->getStatus();
$data = $throwable->getData();
$returnData = ['code' => StatusEnum::Fail,'msg' => $msg,'data' => $data,'statusCode' => $status];
return $response->json($returnData);
$response->json($returnData);
return $this->handleOrigin($response);
}
/**
* 捕获Rpc Response解析失败(未设置服务降级)
Expand All @@ -92,7 +94,8 @@ public function handlerRpcResponseException(Response $response,\Throwable $throw
{
$data = $throwable->getResponse();
$returnData = ['code' => StatusEnum::Fail,'msg' => '','data' => $data,'statusCode' => 10000];
return $response->json($returnData);
$response->json($returnData);
return $this->handleOrigin($response);
}

/**
Expand All @@ -105,7 +108,8 @@ public function handlerRpcClientException(Response $response,\Throwable $throwab
{
$msg = $throwable->getMessage();
$returnData = ['code' => StatusEnum::Fail,'msg' => $msg,'data' => '服务未开机','statusCode' => 10000];
return $response->json($returnData);
$response->json($returnData);
return $this->handleOrigin($response);
}
/**
* @Handler(RuntimeException::class)
Expand All @@ -121,7 +125,8 @@ public function handlerRuntimeException(Response $response, \Throwable $throwabl
$code = $throwable->getCode();
$exception = $throwable->getMessage();

return $response->json([$exception, 'runtimeException']);
$response->json([$exception, 'runtimeException']);
return $this->handleOrigin($response);
}

/**
Expand All @@ -136,7 +141,8 @@ public function handlerValidatorException(Response $response, \Throwable $throwa
{
$exception = $throwable->getMessage();

return $response->json(['code' => 4,'data' => [],'msg' => $exception]);
$response->json(['code' => 4,'data' => [],'msg' => $exception]);
return $this->handleOrigin($response);
}


Expand All @@ -153,7 +159,9 @@ public function handlerBadRequestException(Response $response, \Throwable $throw
{
$exception = $throwable->getMessage();

return $response->json(['message' => $exception]);
$response->json(['message' => $exception]);
return $this->handleOrigin($response);

}

/**
Expand Down Expand Up @@ -198,5 +206,11 @@ public function handlerViewException(Request $request, Response $response, \Thro

return view('exception/index', $data);
}
public function handleOrigin(Response $response){
return $response->withHeader('Access-Control-Allow-Origin', '*')
->withHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
->withHeader('Access-Control-Allow-Credentials', 'true')
->withHeader('Access-Control-Allow-Headers', 'token');
}

}
1 change: 1 addition & 0 deletions gateway-api/app/Middlewares/ControllerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ControllerMiddleware implements MiddlewareInterface
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
echo "\n\n[debug]---".$request->getUri()->getPath()."\n\n";
echo "\n".$request->getMethod();
if ($request->getMethod() === 'OPTIONS')
return \response()->withStatus(202);

Expand Down
82 changes: 41 additions & 41 deletions gateway-api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,67 +9,67 @@
"description": "Modern High performance AOP and Coroutine PHP Framework, base on Swoole",
"license": "Apache-2.0",
"require": {
"php": ">=7.0",
"ext-swoole": ">=2.1",
"swoft/framework": "^1.0",
"swoft/rpc": "^1.0",
"swoft/rpc-server": "^1.0",
"swoft/rpc-client": "^1.0",
"swoft/http-server": "^1.0",
"swoft/http-client": "^1.0",
"swoft/websocket-server": "^1.0",
"swoft/task": "^1.0",
"swoft/http-message": "^1.0",
"swoft/view": "^1.0",
"swoft/db": "^1.1",
"swoft/cache": "^1.0",
"swoft/redis": "^1.0",
"swoft/console": "^1.0",
"swoft/devtool": "^1.0",
"swoft/session": "^1.0",
"swoft/i18n": "^1.0",
"swoft/process": "^1.0",
"swoft/memory": "^1.0",
"swoft/service-governance": "^1.0",
"swoft/auth": "^1.0",
"wp-breeder/swoft-socket": "^1.0",
"php": ">=7.1",
"ext-pdo": "*",
"ext-json": "*",
"swoft/annotation": "^2.0",
"swoft/bean": "^2.0",
"swoft/event": "^2.0",
"swoft/aop": "^2.0",
"swoft/config": "^2.0",
"swoft/stdlib": "^2.0",
"swoft/framework": "^2.0",
"swoft/http-message": "^2.0",
"swoft/server": "^2.0",
"swoft/tcp-server": "^2.0",
"swoft/http-server": "^2.0",
"swoft/websocket-server": "^2.0",
"swoft/log": "^2.0",
"swoft/db": "^2.0",
"swoft/connection-pool": "^2.0",
"swoft/test": "^2.0",
"swoft/console": "^2.0",
"swoft/rpc": "^2.0",
"swoft/rpc-server": "^2.0",
"swoft/rpc-client": "^2.0",
"swoft/task": "^2.0",
"swoft/redis": "^2.0",
"swoft/proxy": "^2.0",
"swoft/error": "^2.0",
"swoft/component": "dev-master as 2.0",
"lxido/components":"@dev"
},
"require-dev": {
"swoft/swoole-ide-helper": "dev-master",
"phpunit/phpunit": "^5.7",
"friendsofphp/php-cs-fixer": "^2.10",
"psy/psysh": "@stable"
"phpunit/phpunit": "^7.5",
"friendsofphp/php-cs-fixer": "^2.10"
},
"autoload": {
"psr-4":{
"App\\":"app/"
"psr-4": {
"App\\": "app/"
},
"files": [
"app/Swoft.php",
"app/Helper/Functions.php"
]
},
"autoload-dev": {
"psr-4": {
"Swoft\\Test\\": "test/"
}
},
"scripts": {
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"test": "./vendor/bin/phpunit -c phpunit.xml",
"cs-fix": "./vendor/bin/php-cs-fixer fix $1"
},
"repositories": {
"0":{
"repositories": [
{
"type":"vcs",
"url":"http://www.github.com/Lxido/service-components"
"url":"http://www.github.com/brewlin/service-components"
},
{
"type": "git",
"url": "[email protected]:swoft-cloud/swoft-component.git"
},
"packagist": {
{
"type": "composer",
"url": "https://packagist.laravel-china.org"
}
}
]
}
2 changes: 1 addition & 1 deletion gateway-api/config/beans/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
return [
'serverDispatcher' => [
'middlewares' => [
\App\Middlewares\ControllerMiddleware::class
\App\Middlewares\ControllerMiddleware::class,
// \Swoft\View\Middleware\ViewMiddleware::class,
// // \Swoft\Session\Middleware\SessionMiddleware::class,
//\Swoft\Devtool\Middleware\DevToolMiddleware::class,
Expand Down
3 changes: 2 additions & 1 deletion gateway-api/config/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
'daemonize' => env('DAEMONIZE', 0),
'dispatch_mode' => env('DISPATCH_MODE', 2),
'log_file' => env('LOG_FILE', '@runtime/logs/swoole.log'),
'package_max_length' => env('PACKAGE_MAX_LENGTH', 2048),
//包长度限制 在上传图片的时候需要配置
'package_max_length' => env('PACKAGE_MAX_LENGTH', 204800),
'upload_tmp_dir' => env('UPLOAD_TMP_DIR', '@runtime/uploadfiles'),
'document_root' => env('DOCUMENT_ROOT', BASE_PATH . '/public'),
'enable_static_handler' => env('ENABLE_STATIC_HANDLER', true),
Expand Down
2 changes: 1 addition & 1 deletion group-service/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"repositories": {
"0":{
"type":"vcs",
"url":"http://www.github.com/Lxido/service-components"
"url":"http://www.github.com/brewlin/service-components"
},
"packagist": {
"type": "composer",
Expand Down
2 changes: 1 addition & 1 deletion msg-service/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"repositories": {
"0":{
"type":"vcs",
"url":"http://www.github.com/Lxido/service-components"
"url":"http://www.github.com/brewlin/service-components"
},
"packagist": {
"type": "composer",
Expand Down
2 changes: 1 addition & 1 deletion redis-service/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"repositories": {
"0":{
"type":"vcs",
"url":"http://www.github.com/Lxido/service-components"
"url":"http://www.github.com/brewlin/service-components"
},
"packagist": {
"type": "composer",
Expand Down
2 changes: 1 addition & 1 deletion user-service/app/Models/Dao/UserRecordModelDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function touser(){
}
public function updateByWhere($where ,$data)
{
return UserRecord::updateAll($data,$where);
return UserRecord::updateAll($data,$where)->getResult();
}

public function newRecord($data)
Expand Down
2 changes: 1 addition & 1 deletion user-service/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"repositories": {
"0":{
"type":"vcs",
"url":"http://www.github.com/Lxido/service-components"
"url":"http://www.github.com/brewlin/service-components"
},
"packagist": {
"type": "composer",
Expand Down

0 comments on commit 220cb23

Please sign in to comment.