최지우

edit video api

...@@ -3,7 +3,7 @@ from django.conf import settings ...@@ -3,7 +3,7 @@ from django.conf import settings
3 from django.utils import timezone 3 from django.utils import timezone
4 4
5 # Create your models here. 5 # Create your models here.
6 -class Phone(models.Model) : 6 +class Device(models.Model) :
7 username = models.CharField(max_length = 255) 7 username = models.CharField(max_length = 255)
8 and_id = models.CharField(max_length = 255, primary_key = True) 8 and_id = models.CharField(max_length = 255, primary_key = True)
9 9
......
...@@ -4,7 +4,7 @@ from rest_framework import serializers ...@@ -4,7 +4,7 @@ from rest_framework import serializers
4 4
5 class PhoneSerializer(serializers.ModelSerializer) : 5 class PhoneSerializer(serializers.ModelSerializer) :
6 class Meta : 6 class Meta :
7 - model = Phone 7 + model = Device
8 fields = '__all__' 8 fields = '__all__'
9 9
10 class VideoSerializer(serializers.ModelSerializer) : 10 class VideoSerializer(serializers.ModelSerializer) :
......
...@@ -20,7 +20,7 @@ from src.settings import S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_STORAGE_BUCK ...@@ -20,7 +20,7 @@ from src.settings import S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_STORAGE_BUCK
20 from datetime import datetime, timedelta 20 from datetime import datetime, timedelta
21 # Create your views here. 21 # Create your views here.
22 22
23 -class VideoDownload(APIView) : 23 +class Video(APIView) :
24 def get(self, request, format = None) : 24 def get(self, request, format = None) :
25 try : 25 try :
26 request_id = request.GET.get('vidname') 26 request_id = request.GET.get('vidname')
...@@ -44,18 +44,6 @@ class VideoDownload(APIView) : ...@@ -44,18 +44,6 @@ class VideoDownload(APIView) :
44 'date' : datetime.now() 44 'date' : datetime.now()
45 }, status = status.HTTP_404_NOT_FOUND) 45 }, status = status.HTTP_404_NOT_FOUND)
46 46
47 -class VideoAutoDelete(APIView) :
48 - def post(self, request, format = None) :
49 - checkdate = datetime.now() + timedelta(days = -7)
50 - quaryset = Video.objects.filter(created__lt = checkdate)
51 - session = boto3.session.Session(aws_access_key_id = S3_ACCESS_KEY_ID, aws_secret_access_key = S3_SECRET_ACCESS_KEY, region_name = AWS_REGION)
52 - s3 = session.client('s3')
53 - for delvid in quaryset :
54 - s3.delete_object(Bucket = S3_STORAGE_BUCKET_NAME, Key = str(delvid.vidname))
55 - quaryset.delete()
56 - return Response(status = status.HTTP_200_OK)
57 -
58 -class VideoDelete(APIView) :
59 def post(self, request, format = None) : 47 def post(self, request, format = None) :
60 try : 48 try :
61 request_id = request.GET.get('vidname') 49 request_id = request.GET.get('vidname')
...@@ -73,3 +61,16 @@ class VideoDelete(APIView) : ...@@ -73,3 +61,16 @@ class VideoDelete(APIView) :
73 'error' : "FieldDoesNotExist ", 61 'error' : "FieldDoesNotExist ",
74 'date' : datetime.now() 62 'date' : datetime.now()
75 }, status = status.HTTP_400_BAD_REQUEST) 63 }, status = status.HTTP_400_BAD_REQUEST)
64 +
65 +class CheckDate(APIView) :
66 + def post(self, request, format = None) :
67 + checkdate = datetime.now() + timedelta(days = -7)
68 + quaryset = Video.objects.filter(created__lt = checkdate)
69 + session = boto3.session.Session(aws_access_key_id = S3_ACCESS_KEY_ID, aws_secret_access_key = S3_SECRET_ACCESS_KEY, region_name = AWS_REGION)
70 + s3 = session.client('s3')
71 + for delvid in quaryset :
72 + s3.delete_object(Bucket = S3_STORAGE_BUCKET_NAME, Key = str(delvid.vidname))
73 + quaryset.delete()
74 + return Response(status = status.HTTP_200_OK)
75 +
76 +
......
...@@ -20,7 +20,6 @@ from api import views ...@@ -20,7 +20,6 @@ from api import views
20 20
21 urlpatterns = [ 21 urlpatterns = [
22 path('admin/', admin.site.urls), 22 path('admin/', admin.site.urls),
23 - path('api/videoDownload/', views.VideoDownload.as_view()), 23 + path('api/video/', views.Video.as_view()),
24 - path('api/videoAutoDelete/', views.VideoAutoDelete.as_view()), 24 + path('api/videoAutoDelete/', views.CheckDate.as_view()),
25 - path('api/videoDelete/', views.VideoDelete.as_view()),
26 ] 25 ]
......