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-18 19:35:42 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e45dbe17df0c6eb9ac96ed4de3e567d050ae9661
e45dbe17
1 parent
5db87763
비디오 녹화 시간 체크 관련 추가
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
59 deletions
api/migrations/0001_initial.py
api/models.py
api/videorecord.py
api/views.py
api/migrations/0001_initial.py
deleted
100644 → 0
View file @
5db8776
# Generated by Django 3.1.2 on 2020-11-13 10:30
from
django.db
import
migrations
,
models
import
django.utils.timezone
class
Migration
(
migrations
.
Migration
):
initial
=
True
dependencies
=
[
]
operations
=
[
migrations
.
CreateModel
(
name
=
'Device'
,
fields
=
[
(
'rfid_id'
,
models
.
CharField
(
max_length
=
255
,
primary_key
=
True
,
serialize
=
False
)),
(
'created'
,
models
.
DateTimeField
(
default
=
django
.
utils
.
timezone
.
now
)),
],
),
migrations
.
CreateModel
(
name
=
'Door'
,
fields
=
[
(
'door_id'
,
models
.
CharField
(
max_length
=
255
,
primary_key
=
True
,
serialize
=
False
)),
],
),
migrations
.
CreateModel
(
name
=
'History'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'device_name'
,
models
.
CharField
(
max_length
=
255
)),
(
'ctrtime'
,
models
.
DateTimeField
(
default
=
django
.
utils
.
timezone
.
now
)),
],
),
migrations
.
CreateModel
(
name
=
'Lock'
,
fields
=
[
(
'id'
,
models
.
IntegerField
(
primary_key
=
True
,
serialize
=
False
)),
(
'state'
,
models
.
BooleanField
(
default
=
True
)),
],
),
migrations
.
CreateModel
(
name
=
'Record'
,
fields
=
[
(
'id'
,
models
.
IntegerField
(
primary_key
=
True
,
serialize
=
False
)),
(
'recording'
,
models
.
BooleanField
(
default
=
True
)),
],
),
migrations
.
CreateModel
(
name
=
'Video'
,
fields
=
[
(
'vid_name'
,
models
.
CharField
(
max_length
=
255
,
primary_key
=
True
,
serialize
=
False
)),
(
'created'
,
models
.
DateTimeField
(
default
=
django
.
utils
.
timezone
.
now
)),
],
),
]
api/models.py
View file @
e45dbe1
...
...
@@ -13,6 +13,7 @@ class Device(models.Model) :
class
Video
(
models
.
Model
)
:
vid_name
=
models
.
CharField
(
max_length
=
255
,
primary_key
=
True
)
created
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
vid_time
=
models
.
CharField
(
max_length
=
255
)
thumb
=
models
.
CharField
(
max_length
=
255
)
class
Lock
(
models
.
Model
)
:
...
...
api/videorecord.py
View file @
e45dbe1
...
...
@@ -34,10 +34,14 @@ def record() :
# take a video
camera
.
resolution
=
[
320
,
240
]
camera
.
start_preview
()
now
=
datetime
.
datetime
.
now
()
start_time
=
time
.
time
()
vid_name
=
now
.
strftime
(
'
%
Y
%
m
%
d-
%
H
%
M
%
S'
)
vid_path
=
path
+
'/'
+
vid_name
+
'.h264'
thumbnail_path
=
path
+
'/'
+
vid_name
+
'.jpg'
camera
.
start_recording
(
output
=
vid_path
)
time
.
sleep
(
1
)
camera
.
capture
(
thumbnail_path
)
...
...
@@ -47,6 +51,9 @@ def record() :
camera
.
stop_recording
()
camera
.
stop_preview
()
rec_time
=
time
.
time
()
-
start_time
vid_time
=
rec_time
.
strftime
(
"
%
H:
%
M:
%
S"
)
# s3 upload
'''
s3 = boto3.client('s3', region_name = 'ap-northeast-2')
...
...
@@ -56,7 +63,8 @@ def record() :
uploadVideo = {}
uploadVideo['vid_name'] = vid_name
uploadVideo['created'] = now
uploadVideo['thumb'] = 'http://' + S3_STORAGE_BUCKET_NAME + 's3.ap-northeast-2.amazonaws.com/' + vid_name + '_thumb'
uploadVideo['vid_time'] = vid_time
uploadVideo['thumb'] = S3_ACCESS_URL + vid_name + '_thumb'
serializer = VideoSerializer(data = uploadVideo)
serializer.save()
'''
...
...
api/views.py
View file @
e45dbe1
...
...
@@ -64,7 +64,7 @@ class VideoDownload(APIView) :
if
not
download_url
:
raise
ObjectDoesNotExist
res
=
{
's3
_
link'
:
download_url
's3link'
:
download_url
}
# 응답 코드에 보낼 데이터
return
Response
(
res
,
status
=
status
.
HTTP_200_OK
)
except
FieldDoesNotExist
as
error
:
...
...
Please
register
or
login
to post a comment