pandora_transcribe/views.py
2025-01-24 19:43:09 +05:30

32 lines
982 B
Python

# -*- coding: utf-8 -*-
from oxdjango.decorators import login_required_json
from oxdjango.shortcuts import render_to_json_response, get_object_or_404_json, json_response
from item.models import Item
from oxdjango.api import actions
from user.models import has_capability
from . import tasks
@login_required_json
def transcribeAudio(request, data):
'''
Transcribe audio and add to subtitles layer
takes {
item: string // item id
}
returns {
item: id // item id
}
'''
response = {}
item = get_object_or_404_json(Item, public_id=data["item"])
if has_capability(request.user, 'canTranscribeAudio') and item.editalbe(request.user):
t = tasks.transcribe.delay(item=data["item"], user=request.user.username)
response["taskId"] = t.task_id
else:
response = json_response(status=403, text='permission denied')
return render_to_json_response(response)
actions.register(transcribeAudio, cache=False)