Skip to content

Commit

Permalink
更新:优化后台页面,新增SForum通知
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuchunshu committed Aug 20, 2023
1 parent 6f3caf3 commit 1dadecf
Show file tree
Hide file tree
Showing 5 changed files with 245 additions and 128 deletions.
1 change: 1 addition & 0 deletions app/CodeFec/Itf/Setting/default.php
Expand Up @@ -9,4 +9,5 @@
* @license https://github.com/zhuchunshu/SForum/blob/master/LICENSE
*/
Itf_Setting()->add(1, '基本设置', 'default', 'admin.setting.core.1');
Itf_Setting()->add(2, '后台/服务', 'admin', 'admin.setting.core.2');

44 changes: 33 additions & 11 deletions app/Controller/Admin/ApiController.php
@@ -1,6 +1,6 @@
<?php

declare (strict_types=1);
declare(strict_types=1);
/**
* This file is part of zhuchunshu.
* @link https://github.com/zhuchunshu
Expand All @@ -24,17 +24,23 @@
#[Middleware(AdminMiddleware::class)]
class ApiController
{

#[Inject]
protected Upgrading $service;


// sforum github api接口
private string $api_releases = 'https://api.github.com/repos/zhuchunshu/SForum/releases';


// sforum 通知接口
private string $api_notice = 'https://www.runpod.cn/api/v1/SFService/sforum/admin/notice';

// sforum 通知获取数量
private int $api_notice_limit = 100;

#[PostMapping('getVersion')]
public function getVersion()
{
// 获取最新版
if (!cache()->has('admin.git.getVersion')) {
if (! cache()->has('admin.git.getVersion')) {
$data = http()->get($this->api_releases);
// 当前版本
$current = null;
Expand Down Expand Up @@ -66,11 +72,11 @@ public function getVersion()
}
return cache()->get('admin.git.getVersion');
}

#[PostMapping('getRelease/{id}')]
public function getRelease($id)
{
if (!cache()->has('admin.git.getRelease.' . $id)) {
if (! cache()->has('admin.git.getRelease.' . $id)) {
$data = http()->get($this->api_releases . '/' . $id);
$r = http('raw')->get($data['html_url']);
$body = $r->getBody();
Expand All @@ -81,20 +87,20 @@ public function getRelease($id)
}
return cache()->get('admin.git.getRelease.' . $id);
}

#[PostMapping('getUpdateLog')]
public function getCommit()
{
return (new ContentParse())->parse('此功能已关闭');
}

#[PostMapping('clearCache')]
public function clearCache()
{
cache()->delete('admin.git.getVersion');
return Json_Api(200, true, ['msg' => '缓存清理成功']);
}

#[PostMapping('update')]
public function update()
{
Expand All @@ -121,12 +127,28 @@ public function update()
$this->service->handle($url, $file_path);
return Json_Api(200, true, ['msg' => '升级任务已创建']);
}

// 同意免责声明
// 同意免责声明

#[GetMapping('agree.disclaimer')]
public function agree_disclaimer()
{
cache()->set('admin.core.disclaimer', time());
return Json_Api(200, true, ['msg' => 'success']);
}
}

// 获取sforum通知
#[PostMapping('sforum.notice')]
public function sforum_notice(): array
{
try {
$data = http()->post($this->api_notice, [
'limit' => $this->api_notice_limit,
]);
} catch (\Throwable) {
return Json_Api(500, false, ['msg' => '获取失败']);
}
return Json_Api(200, true, ['msg' => 'success', 'data' => $data]);
}
}

0 comments on commit 1dadecf

Please sign in to comment.