pixelfed/app/Http/Controllers/Api/InstanceApiController.php

64 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2019-01-03 05:00:31 +00:00
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
2024-06-12 08:58:25 +00:00
use App\{Profile, Instance, Status, User};
2019-01-03 05:00:31 +00:00
use Cache;
2024-06-12 08:58:25 +00:00
use App\Services\StatusService;
2019-01-03 05:00:31 +00:00
class InstanceApiController extends Controller {
protected function getData()
{
2019-02-25 18:56:24 +00:00
$contact = Cache::remember('api:v1:instance:contact', now()->addMinutes(1440), function() {
2019-01-03 05:00:31 +00:00
$admin = User::whereIsAdmin(true)->first()->profile;
return [
'id' => $admin->id,
'username' => $admin->username,
'acct' => $admin->username,
'display_name' => e($admin->name),
'locked' => (bool) $admin->is_private,
2022-05-20 19:22:59 +00:00
'created_at' => str_replace('+00:00', 'Z', $admin->created_at->format(DATE_RFC3339_EXTENDED)),
2019-01-03 05:00:31 +00:00
'note' => e($admin->bio),
'url' => $admin->url(),
'avatar' => $admin->avatarUrl(),
'avatar_static' => $admin->avatarUrl(),
'header' => null,
'header_static' => null,
'moved' => null,
'fields' => null,
'bot' => null,
];
});
$res = [
'uri' => config('pixelfed.domain.app'),
2021-05-08 03:47:51 +00:00
'title' => config_cache('app.name'),
2019-01-03 05:00:31 +00:00
'description' => '',
'version' => config('pixelfed.version'),
'urls' => [],
'stats' => [
'user_count' => User::count(),
2024-06-12 08:58:25 +00:00
'status_count' => StatusService::totalLocalStatuses(),
'domain_count' => Instance::count()
2019-01-03 05:00:31 +00:00
],
'thumbnail' => '',
'languages' => [],
'contact_account' => $contact
];
return $res;
}
public function instance()
{
2019-02-25 18:56:24 +00:00
$res = Cache::remember('api:v1:instance', now()->addMinutes(60), function() {
2019-01-03 05:00:31 +00:00
return json_encode($this->getData());
});
return response($res)->header('Content-Type', 'application/json');
}
2020-02-22 13:47:49 +00:00
}