X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=application%2Fapi%2FApiUtils.php;h=05a2840a6221d3c50c215c7994415c586b01677c;hb=53054b2bf6a919fd4ff9b44b6ad1986f21f488b6;hp=5156a5f783f0bc6767c0684f1c1a595959f3fbbd;hpb=3fb29fdda04ca86e04422d49b86cf646d53c4f9d;p=github%2Fshaarli%2FShaarli.git diff --git a/application/api/ApiUtils.php b/application/api/ApiUtils.php index 5156a5f7..05a2840a 100644 --- a/application/api/ApiUtils.php +++ b/application/api/ApiUtils.php @@ -1,4 +1,5 @@ iat) + if ( + empty($payload->iat) || $payload->iat > time() || time() - $payload->iat > ApiMiddleware::$TOKEN_DURATION ) { @@ -67,7 +69,7 @@ class ApiUtils if (! $bookmark->isNote()) { $out['url'] = $bookmark->getUrl(); } else { - $out['url'] = $indexUrl . $bookmark->getUrl(); + $out['url'] = rtrim($indexUrl, '/') . '/' . ltrim($bookmark->getUrl(), '/'); } $out['shorturl'] = $bookmark->getShortUrl(); $out['title'] = $bookmark->getTitle(); @@ -89,12 +91,12 @@ class ApiUtils * If no URL is provided, it will generate a local note URL. * If no title is provided, it will use the URL as title. * - * @param array $input Request Link. - * @param bool $defaultPrivate Request Link. + * @param array|null $input Request Link. + * @param bool $defaultPrivate Setting defined if a bookmark is private by default. * * @return Bookmark instance. */ - public static function buildLinkFromRequest($input, $defaultPrivate) + public static function buildBookmarkFromRequest(?array $input, bool $defaultPrivate): Bookmark { $bookmark = new Bookmark(); $url = ! empty($input['url']) ? cleanup_url($input['url']) : ''; @@ -110,6 +112,15 @@ class ApiUtils $bookmark->setTags(! empty($input['tags']) ? $input['tags'] : []); $bookmark->setPrivate($private); + $created = \DateTime::createFromFormat(\DateTime::ATOM, $input['created'] ?? ''); + if ($created instanceof \DateTimeInterface) { + $bookmark->setCreated($created); + } + $updated = \DateTime::createFromFormat(\DateTime::ATOM, $input['updated'] ?? ''); + if ($updated instanceof \DateTimeInterface) { + $bookmark->setUpdated($updated); + } + return $bookmark; }