Skip to content

Commit

Permalink
Persist icons and altsvcs on Postgres (#2189)
Browse files Browse the repository at this point in the history
* Persist icons and altsvcs on Postgres

* Fix list API to terminate SQL output with LF
  • Loading branch information
chitoku-k authored Dec 12, 2022
1 parent 06358de commit 49ecd32
Show file tree
Hide file tree
Showing 33 changed files with 588 additions and 476 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ BuildKit(または Docker の対応するバージョン)あるいは Builda
- `docker build` を利用する場合: Docker 18.09 以上
- `docker buildx` を利用する場合: Docker 19.03 以上

nginx + PHP-FPM + PostgreSQL + Redis で構成されています。
nginx + PHP-FPM + PostgreSQL で構成されています。

### 設定

Expand All @@ -105,8 +105,6 @@ $ export HOMOCHECKER_DB_SSLCERT=/path/to/sslcert
$ export HOMOCHECKER_DB_SSLKEY=/path/to/sslkey
$ export HOMOCHECKER_DB_SSLROOTCERT=/path/to/sslrootcert
$ export HOMOCHECKER_LOG_LEVEL=debug
$ export HOMOCHECKER_REDIS_HOST=redis
$ export HOMOCHECKER_REDIS_PORT=6379
$ export HOMOCHECKER_TWITTER_CONSUMER_KEY=
$ export HOMOCHECKER_TWITTER_CONSUMER_SECRET=
$ export HOMOCHECKER_TWITTER_TOKEN=
Expand Down
6 changes: 2 additions & 4 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ RUN --mount=type=cache,id=api:/var/cache/apt,target=/var/cache/apt \
make clean && \
ln -s /etc/ssl /usr/local/ssl && \
pecl install \
apcu \
redis && \
apcu && \
docker-php-ext-enable \
apcu \
redis && \
apcu && \
docker-php-ext-install \
opcache \
pdo_pgsql && \
Expand Down
2 changes: 0 additions & 2 deletions api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
"require": {
"guzzlehttp/guzzle": "^7.5",
"guzzlehttp/oauth-subscriber": "^0.6.0",
"illuminate/cache": "^9.43",
"illuminate/config": "^9.43",
"illuminate/database": "^9.43",
"illuminate/events": "^9.43",
"illuminate/log": "^9.43",
"illuminate/redis": "^9.43",
"middlewares/access-log": "^2.1",
"phpoption/phpoption": "^1.9",
"promphp/prometheus_client_php": "^2.6",
Expand Down
116 changes: 1 addition & 115 deletions api/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions api/src/Contracts/Repository/AltsvcRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);

namespace HomoChecker\Contracts\Repository;

interface AltsvcRepository
{
/**
* Retrieve all entries.
* @return \stdClass[] The entries.
*/
public function findAll(): array;

/**
* Save the entry.
* @param string $url The URL.
* @param string $protocol The protocol ID.
* @param string $maxAge The max age.
*/
public function save(string $url, string $protocol, string $maxAge): void;
}
15 changes: 15 additions & 0 deletions api/src/Contracts/Repository/ProfileRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
declare(strict_types=1);

namespace HomoChecker\Contracts\Repository;

interface ProfileRepository
{
/**
* Save the profile.
* @param string $screenName The screen name.
* @param string $iconURL The icon URL.
* @param string $expiresAt The expiration.
*/
public function save(string $screenName, string $iconURL, string $expiresAt): void;
}
27 changes: 0 additions & 27 deletions api/src/Contracts/Service/CacheService.php

This file was deleted.

27 changes: 27 additions & 0 deletions api/src/Domain/Homo.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class Homo
*/
protected ?string $url;

/**
* @var ?Profile The profile.
*/
protected ?Profile $profile = null;

/**
* @param array|object $homo
*/
Expand All @@ -36,6 +41,10 @@ public function __construct(array|object $homo = null)
$this->setScreenName($homo->screen_name ?? null);
$this->setService($homo->service ?? null);
$this->setUrl($homo->url ?? null);

if (isset($homo->icon_url)) {
$this->setProfile(new Profile(['icon_url' => $homo->icon_url]));
}
}

/**
Expand Down Expand Up @@ -109,4 +118,22 @@ public function setUrl(?string $url): void
{
$this->url = $url;
}

/**
* Get the profile.
* @return ?Profile The profile.
*/
public function getProfile(): ?Profile
{
return $this->profile;
}

/**
* Set the profile.
* @param ?Profile $profile The profile.
*/
public function setProfile(?Profile $profile): void
{
$this->profile = $profile;
}
}
39 changes: 39 additions & 0 deletions api/src/Domain/Profile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);

namespace HomoChecker\Domain;

class Profile
{
/**
* @var ?string The icon URL.
*/
protected ?string $iconUrl;

/**
* @param array|object $profile
*/
public function __construct(array|object $profile = null)
{
$profile = (object) $profile;

$this->setIconUrl($profile->icon_url ?? null);
}

/**
* Get the icon URL.
* @return ?string The icon URL.
*/
public function getIconUrl(): ?string
{
return $this->iconUrl;
}

/**
* Set the icon URL.
*/
public function setIconUrl(?string $iconUrl): void
{
$this->iconUrl = $iconUrl;
}
}
6 changes: 6 additions & 0 deletions api/src/Providers/HomoAppProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
use HomoChecker\Action\HealthCheckAction;
use HomoChecker\Action\ListAction;
use HomoChecker\Action\MetricsAction;
use HomoChecker\Contracts\Repository\AltsvcRepository as AltsvcRepositoryContract;
use HomoChecker\Contracts\Repository\HomoRepository as HomoRepositoryContract;
use HomoChecker\Contracts\Repository\ProfileRepository as ProfileRepositoryContract;
use HomoChecker\Http\NonBufferedBody;
use HomoChecker\Middleware\AccessLogMiddleware;
use HomoChecker\Middleware\ErrorMiddleware;
use HomoChecker\Middleware\MetricsMiddleware;
use HomoChecker\Repository\AltsvcRepository;
use HomoChecker\Repository\HomoRepository;
use HomoChecker\Repository\ProfileRepository;
use Illuminate\Config\Repository;
use Illuminate\Contracts\Container\Container;
use Illuminate\Support\ServiceProvider;
Expand All @@ -35,7 +39,9 @@ public function register()
$this->app->singleton(ListAction::class);
$this->app->singleton(BadgeAction::class);

$this->app->singleton(AltsvcRepositoryContract::class, AltsvcRepository::class);
$this->app->singleton(HomoRepositoryContract::class, HomoRepository::class);
$this->app->singleton(ProfileRepositoryContract::class, ProfileRepository::class);

$this->app->singleton('app', function (Container $app) {
AppFactory::setContainer($app);
Expand Down
Loading

0 comments on commit 49ecd32

Please sign in to comment.