forked from 0x2620/pandora
validate in/out values of edit clips
This commit is contained in:
parent
f94f25d7c7
commit
2473dfd231
2 changed files with 18 additions and 3 deletions
|
@ -65,6 +65,11 @@ class Edit(models.Model):
|
||||||
clip.index = 0
|
clip.index = 0
|
||||||
else:
|
else:
|
||||||
clip.index +=1
|
clip.index +=1
|
||||||
|
# dont add clip if in/out are invalid
|
||||||
|
if not clip.annotation:
|
||||||
|
duration = clip.item.sort.duration
|
||||||
|
if clip.start >= clip.end or clip.start >= duration or clip.end > duration:
|
||||||
|
return False
|
||||||
clip.save()
|
clip.save()
|
||||||
return clip
|
return clip
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,9 @@ def addClip(request):
|
||||||
edit = get_edit_or_404_json(data['edit'])
|
edit = get_edit_or_404_json(data['edit'])
|
||||||
if edit.editable(request.user):
|
if edit.editable(request.user):
|
||||||
clip = edit.add_clip(data)
|
clip = edit.add_clip(data)
|
||||||
|
if not clip:
|
||||||
|
response = json_response(status=500, text='invalid in/out')
|
||||||
|
else:
|
||||||
response['data'] = clip.json(request.user)
|
response['data'] = clip.json(request.user)
|
||||||
else:
|
else:
|
||||||
response = json_response(status=403, text='permission denied')
|
response = json_response(status=403, text='permission denied')
|
||||||
|
@ -87,6 +90,7 @@ def editClip(request):
|
||||||
response = json_response()
|
response = json_response()
|
||||||
data = json.loads(request.POST['data'])
|
data = json.loads(request.POST['data'])
|
||||||
clip = get_object_or_404_json(models.Clip, pk=ox.fromAZ(data['id']))
|
clip = get_object_or_404_json(models.Clip, pk=ox.fromAZ(data['id']))
|
||||||
|
valid = False
|
||||||
if clip.edit.editable(request.user):
|
if clip.edit.editable(request.user):
|
||||||
for key in ('in', 'out'):
|
for key in ('in', 'out'):
|
||||||
if key in data:
|
if key in data:
|
||||||
|
@ -95,6 +99,12 @@ def editClip(request):
|
||||||
clip.end = clip.annotation.end
|
clip.end = clip.annotation.end
|
||||||
clip.annotation = None
|
clip.annotation = None
|
||||||
setattr(clip, {'in': 'start', 'out': 'end'}.get(key), float(data[key]))
|
setattr(clip, {'in': 'start', 'out': 'end'}.get(key), float(data[key]))
|
||||||
|
if not clip.annotation:
|
||||||
|
duration = clip.item.sort.duration
|
||||||
|
if clip.start >= clip.end or clip.start >= duration or clip.end > duration:
|
||||||
|
response = json_response(status=500, text='invalid in/out')
|
||||||
|
valid = False
|
||||||
|
if valid:
|
||||||
clip.save()
|
clip.save()
|
||||||
response['data'] = clip.json(user=request.user)
|
response['data'] = clip.json(user=request.user)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue