diff --git a/app/Content/Assets.php b/app/Content/Assets.php
index 73bfc7c..e5ee0a9 100644
--- a/app/Content/Assets.php
+++ b/app/Content/Assets.php
@@ -9,6 +9,8 @@ use RuntimeException;
final class Assets
{
public const DEFAULT_ICON = '/assets/system/laysite-mark.webp';
+ public const JQUERY = '/assets/jquery-4.0.0.min.js';
+ public const TOAST_UI_EDITOR = '/assets/vendor/toastui/toastui-editor.min.js';
public static function cdn(string $value): string
{
diff --git a/app/Content/Licenses.php b/app/Content/Licenses.php
index d77b49f..ecefc46 100644
--- a/app/Content/Licenses.php
+++ b/app/Content/Licenses.php
@@ -24,18 +24,21 @@ final class Licenses
public static function dependencies(): array
{
$root = dirname(__DIR__, 2);
+ $jquery = @file_get_contents($root . '/public' . Assets::JQUERY, length: 256);
+ $editor = @file_get_contents($root . '/public' . Assets::TOAST_UI_EDITOR);
+ $version = '([0-9][0-9A-Za-z.+-]*)';
$entries = [
- 'jquery' => ['name' => 'jQuery', 'version' => '4.0.0', 'license' => 'MIT',
+ 'jquery' => ['name' => 'jQuery', 'version' => self::declaredVersion($jquery, '~jQuery v' . $version . '~'), 'license' => 'MIT',
'url' => 'https://jquery.com/', 'file' => $root . '/public/assets/jquery-LICENSE.txt'],
- 'toast-ui-editor' => ['name' => 'TOAST UI Editor', 'version' => '3.2.2', 'license' => 'MIT',
+ 'toast-ui-editor' => ['name' => 'TOAST UI Editor', 'version' => self::declaredVersion($editor, '~@version\h+' . $version . '~'), 'license' => 'MIT',
'url' => 'https://github.com/nhn/tui.editor', 'file' => $root . '/public/assets/vendor/toastui/LICENSE'],
- 'geist' => ['name' => 'Geist', 'version' => '', 'license' => 'OFL-1.1',
+ 'geist' => ['name' => 'Geist', 'license' => 'OFL-1.1',
'url' => 'https://github.com/vercel/geist-font', 'file' => $root . '/public/assets/geist-OFL.txt'],
- 'dompurify' => ['name' => 'DOMPurify', 'version' => '2.3.3', 'license' => 'Apache-2.0 / MPL-2.0',
- 'url' => 'https://github.com/cure53/DOMPurify/tree/2.3.3', 'file' => null],
- 'prosemirror' => ['name' => 'ProseMirror', 'version' => '', 'license' => 'MIT',
+ 'dompurify' => ['name' => 'DOMPurify', 'version' => self::declaredVersion($editor, '~@license DOMPurify\h+' . $version . '~'), 'license' => 'Apache-2.0 / MPL-2.0',
+ 'url' => 'https://github.com/cure53/DOMPurify', 'file' => null],
+ 'prosemirror' => ['name' => 'ProseMirror', 'license' => 'MIT',
'url' => 'https://prosemirror.net/', 'file' => null],
- 'tslib' => ['name' => 'tslib', 'version' => '', 'license' => '0BSD',
+ 'tslib' => ['name' => 'tslib', 'license' => '0BSD',
'url' => 'https://github.com/microsoft/tslib', 'file' => null],
];
$lock = @file_get_contents($root . '/composer.lock');
@@ -57,6 +60,11 @@ final class Licenses
return $entries;
}
+ private static function declaredVersion(string|false $source, string $pattern): string
+ {
+ return $source !== false && preg_match($pattern, $source, $match) ? $match[1] : '';
+ }
+
public static function text(string $key): ?string
{
$path = self::dependencies()[$key]['file'] ?? null;
diff --git a/app/Content/Media.php b/app/Content/Media.php
index 8a7b1e1..d6f61cc 100644
--- a/app/Content/Media.php
+++ b/app/Content/Media.php
@@ -92,7 +92,10 @@ final class Media
{
$bytes = Database::connect()->query('SELECT COALESCE(SUM(size), 0) FROM media')->fetchColumn();
$directory = self::directory();
- $free = is_dir($directory) ? @disk_free_space($directory) : false;
+ while ($directory !== '' && $directory !== dirname($directory) && !@is_dir($directory)) {
+ $directory = dirname($directory);
+ }
+ $free = @is_dir($directory) ? @disk_free_space($directory) : false;
return [
'size' => SystemInfo::bytes((int) $bytes),
diff --git a/app/Content/SystemInfo.php b/app/Content/SystemInfo.php
index ef70646..342b50e 100644
--- a/app/Content/SystemInfo.php
+++ b/app/Content/SystemInfo.php
@@ -38,7 +38,7 @@ final class SystemInfo
{
return [
'cpu' => PHP_OS_FAMILY === 'Linux' ? self::cpu() : null,
- 'memory' => PHP_OS_FAMILY === 'Linux' ? self::memory() : null,
+ 'memory' => self::memory(),
];
}
@@ -58,8 +58,11 @@ final class SystemInfo
return ['total' => array_sum(array_slice($fields, 1, 8)), 'idle' => $fields[4] + $fields[5]];
}
- private static function memory(): ?string
+ public static function memory(): ?string
{
+ if (PHP_OS_FAMILY !== 'Linux') {
+ return null;
+ }
$info = @file_get_contents('/proc/meminfo');
if ($info === false || !preg_match('/^MemTotal:\s+(\d+) kB$/m', $info, $total)
|| !preg_match('/^MemAvailable:\s+(\d+) kB$/m', $info, $available) || (int) $total[1] === 0) {
diff --git a/app/Controller/AdminController.php b/app/Controller/AdminController.php
index 1e645c9..887a60f 100644
--- a/app/Controller/AdminController.php
+++ b/app/Controller/AdminController.php
@@ -145,7 +145,7 @@ class AdminController
'运行平台' => SystemInfo::platform(),
PHP_OS_FAMILY === 'Linux' ? 'Linux 内核' : '系统版本' => php_uname('r'),
],
- 'metrics' => SystemInfo::sample(),
+ 'memory' => SystemInfo::memory(),
'mediaUsage' => Media::usage(),
'thirdPartyLicenses' => Licenses::dependencies(),
]);
diff --git a/app/Middleware/PublicAssets.php b/app/Middleware/PublicAssets.php
index 5ea2d2d..3ca44a7 100644
--- a/app/Middleware/PublicAssets.php
+++ b/app/Middleware/PublicAssets.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Middleware;
+use App\Content\Assets;
use Webman\Http\Request;
use Webman\Http\Response;
use Webman\MiddlewareInterface;
@@ -16,7 +17,7 @@ final class PublicAssets implements MiddlewareInterface
$path = $request->path();
if (str_starts_with($path, '/assets/')) {
$response->withHeader('Access-Control-Allow-Origin', '*');
- if ($path === '/assets/jquery-4.0.0.min.js') {
+ if ($path === Assets::JQUERY) {
$response->withHeader('Cache-Control', 'public, max-age=31536000, immutable');
}
}
diff --git a/app/view/admin-about.php b/app/view/admin-about.php
index 6a2fa5e..3c8e81b 100644
--- a/app/view/admin-about.php
+++ b/app/view/admin-about.php
@@ -6,26 +6,23 @@ $e = View::escape(...);
?>
= $e($title) ?>
CPU 和内存显示当前 Linux 系统可见的用量,页面可见时自动更新。
-