all
Some checks failed
Publish Docker Image / build-and-push (push) Failing after 2m13s

This commit is contained in:
Sam Kintop
2026-04-30 09:44:02 -05:00
parent 0a30837e3d
commit bf3870ccca
111 changed files with 8383 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
<?php
namespace Aternos\Mclogs\Api\Response;
use Aternos\Mclogs\Log;
use Aternos\Mclogs\Util\URL;
class LogResponse extends ApiResponse
{
public function __construct(
protected Log $log,
protected bool $withToken = false,
protected bool $withInsights = false,
protected bool $withRaw = false,
protected bool $withParsed = false)
{
$this->loadFromGet();
}
public function loadFromGet(): static
{
$url = URL::getCurrent();
$query = $url->getQuery();
if (empty($query)) {
return $this;
}
parse_str($url->getQuery(), $get);
$this->withInsights = isset($get['insights']);
$this->withRaw = isset($get['raw']);
$this->withParsed = isset($get['parsed']);
return $this;
}
public function jsonSerialize(): array
{
$data = parent::jsonSerialize();
$data['id'] = $this->log->getId();
$data['source'] = $this->log->getSource();
$data['created'] = $this->log->getCreated()?->toDateTime()->getTimestamp();
$data['expires'] = $this->log->getExpires()?->toDateTime()->getTimestamp();
$data['size'] = $this->log->getSize();
$data['lines'] = $this->log->getLinesCount();
$data['errors'] = $this->log->getErrorsCount();
$data['url'] = $this->log->getUrl()->toString();
$data['raw'] = $this->log->getRawURL()->toString();
if ($this->withToken) {
$data['token'] = $this->log->getToken();
}
$data['metadata'] = $this->log->getMetadata();
if ($this->withInsights || $this->withRaw || $this->withParsed) {
$data['content'] = [];
}
if ($this->withInsights) {
$data['content']['insights'] = $this->log->getCodexLog()->setIncludeEntries(false);
}
if ($this->withRaw) {
$data['content']['raw'] = $this->log->getContent();
}
if ($this->withParsed) {
$data['content']['parsed'] = $this->log->getCodexLog()->getEntries();
}
return $data;
}
}