mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-27 20:11:34 +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": {
|
"meta": {
|
||||||
"$ref": "./ShortUrlMeta.json"
|
"$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",
|
"validSince": "2017-01-21T00:00:00+02:00",
|
||||||
"validUntil": null,
|
"validUntil": null,
|
||||||
"maxVisits": 100
|
"maxVisits": 100
|
||||||
}
|
},
|
||||||
|
"domain": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"shortCode": "12Kb3",
|
"shortCode": "12Kb3",
|
||||||
|
@ -138,11 +139,12 @@
|
||||||
"validSince": null,
|
"validSince": null,
|
||||||
"validUntil": null,
|
"validUntil": null,
|
||||||
"maxVisits": null
|
"maxVisits": null
|
||||||
}
|
},
|
||||||
|
"domain": null
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"shortCode": "123bA",
|
"shortCode": "123bA",
|
||||||
"shortUrl": "https://doma.in/123bA",
|
"shortUrl": "https://example.com/123bA",
|
||||||
"longUrl": "https://www.google.com",
|
"longUrl": "https://www.google.com",
|
||||||
"dateCreated": "2015-10-01T20:34:16+02:00",
|
"dateCreated": "2015-10-01T20:34:16+02:00",
|
||||||
"visitsCount": 25,
|
"visitsCount": 25,
|
||||||
|
@ -151,7 +153,8 @@
|
||||||
"validSince": "2017-01-21T00:00:00+02:00",
|
"validSince": "2017-01-21T00:00:00+02:00",
|
||||||
"validUntil": null,
|
"validUntil": null,
|
||||||
"maxVisits": null
|
"maxVisits": null
|
||||||
}
|
},
|
||||||
|
"domain": "example.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"pagination": {
|
"pagination": {
|
||||||
|
@ -271,7 +274,8 @@
|
||||||
"validSince": "2017-01-21T00:00:00+02:00",
|
"validSince": "2017-01-21T00:00:00+02:00",
|
||||||
"validUntil": null,
|
"validUntil": null,
|
||||||
"maxVisits": 500
|
"maxVisits": 500
|
||||||
}
|
},
|
||||||
|
"domain": null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -72,7 +72,8 @@
|
||||||
"validSince": "2017-01-21T00:00:00+02:00",
|
"validSince": "2017-01-21T00:00:00+02:00",
|
||||||
"validUntil": null,
|
"validUntil": null,
|
||||||
"maxVisits": 100
|
"maxVisits": 100
|
||||||
}
|
},
|
||||||
|
"domain": null
|
||||||
},
|
},
|
||||||
"text/plain": "https://doma.in/abc123"
|
"text/plain": "https://doma.in/abc123"
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,8 @@
|
||||||
"validSince": "2017-01-21T00:00:00+02:00",
|
"validSince": "2017-01-21T00:00:00+02:00",
|
||||||
"validUntil": null,
|
"validUntil": null,
|
||||||
"maxVisits": 100
|
"maxVisits": 100
|
||||||
}
|
},
|
||||||
|
"domain": null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,9 +4,10 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Shlinkio\Shlink\Core\Entity;
|
namespace Shlinkio\Shlink\Core\Entity;
|
||||||
|
|
||||||
|
use JsonSerializable;
|
||||||
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
use Shlinkio\Shlink\Common\Entity\AbstractEntity;
|
||||||
|
|
||||||
class Domain extends AbstractEntity
|
class Domain extends AbstractEntity implements JsonSerializable
|
||||||
{
|
{
|
||||||
private string $authority;
|
private string $authority;
|
||||||
|
|
||||||
|
@ -19,4 +20,9 @@ class Domain extends AbstractEntity
|
||||||
{
|
{
|
||||||
return $this->authority;
|
return $this->authority;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function jsonSerialize(): string
|
||||||
|
{
|
||||||
|
return $this->getAuthority();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,11 @@ class ShortUrl extends AbstractEntity
|
||||||
return $this->dateCreated;
|
return $this->dateCreated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDomain(): ?Domain
|
||||||
|
{
|
||||||
|
return $this->domain;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Collection|Tag[]
|
* @return Collection|Tag[]
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -24,16 +24,15 @@ class ShortUrlDataTransformer implements DataTransformerInterface
|
||||||
*/
|
*/
|
||||||
public function transform($shortUrl): array // phpcs:ignore
|
public function transform($shortUrl): array // phpcs:ignore
|
||||||
{
|
{
|
||||||
$longUrl = $shortUrl->getLongUrl();
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'shortCode' => $shortUrl->getShortCode(),
|
'shortCode' => $shortUrl->getShortCode(),
|
||||||
'shortUrl' => $shortUrl->toString($this->domainConfig),
|
'shortUrl' => $shortUrl->toString($this->domainConfig),
|
||||||
'longUrl' => $longUrl,
|
'longUrl' => $shortUrl->getLongUrl(),
|
||||||
'dateCreated' => $shortUrl->getDateCreated()->toAtomString(),
|
'dateCreated' => $shortUrl->getDateCreated()->toAtomString(),
|
||||||
'visitsCount' => $shortUrl->getVisitsCount(),
|
'visitsCount' => $shortUrl->getVisitsCount(),
|
||||||
'tags' => invoke($shortUrl->getTags(), '__toString'),
|
'tags' => invoke($shortUrl->getTags(), '__toString'),
|
||||||
'meta' => $this->buildMeta($shortUrl),
|
'meta' => $this->buildMeta($shortUrl),
|
||||||
|
'domain' => $shortUrl->getDomain(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ class ListShortUrlsTest extends ApiTestCase
|
||||||
'validUntil' => null,
|
'validUntil' => null,
|
||||||
'maxVisits' => null,
|
'maxVisits' => null,
|
||||||
],
|
],
|
||||||
|
'domain' => null,
|
||||||
];
|
];
|
||||||
private const SHORT_URL_CUSTOM_SLUG_AND_DOMAIN = [
|
private const SHORT_URL_CUSTOM_SLUG_AND_DOMAIN = [
|
||||||
'shortCode' => 'custom-with-domain',
|
'shortCode' => 'custom-with-domain',
|
||||||
|
@ -37,6 +38,7 @@ class ListShortUrlsTest extends ApiTestCase
|
||||||
'validUntil' => null,
|
'validUntil' => null,
|
||||||
'maxVisits' => null,
|
'maxVisits' => null,
|
||||||
],
|
],
|
||||||
|
'domain' => 'some-domain.com',
|
||||||
];
|
];
|
||||||
private const SHORT_URL_META = [
|
private const SHORT_URL_META = [
|
||||||
'shortCode' => 'def456',
|
'shortCode' => 'def456',
|
||||||
|
@ -52,6 +54,7 @@ class ListShortUrlsTest extends ApiTestCase
|
||||||
'validUntil' => null,
|
'validUntil' => null,
|
||||||
'maxVisits' => null,
|
'maxVisits' => null,
|
||||||
],
|
],
|
||||||
|
'domain' => null,
|
||||||
];
|
];
|
||||||
private const SHORT_URL_CUSTOM_SLUG = [
|
private const SHORT_URL_CUSTOM_SLUG = [
|
||||||
'shortCode' => 'custom',
|
'shortCode' => 'custom',
|
||||||
|
@ -65,6 +68,7 @@ class ListShortUrlsTest extends ApiTestCase
|
||||||
'validUntil' => null,
|
'validUntil' => null,
|
||||||
'maxVisits' => 2,
|
'maxVisits' => 2,
|
||||||
],
|
],
|
||||||
|
'domain' => null,
|
||||||
];
|
];
|
||||||
private const SHORT_URL_CUSTOM_DOMAIN = [
|
private const SHORT_URL_CUSTOM_DOMAIN = [
|
||||||
'shortCode' => 'ghi789',
|
'shortCode' => 'ghi789',
|
||||||
|
@ -80,6 +84,7 @@ class ListShortUrlsTest extends ApiTestCase
|
||||||
'validUntil' => null,
|
'validUntil' => null,
|
||||||
'maxVisits' => null,
|
'maxVisits' => null,
|
||||||
],
|
],
|
||||||
|
'domain' => 'example.com',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue