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-09 14:16:08 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6b5bc5a5b107d89a9d11acb5d8d8a0166ec596c6
6b5bc5a5
1 parent
49facf08
add Video Download API
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
71 additions
and
5 deletions
.aws_key.json
.gitignore
api/serializers.py
api/views.py
requirements.txt
src/settings.py
src/urls.py
.aws_key.json
0 → 100644
View file @
6b5bc5a
{
"aws"
:
{
"access_key_id"
:
"AKIA5ZZ6DPFONI4VDIPH"
,
"secret_access_key"
:
"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"
,
"s3_bucket_name"
:
"khuproject2020"
,
"s3_access_url"
:
"https://khuproject2020.s3.ap-northeast-2.amazonaws.com/"
}
}
\ No newline at end of file
.gitignore
View file @
6b5bc5a
...
...
@@ -4,3 +4,4 @@ __pycache__
db.sqlite3
/static
.DS_Store
.aws_key
...
...
api/serializers.py
View file @
6b5bc5a
from
api.models
import
Phone
,
Video
from
rest_framework
import
serializers
class
PhoneSerializer
(
serializers
.
ModelSerializer
)
:
class
Meta
:
model
=
models
.
Phone
model
=
Phone
fields
=
'__all__'
class
VideoSerializer
(
serializers
.
ModelSerializer
)
:
class
Meta
:
model
=
models
.
Video
model
=
Video
fields
=
'__all__'
...
...
api/views.py
View file @
6b5bc5a
import
boto3
from
django.http
import
HttpResponse
from
django.core
import
serializers
from
django.core.exceptions
import
FieldDoesNotExist
,
ObjectDoesNotExist
from
django.shortcuts
import
render
from
api.models
import
Video
,
Phone
from
api.serializers
import
VideoSerializer
,
PhoneSerializer
from
rest_framework
import
status
from
rest_framework.views
import
APIView
from
rest_framework.request
import
Request
from
rest_framework.response
import
Response
from
boto3.session
import
Session
from
src.settings
import
AWS_REGION
from
src.settings
import
S3_ACCESS_URL
from
datetime
import
datetime
,
timedelta
# Create your views here.
class
VideoDownload
(
APIView
)
:
def
get
(
self
,
request
,
format
=
None
)
:
try
:
request_id
=
request
.
GET
.
get
(
'vidname'
)
if
request_id
==
'None'
:
raise
FieldDoesNotExist
download_url
=
S3_ACCESS_URL
+
str
(
request_id
)
if
not
download_url
:
raise
ObjectDoesNotExist
res
=
{
's3_link'
:
download_url
}
return
Response
(
res
,
status
=
status
.
HTTP_200_OK
)
except
FieldDoesNotExist
as
error
:
return
Response
({
'error'
:
"FieldDoesNotExist "
,
'date'
:
datetime
.
now
()
},
status
=
status
.
HTTP_400_BAD_REQUEST
)
except
ObjectDoesNotExist
as
error
:
return
Response
({
'error'
:
"ObjectDoesNotExist"
,
'date'
:
datetime
.
now
()
},
status
=
status
.
HTTP_404_NOT_FOUND
)
...
...
requirements.txt
View file @
6b5bc5a
D
jango==3.1.2
d
jango==3.1.2
djangorestframework==3.12.1
sqlparse==0.3.1
pytz==2020.1
django-cors-headers==3.5.0
boto3==1.15.15
...
...
src/settings.py
View file @
6b5bc5a
...
...
@@ -9,7 +9,7 @@ https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import
os
import
json
from
pathlib
import
Path
...
...
@@ -123,3 +123,12 @@ USE_TZ = True
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL
=
'/static/'
AWS_REGION
=
'ap-northeast-2'
AWS_SETTINGS
=
os
.
path
.
join
(
BASE_DIR
,
'.aws_key.json'
)
awskey
=
json
.
loads
(
open
(
AWS_SETTINGS
)
.
read
())
S3_ACCESS_KEY_ID
=
awskey
[
'aws'
][
'access_key_id'
]
S3_SECRET_ACCESS_KEY
=
awskey
[
'aws'
][
'secret_access_key'
]
S3_STORAGE_BUCKET_NAME
=
awskey
[
'aws'
][
's3_bucket_name'
]
S3_ACCESS_URL
=
awskey
[
'aws'
][
's3_access_url'
]
...
...
src/urls.py
View file @
6b5bc5a
...
...
@@ -14,8 +14,11 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from
django.contrib
import
admin
from
django.urls
import
path
from
rest_framework
import
routers
from
django.urls
import
path
,
include
from
api
import
views
urlpatterns
=
[
path
(
'admin/'
,
admin
.
site
.
urls
),
path
(
'api/videoDownload/'
,
views
.
VideoDownload
.
as_view
()),
]
...
...
Please
register
or
login
to post a comment