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-11-21 11:58:16 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
7589f5dbf83ac982cb5b8f87392886ca86be1c55
7589f5db
1 parent
b4d7dfbf
Bug Fix
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
api/views.py
videorecord.py
api/views.py
View file @
7589f5d
...
...
@@ -7,7 +7,6 @@ from django.core.exceptions import FieldDoesNotExist, ObjectDoesNotExist
from
django.shortcuts
import
render
from
django.contrib.auth.models
import
User
from
api.videorecord
import
record
from
api.models
import
Video
,
Device
,
RemoteHistory
,
Lock
,
Record
,
Door
,
AddDevice
from
api.serializers
import
VideoSerializer
,
DeviceSerializer
,
RemoteHistorySerializer
,
RecordSerializer
,
LockSerializer
,
AddDeviceSerializer
...
...
@@ -160,7 +159,7 @@ class Remote(APIView):
return
Response
(
res
,
status
=
status
.
HTTP_200_OK
)
# 원격 잠금 해제
def
p
os
t
(
self
,
request
,
format
=
None
)
:
def
p
u
t
(
self
,
request
,
format
=
None
)
:
try
:
print
(
request
.
body
)
data
=
json
.
loads
(
request
.
body
)
...
...
@@ -211,7 +210,8 @@ class VideoList(APIView) :
s3
=
session
.
client
(
's3'
)
target
=
Video
.
objects
.
get
(
vid_name
=
request_id
)
s3
.
delete_object
(
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
str
(
target
.
vid_name
))
s3
.
delete_object
(
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
str
(
target
.
vid_name
)
+
'.mp4'
)
s3
.
delete_object
(
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
str
(
target
.
vid_name
)
+
'_thumb.jpg'
)
target
.
delete
()
return
Response
(
status
=
status
.
HTTP_200_OK
)
except
FieldDoesNotExist
as
error
:
...
...
@@ -227,7 +227,7 @@ class VideoDownload(APIView) :
request_id
=
vid_name
if
request_id
==
'None'
:
raise
FieldDoesNotExist
download_url
=
S3_ACCESS_URL
+
str
(
request_id
)
# S3 다운로드 링크 변환
download_url
=
S3_ACCESS_URL
+
str
(
request_id
)
+
'.mp4'
# S3 다운로드 링크 변환
if
not
download_url
:
raise
ObjectDoesNotExist
res
=
{
...
...
@@ -253,7 +253,7 @@ class CheckDate(APIView) :
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
.
vid_name
))
s3
.
delete_object
(
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
str
(
delvid
.
vid_name
)
+
'.mp4'
)
quaryset
.
delete
()
return
Response
(
status
=
status
.
HTTP_200_OK
)
...
...
videorecord.py
View file @
7589f5d
...
...
@@ -83,14 +83,14 @@ def record() :
else
:
ACCESS_KEY
,
SECRET_KEY
=
secret
s3
=
boto3
.
client
(
's3'
,
region_name
=
'ap-northeast-2'
,
aws_access_key_id
=
ACCESS_KEY
,
aws_secret_access_key
=
SECRET_KEY
)
s3
.
upload_file
(
Filename
=
vid_path
,
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
vid_name
)
s3
.
upload_file
(
Filename
=
thumbnail_path
,
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
vid_name
+
'_thumb'
)
s3
.
upload_file
(
Filename
=
vid_path
,
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
vid_name
+
'.mp4'
)
s3
.
upload_file
(
Filename
=
thumbnail_path
,
Bucket
=
S3_STORAGE_BUCKET_NAME
,
Key
=
vid_name
+
'_thumb
.jpg
'
)
uploadVideo
=
{}
uploadVideo
[
'vid_name'
]
=
vid_name
uploadVideo
[
'created'
]
=
now
uploadVideo
[
'vid_time'
]
=
vid_time
uploadVideo
[
'thumb'
]
=
S3_ACCESS_URL
+
vid_name
+
'_thumb'
uploadVideo
[
'thumb'
]
=
S3_ACCESS_URL
+
vid_name
+
'_thumb
.jpg
'
serializer
=
VideoSerializer
(
data
=
uploadVideo
)
serializer
.
is_valid
()
serializer
.
save
()
...
...
Please
register
or
login
to post a comment