forked from laysense/laysite
Address system information and license review suggestions
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user