add forum announcements
This commit is contained in:
parent
1efe83a61e
commit
652d2060bc
@ -31,3 +31,6 @@ MONGO_DB_AUTHENTICATION_DATABASE=admin
|
|||||||
LARAVELS_LISTEN_IP=127.0.0.0
|
LARAVELS_LISTEN_IP=127.0.0.0
|
||||||
|
|
||||||
ALIPAY_APP_ID=
|
ALIPAY_APP_ID=
|
||||||
|
|
||||||
|
FORUM_BASEURL=https://forum.laecloud.com
|
||||||
|
|
||||||
|
63
app/Http/Controllers/ForumController.php
Normal file
63
app/Http/Controllers/ForumController.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
|
class ForumController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
private $http, $baseUrl;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->baseUrl = config('forum.base_url');
|
||||||
|
|
||||||
|
$this->http = Http::baseUrl($this->baseUrl . '/api')->throw();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get($url)
|
||||||
|
{
|
||||||
|
|
||||||
|
try {
|
||||||
|
$resp = $this->http->get($url)->json()['data'];
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return $this->error($e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->success($resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function announcements()
|
||||||
|
{
|
||||||
|
|
||||||
|
$resp = $this->cache(function () {
|
||||||
|
return $this->get('discussions?filter[tag]=announcements&page[offset]=0&sort=-commentCount');
|
||||||
|
});
|
||||||
|
|
||||||
|
if (isset($resp->original['data'])) {
|
||||||
|
$resp = $resp->original['data'];
|
||||||
|
} else {
|
||||||
|
$resp = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->success($resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function cache(Closure $callback)
|
||||||
|
{
|
||||||
|
// 获取调用方法名
|
||||||
|
$method = debug_backtrace()[1]['function'];
|
||||||
|
|
||||||
|
|
||||||
|
return Cache::remember('forum.func.' . $method . '.user_' . auth()->id(), 60, function () use ($callback) {
|
||||||
|
return $callback();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
@ -75,6 +75,7 @@
|
|||||||
$app->configure('session');
|
$app->configure('session');
|
||||||
$app->configure('alipay');
|
$app->configure('alipay');
|
||||||
$app->configure('drops');
|
$app->configure('drops');
|
||||||
|
$app->configure('forum');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
5
config/forum.php
Normal file
5
config/forum.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'base_url' => env('FORUM_BASEURL')
|
||||||
|
];
|
@ -84,6 +84,13 @@
|
|||||||
// });
|
// });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$router->group(['prefix' => 'forum'], function () use ($router) {
|
||||||
|
$router->get('/announcements', [
|
||||||
|
'uses' => 'ForumController@announcements'
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
$router->group(['prefix' => 'modules/{module}'], function () use ($router) {
|
$router->group(['prefix' => 'modules/{module}'], function () use ($router) {
|
||||||
$controller = 'Remote\ModuleController@call';
|
$controller = 'Remote\ModuleController@call';
|
||||||
$router->get('/{route:.*}/', $controller);
|
$router->get('/{route:.*}/', $controller);
|
||||||
|
Loading…
Reference in New Issue
Block a user