mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 11:27:24 +08:00
[api] handle no latest
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Models\News;
|
||||
use App\Repositories\NewsRepository;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Nexus\Database\NexusDB;
|
||||
@@ -104,10 +105,15 @@ class NewsController extends Controller
|
||||
{
|
||||
$user = Auth::user();
|
||||
$result = News::query()->orderBy('id', 'desc')->first();
|
||||
$resource = new NewsResource($result);
|
||||
if ($result) {
|
||||
$resource = new NewsResource($result);
|
||||
} else {
|
||||
$resource = new JsonResource(null);
|
||||
}
|
||||
$resource->additional([
|
||||
'site_info' => site_info(),
|
||||
]);
|
||||
|
||||
/**
|
||||
* Visiting the home page is the same as viewing the latest news
|
||||
* @see functions.php line 2590
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Http\Resources\PollResource;
|
||||
use App\Models\Poll;
|
||||
use App\Repositories\PollRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
@@ -96,7 +97,6 @@ class PollController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo 弃权选项
|
||||
* @return array
|
||||
*/
|
||||
public function latest()
|
||||
@@ -130,9 +130,11 @@ class PollController extends Controller
|
||||
foreach ($answerStats as $index => &$value) {
|
||||
$value = number_format(($value / $poll->answers_count) * 100, 2) . '%';
|
||||
}
|
||||
$resource = new PollResource($poll);
|
||||
} else {
|
||||
$resource = new JsonResource(null);
|
||||
}
|
||||
|
||||
$resource = new PollResource($poll);
|
||||
$resource->additional([
|
||||
'selection' => $selection,
|
||||
'answer_stats' => $answerStats,
|
||||
|
||||
@@ -25,17 +25,16 @@ if ($currentStep == 1) {
|
||||
if ($currentStep == 2) {
|
||||
$tableRows = [];
|
||||
$versionTable = $versions = [];
|
||||
$cacheKkey = '__versions_' . date('Ymd_H');
|
||||
$tableRows[] = [
|
||||
'checkbox' => sprintf('<input type="radio" name="version_url" value="manual"/>'),
|
||||
'tag_name' => 'Manual',
|
||||
'name' => 'If there are changes that are not suitable for full coverage, please check this box and make sure you have updated the code manually',
|
||||
'published_at' => '---',
|
||||
];
|
||||
try {
|
||||
$versions = $update->listVersions();
|
||||
// if (!empty($_SESSION[$cacheKkey])) {
|
||||
// $update->doLog("get versions from session.");
|
||||
// $versions = $_SESSION[$cacheKkey];
|
||||
// } else {
|
||||
// $_SESSION[$cacheKkey] = $versions;
|
||||
// }
|
||||
} catch (\Exception $exception) {
|
||||
$error = $exception->getMessage();
|
||||
$update->doLog("can not fetch versions from github: " . $exception->getMessage());
|
||||
}
|
||||
if (!$isPost) {
|
||||
$versionHeader = [
|
||||
@@ -51,23 +50,22 @@ if ($currentStep == 2) {
|
||||
$update->doLog("no .env file, release time is github original");
|
||||
$timezone = null;
|
||||
}
|
||||
$tableRows[] = [
|
||||
'checkbox' => sprintf('<input type="radio" name="version_url" value="manual"/>'),
|
||||
'tag_name' => 'Manual',
|
||||
'name' => 'If there are changes that are not suitable for full coverage, please check this box and make sure you have updated the code manually',
|
||||
'published_at' => '---',
|
||||
];
|
||||
$latestCommit = $update->getLatestCommit();
|
||||
$time = \Carbon\Carbon::parse($latestCommit['commit']['committer']['date']);
|
||||
if ($timezone) {
|
||||
$time->tz = $timezone;
|
||||
|
||||
try {
|
||||
$latestCommit = $update->getLatestCommit();
|
||||
$time = \Carbon\Carbon::parse($latestCommit['commit']['committer']['date']);
|
||||
if ($timezone) {
|
||||
$time->tz = $timezone;
|
||||
}
|
||||
$tableRows[] = [
|
||||
'checkbox' => sprintf('<input type="radio" name="version_url" value="development|%s"/>', $latestCommit['sha']),
|
||||
'tag_name' => 'Latest development code',
|
||||
'name' => "Development testing only! Latest commit:" . $latestCommit['commit']['message'],
|
||||
'published_at' => $time->format('Y-m-d H:i:s'),
|
||||
];
|
||||
} catch (\Exception $exception) {
|
||||
$update->doLog("can not fetch latest commit from github: " . $exception->getMessage());
|
||||
}
|
||||
$tableRows[] = [
|
||||
'checkbox' => sprintf('<input type="radio" name="version_url" value="development|%s"/>', $latestCommit['sha']),
|
||||
'tag_name' => 'Latest development code',
|
||||
'name' => "Development testing only! Latest commit:" . $latestCommit['commit']['message'],
|
||||
'published_at' => $time->format('Y-m-d H:i:s'),
|
||||
];
|
||||
foreach ($versions as $version) {
|
||||
if ($version['draft']) {
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user