2021-04-21 05:11:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use Cache;
|
|
|
|
use App\Instance;
|
|
|
|
|
|
|
|
class InstanceService
|
|
|
|
{
|
2022-03-13 06:32:31 +00:00
|
|
|
const CACHE_KEY_BANNED_DOMAINS = 'instances:banned:domains';
|
|
|
|
const CACHE_KEY_UNLISTED_DOMAINS = 'instances:unlisted:domains';
|
|
|
|
const CACHE_KEY_NSFW_DOMAINS = 'instances:auto_cw:domains';
|
|
|
|
|
2021-10-20 01:51:14 +00:00
|
|
|
public static function getByDomain($domain)
|
|
|
|
{
|
|
|
|
return Cache::remember('pf:services:instance:by_domain:'.$domain, 3600, function() use($domain) {
|
|
|
|
return Instance::whereDomain($domain)->first();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-21 05:11:43 +00:00
|
|
|
public static function getBannedDomains()
|
|
|
|
{
|
2022-03-13 06:32:31 +00:00
|
|
|
return Cache::remember(self::CACHE_KEY_BANNED_DOMAINS, now()->addHours(12), function() {
|
2021-04-21 05:11:43 +00:00
|
|
|
return Instance::whereBanned(true)->pluck('domain')->toArray();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getUnlistedDomains()
|
|
|
|
{
|
2022-03-13 06:32:31 +00:00
|
|
|
return Cache::remember(self::CACHE_KEY_UNLISTED_DOMAINS, now()->addHours(12), function() {
|
2021-04-21 05:11:43 +00:00
|
|
|
return Instance::whereUnlisted(true)->pluck('domain')->toArray();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getNsfwDomains()
|
|
|
|
{
|
2022-03-13 06:32:31 +00:00
|
|
|
return Cache::remember(self::CACHE_KEY_NSFW_DOMAINS, now()->addHours(12), function() {
|
2021-04-21 05:11:43 +00:00
|
|
|
return Instance::whereAutoCw(true)->pluck('domain')->toArray();
|
|
|
|
});
|
|
|
|
}
|
2021-08-31 06:37:28 +00:00
|
|
|
|
|
|
|
public static function software($domain)
|
|
|
|
{
|
|
|
|
$key = 'instances:software:' . strtolower($domain);
|
|
|
|
return Cache::remember($key, 86400, function() use($domain) {
|
|
|
|
$instance = Instance::whereDomain($domain)->first();
|
|
|
|
if(!$instance) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return $instance->software;
|
|
|
|
});
|
|
|
|
}
|
2021-04-21 05:11:43 +00:00
|
|
|
}
|