Toggle navigation
Toggle navigation
This project
Loading...
Sign in
cse437_e
/
smartdoorlock-backend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
최지우
2020-10-19 19:57:23 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
93b922c15e50250d56b2f23e061b2d043ee247f2
93b922c1
1 parent
44b8dc32
edit video api
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
18 deletions
api/models.py
api/serializers.py
api/views.py
src/urls.py
api/models.py
View file @
93b922c
...
...
@@ -3,7 +3,7 @@ from django.conf import settings
from
django.utils
import
timezone
# Create your models here.
class
Phon
e
(
models
.
Model
)
:
class
Devic
e
(
models
.
Model
)
:
username
=
models
.
CharField
(
max_length
=
255
)
and_id
=
models
.
CharField
(
max_length
=
255
,
primary_key
=
True
)
...
...
api/serializers.py
View file @
93b922c
...
...
@@ -4,7 +4,7 @@ from rest_framework import serializers
class
PhoneSerializer
(
serializers
.
ModelSerializer
)
:
class
Meta
:
model
=
Phon
e
model
=
Devic
e
fields
=
'__all__'
class
VideoSerializer
(
serializers
.
ModelSerializer
)
:
...
...
api/views.py
View file @
93b922c
...
...
@@ -20,7 +20,7 @@ from src.settings import S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_STORAGE_BUCK
from
datetime
import
datetime
,
timedelta
# Create your views here.
class
Video
Download
(
APIView
)
:
class
Video
(
APIView
)
:
def
get
(
self
,
request
,
format
=
None
)
:
try
:
request_id
=
request
.
GET
.
get
(
'vidname'
)
...
...
@@ -44,18 +44,6 @@ class VideoDownload(APIView) :
'date'
:
datetime
.
now
()
},
status
=
status
.
HTTP_404_NOT_FOUND
)
class
VideoAutoDelete
(
APIView
)
:
def
post
(
self
,
request
,
format
=
None
)
:
checkdate
=
datetime
.
now
()
+
timedelta
(
days
=
-
7
)
quaryset
=
Video
.
objects
.
filter
(
created__lt
=
checkdate
)
session
=
boto3
.
session
.
Session
(
aws_access_key_id
=
S3_ACCESS_KEY_ID
,
aws_secret_access_key
=
S3_SECRET_ACCESS_KEY
,
region_name
=
AWS_REGION
)
s3
=
session
.
client
(
's3'
)
for
delvid
in
quaryset
:
s3
.
delete_object
(
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
str
(
delvid
.
vidname
))
quaryset
.
delete
()
return
Response
(
status
=
status
.
HTTP_200_OK
)
class
VideoDelete
(
APIView
)
:
def
post
(
self
,
request
,
format
=
None
)
:
try
:
request_id
=
request
.
GET
.
get
(
'vidname'
)
...
...
@@ -73,3 +61,16 @@ class VideoDelete(APIView) :
'error'
:
"FieldDoesNotExist "
,
'date'
:
datetime
.
now
()
},
status
=
status
.
HTTP_400_BAD_REQUEST
)
class
CheckDate
(
APIView
)
:
def
post
(
self
,
request
,
format
=
None
)
:
checkdate
=
datetime
.
now
()
+
timedelta
(
days
=
-
7
)
quaryset
=
Video
.
objects
.
filter
(
created__lt
=
checkdate
)
session
=
boto3
.
session
.
Session
(
aws_access_key_id
=
S3_ACCESS_KEY_ID
,
aws_secret_access_key
=
S3_SECRET_ACCESS_KEY
,
region_name
=
AWS_REGION
)
s3
=
session
.
client
(
's3'
)
for
delvid
in
quaryset
:
s3
.
delete_object
(
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
str
(
delvid
.
vidname
))
quaryset
.
delete
()
return
Response
(
status
=
status
.
HTTP_200_OK
)
...
...
src/urls.py
View file @
93b922c
...
...
@@ -20,7 +20,6 @@ from api import views
urlpatterns
=
[
path
(
'admin/'
,
admin
.
site
.
urls
),
path
(
'api/videoDownload/'
,
views
.
VideoDownload
.
as_view
()),
path
(
'api/videoAutoDelete/'
,
views
.
VideoAutoDelete
.
as_view
()),
path
(
'api/videoDelete/'
,
views
.
VideoDelete
.
as_view
()),
path
(
'api/video/'
,
views
.
Video
.
as_view
()),
path
(
'api/videoAutoDelete/'
,
views
.
CheckDate
.
as_view
()),
]
...
...
Please
register
or
login
to post a comment