kopia lustrzana https://github.com/nextcloud/social
add meta to attachments
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/1632/head
rodzic
0a6aea1fe4
commit
a8e7de151f
|
@ -57,6 +57,12 @@ class CacheDocumentsRequest extends CacheDocumentsRequestBuilder {
|
|||
->setValue('parent_id_prim', $qb->createNamedParameter($qb->prim($document->getParentId())))
|
||||
->setValue('public', $qb->createNamedParameter(($document->isPublic()) ? '1' : '0'));
|
||||
|
||||
// generate Meta
|
||||
$document->convertToMediaAttachment();
|
||||
if ($document->getMeta() !== null) {
|
||||
$qb->setValue('meta', $qb->createNamedParameter(json_encode($document->getMeta())));
|
||||
}
|
||||
|
||||
try {
|
||||
$qb->setValue(
|
||||
'creation',
|
||||
|
|
|
@ -62,8 +62,8 @@ class CacheDocumentsRequestBuilder extends CoreRequestBuilder {
|
|||
$qb->select(
|
||||
'cd.nid', 'cd.id', 'cd.type', 'cd.parent_id', 'cd.account',
|
||||
'cd.media_type', 'cd.mime_type', 'cd.url', 'cd.local_copy', 'cd.public',
|
||||
'cd.error', 'cd.creation', 'cd.caching', 'cd.resized_copy', 'cd.blurhash',
|
||||
'cd.description'
|
||||
'cd.error', 'cd.creation', 'cd.caching', 'cd.resized_copy', 'cd.meta',
|
||||
'cd.blurhash', 'cd.description'
|
||||
)
|
||||
->from(self::TABLE_CACHE_DOCUMENTS, 'cd');
|
||||
|
||||
|
|
|
@ -130,6 +130,7 @@ class CoreRequestBuilder {
|
|||
'url',
|
||||
'local_copy',
|
||||
'resized_copy',
|
||||
'meta',
|
||||
'blurhash',
|
||||
'description',
|
||||
'public',
|
||||
|
|
|
@ -986,6 +986,13 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
|
|||
'default' => ''
|
||||
]
|
||||
);
|
||||
$table->addColumn(
|
||||
'meta', Types::TEXT,
|
||||
[
|
||||
'notnull' => true,
|
||||
'default' => '[]'
|
||||
]
|
||||
);
|
||||
$table->addColumn(
|
||||
'blurhash', Types::STRING,
|
||||
[
|
||||
|
|
|
@ -81,6 +81,16 @@ class Version1000Date20230217000002 extends SimpleMigrationStep {
|
|||
);
|
||||
}
|
||||
|
||||
if (!$table->hasColumn('meta')) {
|
||||
$table->addColumn(
|
||||
'meta', Types::TEXT,
|
||||
[
|
||||
'notnull' => true,
|
||||
'default' => '[]'
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
if (!$table->hasColumn('blurhash')) {
|
||||
$table->addColumn(
|
||||
'blurhash', Types::STRING,
|
||||
|
|
|
@ -57,6 +57,7 @@ class Document extends ACore implements JsonSerializable {
|
|||
private string $localCopy = '';
|
||||
private string $resizedCopy = '';
|
||||
private string $blurHash = '';
|
||||
private ?AttachmentMeta $meta = null;
|
||||
private string $description = '';
|
||||
private int $caching = 0;
|
||||
private bool $public = false;
|
||||
|
@ -193,6 +194,16 @@ class Document extends ACore implements JsonSerializable {
|
|||
return $this->blurHash;
|
||||
}
|
||||
|
||||
public function setMeta(AttachmentMeta $meta): self {
|
||||
$this->meta = $meta;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMeta(): ?AttachmentMeta {
|
||||
return $this->meta;
|
||||
}
|
||||
|
||||
public function setDescription(string $description): self {
|
||||
$this->description = $description;
|
||||
|
||||
|
@ -326,6 +337,12 @@ class Document extends ACore implements JsonSerializable {
|
|||
} catch (Exception $e) {
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->get('meta', $data) !== '') {
|
||||
$meta = new AttachmentMeta();
|
||||
$meta->import($this->getArray('meta', $data));
|
||||
$this->setMeta($meta);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -375,12 +392,16 @@ class Document extends ACore implements JsonSerializable {
|
|||
$media->setRemoteUrl($this->getUrl());
|
||||
}
|
||||
|
||||
$meta = new AttachmentMeta();
|
||||
$meta->setOriginal(new AttachmentMetaDim($this->getLocalCopySize()))
|
||||
->setSmall(new AttachmentMetaDim($this->getResizedCopySize()))
|
||||
->setFocus(new AttachmentMetaFocus(0, 0));
|
||||
if ($this->getMeta() === null) {
|
||||
$meta = new AttachmentMeta();
|
||||
$meta->setOriginal(new AttachmentMetaDim($this->getLocalCopySize()))
|
||||
->setSmall(new AttachmentMetaDim($this->getResizedCopySize()))
|
||||
->setFocus(new AttachmentMetaFocus(0, 0));
|
||||
|
||||
$media->setMeta($meta)
|
||||
$this->setMeta($meta);
|
||||
}
|
||||
|
||||
$media->setMeta($this->getMeta())
|
||||
->setDescription($this->getDescription())
|
||||
->setBlurHash($this->getBlurHash());
|
||||
|
||||
|
|
|
@ -204,6 +204,23 @@ class AttachmentMeta implements JsonSerializable {
|
|||
return $this->blurHash;
|
||||
}
|
||||
|
||||
|
||||
public function import(array $data): self {
|
||||
$original = new AttachmentMetaDim();
|
||||
$original->import($this->getArray('original', $data));
|
||||
$this->setOriginal($original);
|
||||
|
||||
$small = new AttachmentMetaDim();
|
||||
$small->import($this->getArray('small', $data));
|
||||
$this->setSmall($small);
|
||||
|
||||
$focus = new AttachmentMetaFocus($this->getInt('focus.x', $data), $this->getInt('focus.y', $data));
|
||||
$this->setFocus($focus);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function jsonSerialize(): array {
|
||||
return array_filter(
|
||||
[
|
||||
|
|
|
@ -30,8 +30,11 @@ declare(strict_types=1);
|
|||
namespace OCA\Social\Model\Client;
|
||||
|
||||
use JsonSerializable;
|
||||
use OCA\Social\Tools\Traits\TArrayTools;
|
||||
|
||||
class AttachmentMetaDim implements JsonSerializable {
|
||||
use TArrayTools;
|
||||
|
||||
private ?int $width = null;
|
||||
private ?int $height = null;
|
||||
private string $size = '';
|
||||
|
@ -40,7 +43,11 @@ class AttachmentMetaDim implements JsonSerializable {
|
|||
private ?float $bitrate = null;
|
||||
private ?float $frameRate = null;
|
||||
|
||||
public function __construct(array $dim) {
|
||||
public function __construct(array $dim = []) {
|
||||
if (sizeof($dim) !== 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
$width = (int)$dim[0];
|
||||
$height = (int)$dim[1];
|
||||
|
||||
|
@ -122,6 +129,18 @@ class AttachmentMetaDim implements JsonSerializable {
|
|||
return $this->frameRate;
|
||||
}
|
||||
|
||||
public function import(array $data): self {
|
||||
$this->setWidth($this->getInt('width', $data))
|
||||
->setHeight($this->getInt('height', $data))
|
||||
->setSize($this->get('size', $data))
|
||||
->setAspect($this->getFloat('aspect', $data))
|
||||
->setDuration($this->getInt('duration', $data))
|
||||
->setBitrate($this->getInt('bitrate', $data))
|
||||
->setFrameRate($this->getFloat('frame_rate', $data));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array {
|
||||
return array_filter(
|
||||
[
|
||||
|
|
|
@ -32,10 +32,10 @@ namespace OCA\Social\Model\Client;
|
|||
use JsonSerializable;
|
||||
|
||||
class AttachmentMetaFocus implements JsonSerializable {
|
||||
private ?float $x;
|
||||
private ?float $y;
|
||||
private float $x;
|
||||
private float $y;
|
||||
|
||||
public function __construct(?float $x = null, ?float $y = null) {
|
||||
public function __construct(float $x = 0, float $y = 0) {
|
||||
$this->x = $x;
|
||||
$this->y = $y;
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ class AttachmentMetaFocus implements JsonSerializable {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getX(): ?float {
|
||||
public function getX(): float {
|
||||
return $this->x;
|
||||
}
|
||||
|
||||
|
@ -56,16 +56,14 @@ class AttachmentMetaFocus implements JsonSerializable {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function getY(): ?float {
|
||||
public function getY(): float {
|
||||
return $this->y;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array {
|
||||
return array_filter(
|
||||
[
|
||||
'x' => $this->getX(),
|
||||
'y' => $this->getY()
|
||||
]
|
||||
);
|
||||
return [
|
||||
'x' => $this->getX(),
|
||||
'y' => $this->getY()
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ class PostService {
|
|||
$token = $this->activityService->createActivity($actor, $note, $activity);
|
||||
$this->accountService->cacheLocalActorDetailCount($actor);
|
||||
|
||||
$this->miscService->log('Activity: ' . json_encode($activity));
|
||||
$this->logger->debug('Activity: ' . json_encode($activity));
|
||||
|
||||
return $activity;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue