156 lines
3.9 KiB
PHP
156 lines
3.9 KiB
PHP
<?php
|
|
namespace EEPROM\Uploads;
|
|
|
|
use Index\DateTime;
|
|
use Index\MediaType;
|
|
use Index\Data\IDbResult;
|
|
use Index\Net\IPAddress;
|
|
|
|
class UploadInfo {
|
|
private string $id;
|
|
private string $userId;
|
|
private string $appId;
|
|
private string $hash;
|
|
private string $remoteAddr;
|
|
private int $created;
|
|
private ?int $accessed;
|
|
private ?int $expires;
|
|
private ?int $deleted;
|
|
private int $bump;
|
|
private string $name;
|
|
private string $type;
|
|
private int $size;
|
|
|
|
public function __construct(IDbResult $result) {
|
|
$this->id = $result->getString(0);
|
|
$this->userId = $result->getStringOrNull(1);
|
|
$this->appId = $result->getStringOrNull(2);
|
|
$this->hash = $result->getString(3);
|
|
$this->remoteAddr = $result->getString(4);
|
|
$this->created = $result->getInteger(5);
|
|
$this->accessed = $result->getIntegerOrNull(6);
|
|
$this->expires = $result->getIntegerOrNull(7);
|
|
$this->deleted = $result->getIntegerOrNull(8);
|
|
$this->bump = $result->getInteger(9);
|
|
$this->name = $result->getString(10);
|
|
$this->type = $result->getString(11);
|
|
$this->size = $result->getInteger(12);
|
|
}
|
|
|
|
public function getId(): string {
|
|
return $this->id;
|
|
}
|
|
|
|
public function hasUserId(): bool {
|
|
return $this->userId !== null;
|
|
}
|
|
|
|
public function getUserId(): ?string {
|
|
return $this->userId;
|
|
}
|
|
|
|
public function hasAppId(): bool {
|
|
return $this->appId !== null;
|
|
}
|
|
|
|
public function getAppId(): ?string {
|
|
return $this->appId;
|
|
}
|
|
|
|
public function getHashString(): string {
|
|
return $this->hash;
|
|
}
|
|
|
|
public function getRemoteAddressRaw(): string {
|
|
return $this->remoteAddr;
|
|
}
|
|
|
|
public function getRemoteAddress(): IPAddress {
|
|
return IPAddress::parse($this->remoteAddr);
|
|
}
|
|
|
|
public function getCreatedTime(): int {
|
|
return $this->created;
|
|
}
|
|
|
|
public function getCreatedAt(): DateTime {
|
|
return DateTime::fromUnixTimeSeconds($this->created);
|
|
}
|
|
|
|
public function hasBeenAccessed(): bool {
|
|
return $this->accessed !== null;
|
|
}
|
|
|
|
public function getAccessedTime(): ?int {
|
|
return $this->accessed;
|
|
}
|
|
|
|
public function getAccessedAt(): ?DateTime {
|
|
return $this->accessed === null ? null : DateTime::fromUnixTimeSeconds($this->accessed);
|
|
}
|
|
|
|
public function hasExpiryTime(): bool {
|
|
return $this->expires !== null;
|
|
}
|
|
|
|
public function hasExpired(): bool {
|
|
return $this->expires !== null && $this->expires <= time();
|
|
}
|
|
|
|
public function getExpiredTime(): ?int {
|
|
return $this->expires;
|
|
}
|
|
|
|
public function getExpiredAt(): ?DateTime {
|
|
return $this->expires === null ? null : DateTime::fromUnixTimeSeconds($this->expires);
|
|
}
|
|
|
|
public function isDeleted(): bool {
|
|
return $this->deleted !== null;
|
|
}
|
|
|
|
public function getDeletedTime(): ?int {
|
|
return $this->deleted;
|
|
}
|
|
|
|
public function getDeletedAt(): ?DateTime {
|
|
return $this->deleted === null ? null : DateTime::fromUnixTimeSeconds($this->deleted);
|
|
}
|
|
|
|
public function getBumpAmount(): int {
|
|
return $this->bump;
|
|
}
|
|
|
|
public function getBumpAmountForUpdate(): ?int {
|
|
return $this->expires !== null && $this->bump > 0 ? $this->bump : null;
|
|
}
|
|
|
|
public function getName(): string {
|
|
return $this->name;
|
|
}
|
|
|
|
public function getMediaTypeString(): string {
|
|
return $this->type;
|
|
}
|
|
|
|
public function getMediaType(): MediaType {
|
|
return MediaType::parse($this->type);
|
|
}
|
|
|
|
public function isImage(): bool {
|
|
return str_starts_with($this->type, 'image/');
|
|
}
|
|
|
|
public function isVideo(): bool {
|
|
return str_starts_with($this->type, 'video/');
|
|
}
|
|
|
|
public function isAudio(): bool {
|
|
return str_starts_with($this->type, 'audio/');
|
|
}
|
|
|
|
public function getDataSize(): int {
|
|
return $this->size;
|
|
}
|
|
}
|