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

66 lines
1.7 KiB
PHP
Raw 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;
use App\{Profile, Status, User};
use Cache;
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,
'created_at' => $admin->created_at->format('c'),
'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(),
'status_count' => Status::whereNull('uri')->count(),
'domain_count' => Profile::whereNotNull('domain')
->groupBy('domain')
->pluck('domain')
->count()
],
'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
}