修复问题

master
newrain 2 years ago
parent 212dcb89cd
commit bd33aea76b
  1. 2
      App/models.py
  2. 15
      App/views.py
  3. 2
      templates/index.html

@ -66,7 +66,7 @@ class thumbs(models.Model):
class videoUpload(models.Model):
username = models.CharField(max_length=100)
video_time = models.DateField(auto_now_add=True)
video_title = models.CharField(max_length=200)
video_title = models.CharField(max_length=200, unique=True)
video_size = models.IntegerField(default=0)
video_path = models.FileField()
video_desc = models.TextField(default="")

@ -146,18 +146,21 @@ def upload(request):
if not os.path.exists(file_path):
os.makedirs(file_path)
file_path = os.path.join(file_path, i.name)
video = videoUpload.objects.filter(username=auth.get_user(request).username, video_title=i.name,
video_size=i.size)
video = videoUpload.objects.filter(video_title=i.name,video_size=i.size)
if video.exists():
import shutil
shutil.move(os.path.join(settings.MEDIA_ROOT,str(video.get().video_path).replace('/upload/','')), file_path)
video.update(video_time=today, video_path=os.path.join('/upload/videos/',file_path.split(r"videos")[-1][1:].replace('\\','/')))
else:
image = get_image('215x280', file_type)
videoUpload.objects.create(username=auth.get_user(request).username, video_title=i.name, video_size=i.size, video_time=today, video_path=os.path.join('/upload/videos/',file_path.split(r"videos")[-1][1:].replace('\\','/')), video_image=image, video_desc=file_type)
with open(file_path, 'wb') as f:
for chunk in i.chunks():
f.write(chunk)
try:
videoUpload.objects.create(username=auth.get_user(request).username, video_title=i.name, video_size=i.size, video_time=today, video_path=os.path.join('/upload/videos/',file_path.split(r"videos")[-1][1:].replace('\\','/')), video_image=image, video_desc=file_type)
with open(file_path, 'wb') as f:
for chunk in i.chunks():
f.write(chunk)
except Exception as e:
print(e)
if data:
return HttpResponse(json.dumps(data))
elif ftype == 'editmd':

@ -8,7 +8,7 @@
{% endblock %}
{% block login %}
<script>
alert('本次更新:\n1、上传页面加载问题解决')
alert('本次更新:\n1、修复上传视频重复问题')
</script>
<header style="padding-top: 70px">
<div class="px-3 py-2 border-bottom mb-3">

Loading…
Cancel
Save