48 lines
1.4 KiB
Python
48 lines
1.4 KiB
Python
|
import logging
|
||
|
import json
|
||
|
|
||
|
from django.core.exceptions import ObjectDoesNotExist
|
||
|
from django.http import HttpResponse
|
||
|
from django.views.decorators.csrf import csrf_exempt
|
||
|
|
||
|
from config.models import Stream
|
||
|
|
||
|
|
||
|
logger = logging.getLogger(__name__)
|
||
|
|
||
|
from config.tasks import async_scrape_srs_servers
|
||
|
|
||
|
|
||
|
@csrf_exempt
|
||
|
def callback_srs(request):
|
||
|
if request.method != 'POST':
|
||
|
return HttpResponse('1', status=405)
|
||
|
|
||
|
try:
|
||
|
json_data = json.loads(request.body)
|
||
|
except json.decoder.JSONDecodeError:
|
||
|
return HttpResponse('1', status=400)
|
||
|
|
||
|
try:
|
||
|
app_name = json_data['app']
|
||
|
# QUIRK this is a weird bug when pushing from OME to SRS. wtf.
|
||
|
# for some reason srs interprets the incoming app as app/stream, and passes this on to portier.
|
||
|
# only keep the stuff infront of a (potential) slash, and throw away the rest. problem solved^tm
|
||
|
app_name = app_name.split('/')[0]
|
||
|
# ENDQUIRK
|
||
|
stream_name = json_data['stream']
|
||
|
param = json_data['param']
|
||
|
except KeyError:
|
||
|
return HttpResponse('1', status=401)
|
||
|
try:
|
||
|
Stream.objects.get(stream=stream_name)
|
||
|
|
||
|
except ObjectDoesNotExist:
|
||
|
return HttpResponse('1', status=401)
|
||
|
|
||
|
# Scraping the server will make sure we are using the actual data from the server
|
||
|
# and updating the count of the stream instances.
|
||
|
async_scrape_srs_servers.delay()
|
||
|
|
||
|
return HttpResponse('0')
|