mirror of
https://github.com/shlinkio/shlink.git
synced 2024-11-26 23:18:37 +03:00
Exposed domain on short URLs
This commit is contained in:
parent
6858dc4785
commit
1a8e4cdfd7
8 changed files with 36 additions and 11 deletions
|
@ -31,6 +31,10 @@
|
|||
},
|
||||
"meta": {
|
||||
"$ref": "./ShortUrlMeta.json"
|
||||
},
|
||||
"domain": {
|
||||
"type": "string",
|
||||
"description": "The domain in which the short URL was created. Null if it belongs to default domain."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,7 +123,8 @@
|
|||
"validSince": "2017-01-21T00:00:00+02:00",
|
||||
"validUntil": null,
|
||||
"maxVisits": 100
|
||||
}
|
||||
},
|
||||
"domain": null
|
||||
},
|
||||
{
|
||||
"shortCode": "12Kb3",
|
||||
|
@ -138,11 +139,12 @@
|
|||
"validSince": null,
|
||||
"validUntil": null,
|
||||
"maxVisits": null
|
||||
}
|
||||
},
|
||||
"domain": null
|
||||
},
|
||||
{
|
||||
"shortCode": "123bA",
|
||||
"shortUrl": "https://doma.in/123bA",
|
||||
"shortUrl": "https://example.com/123bA",
|
||||
"longUrl": "https://www.google.com",
|
||||
"dateCreated": "2015-10-01T20:34:16+02:00",
|
||||
"visitsCount": 25,
|
||||
|
@ -151,7 +153,8 @@
|
|||
"validSince": "2017-01-21T00:00:00+02:00",
|
||||
"validUntil": null,
|
||||
"maxVisits": null
|
||||
}
|
||||
},
|
||||
"domain": "example.com"
|
||||
}
|
||||
],
|
||||
"pagination": {
|
||||
|
@ -271,7 +274,8 @@
|
|||
"validSince": "2017-01-21T00:00:00+02:00",
|
||||
"validUntil": null,
|
||||
"maxVisits": 500
|
||||
}
|
||||
},
|
||||
"domain": null
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -72,7 +72,8 @@
|
|||
"validSince": "2017-01-21T00:00:00+02:00",
|
||||
"validUntil": null,
|
||||
"maxVisits": 100
|
||||
}
|
||||
},
|
||||
"domain": null
|
||||
},
|
||||
"text/plain": "https://doma.in/abc123"
|
||||
}
|
||||
|
|
|
@ -58,7 +58,8 @@
|
|||
"validSince": "2017-01-21T00:00:00+02:00",
|
||||
"validUntil": null,
|
||||
"maxVisits": 100
|
||||
}
|
||||
},
|
||||
"domain": null
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -4,9 +4,10 @@ declare(strict_types=1);
|
|||
|
||||
namespace Shlinkio\Shlink\Core\Entity;
|
||||
|
||||
use JsonSerializable;
|
||||
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
||||
|
||||
class Domain extends AbstractEntity
|
||||
class Domain extends AbstractEntity implements JsonSerializable
|
||||
{
|
||||
private string $authority;
|
||||
|
||||
|
@ -19,4 +20,9 @@ class Domain extends AbstractEntity
|
|||
{
|
||||
return $this->authority;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): string
|
||||
{
|
||||
return $this->getAuthority();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,6 +69,11 @@ class ShortUrl extends AbstractEntity
|
|||
return $this->dateCreated;
|
||||
}
|
||||
|
||||
public function getDomain(): ?Domain
|
||||
{
|
||||
return $this->domain;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection|Tag[]
|
||||
*/
|
||||
|
|
|
@ -24,16 +24,15 @@ class ShortUrlDataTransformer implements DataTransformerInterface
|
|||
*/
|
||||
public function transform($shortUrl): array // phpcs:ignore
|
||||
{
|
||||
$longUrl = $shortUrl->getLongUrl();
|
||||
|
||||
return [
|
||||
'shortCode' => $shortUrl->getShortCode(),
|
||||
'shortUrl' => $shortUrl->toString($this->domainConfig),
|
||||
'longUrl' => $longUrl,
|
||||
'longUrl' => $shortUrl->getLongUrl(),
|
||||
'dateCreated' => $shortUrl->getDateCreated()->toAtomString(),
|
||||
'visitsCount' => $shortUrl->getVisitsCount(),
|
||||
'tags' => invoke($shortUrl->getTags(), '__toString'),
|
||||
'meta' => $this->buildMeta($shortUrl),
|
||||
'domain' => $shortUrl->getDomain(),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ class ListShortUrlsTest extends ApiTestCase
|
|||
'validUntil' => null,
|
||||
'maxVisits' => null,
|
||||
],
|
||||
'domain' => null,
|
||||
];
|
||||
private const SHORT_URL_CUSTOM_SLUG_AND_DOMAIN = [
|
||||
'shortCode' => 'custom-with-domain',
|
||||
|
@ -37,6 +38,7 @@ class ListShortUrlsTest extends ApiTestCase
|
|||
'validUntil' => null,
|
||||
'maxVisits' => null,
|
||||
],
|
||||
'domain' => 'some-domain.com',
|
||||
];
|
||||
private const SHORT_URL_META = [
|
||||
'shortCode' => 'def456',
|
||||
|
@ -52,6 +54,7 @@ class ListShortUrlsTest extends ApiTestCase
|
|||
'validUntil' => null,
|
||||
'maxVisits' => null,
|
||||
],
|
||||
'domain' => null,
|
||||
];
|
||||
private const SHORT_URL_CUSTOM_SLUG = [
|
||||
'shortCode' => 'custom',
|
||||
|
@ -65,6 +68,7 @@ class ListShortUrlsTest extends ApiTestCase
|
|||
'validUntil' => null,
|
||||
'maxVisits' => 2,
|
||||
],
|
||||
'domain' => null,
|
||||
];
|
||||
private const SHORT_URL_CUSTOM_DOMAIN = [
|
||||
'shortCode' => 'ghi789',
|
||||
|
@ -80,6 +84,7 @@ class ListShortUrlsTest extends ApiTestCase
|
|||
'validUntil' => null,
|
||||
'maxVisits' => null,
|
||||
],
|
||||
'domain' => 'example.com',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue