Merge pull request #3545 from pixelfed/staging

Staging
This commit is contained in:
daniel 2022-06-15 02:18:26 -06:00 committed by GitHub
commit 4f3a0d0ead
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 297 additions and 210 deletions

View file

@ -4,6 +4,7 @@
### New Features ### New Features
- Custom content warnings/spoiler text ([d4864213](https://github.com/pixelfed/pixelfed/commit/d4864213)) - Custom content warnings/spoiler text ([d4864213](https://github.com/pixelfed/pixelfed/commit/d4864213))
- Add NetworkTimelineService cache ([1310d95c](https://github.com/pixelfed/pixelfed/commit/1310d95c))
### Breaking ### Breaking
- Replaced `predis` with `phpredis` as default redis driver due to predis being deprecated, install [phpredis](https://github.com/phpredis/phpredis/blob/develop/INSTALL.markdown) if you're still using predis. - Replaced `predis` with `phpredis` as default redis driver due to predis being deprecated, install [phpredis](https://github.com/phpredis/phpredis/blob/develop/INSTALL.markdown) if you're still using predis.
@ -27,6 +28,13 @@
- Refactor AP profileFetch logic to fix race conditions and improve updating fields and avatars ([505261da](https://github.com/pixelfed/pixelfed/commit/505261da)) - Refactor AP profileFetch logic to fix race conditions and improve updating fields and avatars ([505261da](https://github.com/pixelfed/pixelfed/commit/505261da))
- Update network timeline api, limit falloff to 2 days ([13a66303](https://github.com/pixelfed/pixelfed/commit/13a66303)) - Update network timeline api, limit falloff to 2 days ([13a66303](https://github.com/pixelfed/pixelfed/commit/13a66303))
- Update Inbox, store follow request activity ([c82f2085](https://github.com/pixelfed/pixelfed/commit/c82f2085)) - Update Inbox, store follow request activity ([c82f2085](https://github.com/pixelfed/pixelfed/commit/c82f2085))
- Update UserFilterService, improve cache strategy by using in-memory state via UserFilterObserver for empty lists with a ttl of 90 days ([9c17def4](https://github.com/pixelfed/pixelfed/commit/9c17def4))
- Update ApiV1Controller, add network timeline support via NetworkTimelineService ([f54fd6e9](https://github.com/pixelfed/pixelfed/commit/f54fd6e9))
- Bump max_collection_length default to 100 from 18 ([65cf9cca](https://github.com/pixelfed/pixelfed/commit/65cf9cca))
- Improve follow request flow, federate rejections and delete rejections from database to properly handle future follow requests from same actor ([4470981a](https://github.com/pixelfed/pixelfed/commit/4470981a))
- Update follower counts on follow_request approval ([e97900a0](https://github.com/pixelfed/pixelfed/commit/e97900a0))
- Update ApiV1Controller, improve local/remote logic in public timeline endpoint ([4ff179ad](https://github.com/pixelfed/pixelfed/commit/4ff179ad))
- Update ApiV1Controller, fix network timeline ([11e99d78](https://github.com/pixelfed/pixelfed/commit/11e99d78))
- ([](https://github.com/pixelfed/pixelfed/commit/)) - ([](https://github.com/pixelfed/pixelfed/commit/))
## [v0.11.3 (2022-05-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.2...v0.11.3) ## [v0.11.3 (2022-05-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.2...v0.11.3)

View file

@ -1973,17 +1973,18 @@ class ApiV1Controller extends Controller
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX, 'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX, 'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
'limit' => 'nullable|integer|max:100', 'limit' => 'nullable|integer|max:100',
'remote' => 'sometimes' 'remote' => 'sometimes',
'local' => 'sometimes'
]); ]);
$min = $request->input('min_id'); $min = $request->input('min_id');
$max = $request->input('max_id'); $max = $request->input('max_id');
$limit = $request->input('limit') ?? 20; $limit = $request->input('limit') ?? 20;
$user = $request->user(); $user = $request->user();
$remote = $request->has('remote'); $remote = ($request->has('remote') && $request->input('remote') == true) || ($request->filled('local') && $request->input('local') != true);
$filtered = $user ? UserFilterService::filters($user->profile_id) : []; $filtered = $user ? UserFilterService::filters($user->profile_id) : [];
if($remote && config('instance.timeline.network.cached')) { if((!$request->has('local') || $remote) && config('instance.timeline.network.cached')) {
Cache::remember('api:v1:timelines:network:cache_check', 10368000, function() { Cache::remember('api:v1:timelines:network:cache_check', 10368000, function() {
if(NetworkTimelineService::count() == 0) { if(NetworkTimelineService::count() == 0) {
NetworkTimelineService::warmCache(true, config('instance.timeline.network.cache_dropoff')); NetworkTimelineService::warmCache(true, config('instance.timeline.network.cache_dropoff'));

View file

@ -46,11 +46,13 @@ class LiveStreamController extends Controller
$stream->description = $request->input('description'); $stream->description = $request->input('description');
$stream->visibility = $request->input('visibility'); $stream->visibility = $request->input('visibility');
$stream->profile_id = $request->user()->profile_id; $stream->profile_id = $request->user()->profile_id;
$stream->stream_id = Str::random(40); $stream->stream_id = Str::random(40) . '_' . $stream->profile_id;
$stream->stream_key = Str::random(64); $stream->stream_key = 'streamkey-' . Str::random(64);
$stream->save(); $stream->save();
return [ return [
'host' => $stream->getStreamServer(),
'key' => $stream->stream_key,
'url' => $stream->getStreamKeyUrl(), 'url' => $stream->getStreamKeyUrl(),
'id' => $stream->stream_id 'id' => $stream->stream_id
]; ];
@ -143,8 +145,8 @@ class LiveStreamController extends Controller
} }
$res = collect(LiveStreamService::getComments($stream->profile_id)) $res = collect(LiveStreamService::getComments($stream->profile_id))
->map(function($r) { ->map(function($res) {
return json_decode($r); return json_decode($res);
}); });
return $res; return $res;
@ -233,4 +235,81 @@ class LiveStreamController extends Controller
return response()->json($res, 200, [], JSON_UNESCAPED_SLASHES); return response()->json($res, 200, [], JSON_UNESCAPED_SLASHES);
} }
public function clientBroadcastPublish(Request $request)
{
abort_if(!config('livestreaming.enabled'), 400);
$key = $request->input('name');
$name = $request->input('name');
abort_if(!$name, 400);
if(empty($key)) {
abort_if(!$request->filled('tcurl'), 400);
$url = $this->parseStreamUrl($request->input('tcurl'));
$key = $request->filled('name') ? $request->input('name') : $url['name'];
}
$token = substr($name, 0, 10) === 'streamkey-';
if($token) {
$stream = LiveStream::whereStreamKey($key)->firstOrFail();
return redirect($stream->getStreamRtmpUrl(), 301);
} else {
$stream = LiveStream::whereStreamId($key)->firstOrFail();
}
if($request->filled('name') && $token == false) {
$stream->live_at = now();
$stream->save();
return [];
} else {
abort(400);
}
abort(400);
}
public function clientBroadcastFinish(Request $request)
{
abort_if(!config('livestreaming.enabled'), 400);
abort_if(!$request->filled('tcurl'), 400);
$url = $this->parseStreamUrl($request->input('tcurl'));
$name = $url['name'] ?? $request->input('name');
$stream = LiveStream::whereStreamId($name)->whereStreamKey($url['key'])->firstOrFail();
if(config('livestreaming.broadcast.delete_token_after_finished')) {
$stream->delete();
} else {
$stream->live_at = null;
$stream->save();
}
return [];
}
protected function parseStreamUrl($url)
{
$name = null;
$key = null;
$query = parse_url($url, PHP_URL_QUERY);
$parts = explode('&', $query);
foreach($parts as $part) {
if (!strlen(trim($part))) {
continue;
}
$s = explode('=', $part);
if(in_array($s[0], ['name', 'key'])) {
if($s[0] === 'name') {
$name = $s[1];
}
if($s[0] === 'key') {
$key = $s[1];
}
}
}
return ['name' => $name, 'key' => $key];
}
} }

View file

@ -16,32 +16,26 @@ class LiveStream extends Model
return url($path); return url($path);
} }
public function getStreamKeyUrl() public function getStreamServer()
{ {
$proto = 'rtmp://'; $proto = 'rtmp://';
$host = config('livestreaming.server.host'); $host = config('livestreaming.server.host');
$port = ':' . config('livestreaming.server.port'); $port = ':' . config('livestreaming.server.port');
$path = '/' . config('livestreaming.server.path') . '?'; $path = '/' . config('livestreaming.server.path');
$query = http_build_query([ return $proto . $host . $port . $path;
'name' => $this->stream_id, }
'key' => $this->stream_key,
'ts' => time()
]);
return $proto . $host . $port . $path . $query; public function getStreamKeyUrl()
{
$path = $this->getStreamServer() . '?';
$query = http_build_query([
'name' => $this->stream_key,
]);
return $path . $query;
} }
public function getStreamRtmpUrl() public function getStreamRtmpUrl()
{ {
$proto = 'rtmp://'; return $this->getStreamServer() . '/' . $this->stream_id;
$host = config('livestreaming.server.host');
$port = ':' . config('livestreaming.server.port');
$path = '/' . config('livestreaming.server.path') . '/'. $this->stream_id . '?';
$query = http_build_query([
'key' => $this->stream_key,
'ts' => time()
]);
return $proto . $host . $port . $path . $query;
} }
} }

View file

@ -106,5 +106,7 @@ Route::group(['prefix' => 'api'], function() use($middleware) {
Route::post('chat/message', 'LiveStreamController@addChatComment')->middleware($middleware); Route::post('chat/message', 'LiveStreamController@addChatComment')->middleware($middleware);
Route::post('chat/delete', 'LiveStreamController@deleteChatComment')->middleware($middleware); Route::post('chat/delete', 'LiveStreamController@deleteChatComment')->middleware($middleware);
Route::get('config', 'LiveStreamController@getConfig')->middleware($middleware); Route::get('config', 'LiveStreamController@getConfig')->middleware($middleware);
Route::post('broadcast/publish', 'LiveStreamController@clientBroadcastPublish');
Route::post('broadcast/finish', 'LiveStreamController@clientBroadcastFinish');
}); });
}); });

View file

@ -5,3 +5,4 @@
!emoji/ !emoji/
!textimg/ !textimg/
!headers/ !headers/
!live-hls/

View file

@ -0,0 +1,2 @@
*
!.gitignore