Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
minor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Christian Knuchel
minor
Commits
b8734348
Commit
b8734348
authored
Jan 18, 2019
by
Fence
🌈
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add config stuff
parent
53879a93
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
11 additions
and
23 deletions
+11
-23
local.py
local.py
+1
-1
minor.wsgi
minor.wsgi
+2
-1
minor/app.py
minor/app.py
+3
-5
minor/controller/api.py
minor/controller/api.py
+0
-13
minor/controller/music.py
minor/controller/music.py
+5
-3
No files found.
local.py
View file @
b8734348
from
minor
import
App
from
minor
import
App
app
=
App
()
app
=
App
(
{
"UPLOAD_DIR"
:
"./upload"
}
)
app
.
run
()
app
.
run
()
\ No newline at end of file
minor.wsgi
View file @
b8734348
from minor import App
from minor import App
app = App()
# change upload dir!
app = App({"UPLOAD_DIR": "./upload"})
application = app.get_application()
application = app.get_application()
\ No newline at end of file
minor/app.py
View file @
b8734348
...
@@ -3,21 +3,19 @@ from minor.controller import ApiController, MusicController
...
@@ -3,21 +3,19 @@ from minor.controller import ApiController, MusicController
class
App
(
object
):
class
App
(
object
):
def
__init__
(
self
):
def
__init__
(
self
,
config
):
self
.
_flask
=
Flask
(
__name__
)
self
.
_flask
=
Flask
(
__name__
)
self
.
_flask
.
config
[
'MONGODB_SETTINGS'
]
=
{
'db'
:
'minor'
}
self
.
_flask
.
config
[
'MONGODB_SETTINGS'
]
=
{
'db'
:
'minor'
}
self
.
_flask
.
config
.
update
(
config
)
from
minor.model
import
db
from
minor.model
import
db
db
.
init_app
(
self
.
_flask
)
db
.
init_app
(
self
.
_flask
)
ApiController
(
self
).
register
(
self
.
_flask
)
ApiController
(
self
).
register
(
self
.
_flask
)
MusicController
().
register
(
self
.
_flask
)
MusicController
(
self
.
_flask
.
config
[
"UPLOAD_DIR"
]
).
register
(
self
.
_flask
)
def
run
(
self
):
def
run
(
self
):
self
.
_flask
.
run
()
self
.
_flask
.
run
()
def
check_key
(
self
,
key
):
return
key
==
"sekrit1234"
def
get_application
(
self
):
def
get_application
(
self
):
return
self
.
_flask
return
self
.
_flask
minor/controller/api.py
View file @
b8734348
...
@@ -19,16 +19,3 @@ class ApiController(FlaskController):
...
@@ -19,16 +19,3 @@ class ApiController(FlaskController):
@
route
(
"/ping"
)
@
route
(
"/ping"
)
def
ping
(
self
):
def
ping
(
self
):
return
"pong"
return
"pong"
@
json_required
@
route
(
"/register"
,
methods
=
[
"POST"
])
def
register_major
(
self
):
json
=
request
.
get_json
()
if
"key"
in
json
:
if
self
.
_app
.
check_key
(
json
[
"key"
]):
# add the instance the the trusted list
new_instance
=
MajorInstance
(
issuer
=
json
[
"issuer"
],
url
=
json
[
"url"
])
new_instance
.
save
()
return
jsonify
({
"code"
:
200
,
"message"
:
"ok"
}),
200
return
jsonify
({
"code"
:
400
,
"message"
:
"bad_request"
}),
400
minor/controller/music.py
View file @
b8734348
...
@@ -12,6 +12,8 @@ from minor.util import get_ext
...
@@ -12,6 +12,8 @@ from minor.util import get_ext
@
route
(
"/api/music"
)
@
route
(
"/api/music"
)
class
MusicController
(
FlaskController
):
class
MusicController
(
FlaskController
):
def
__init__
(
self
,
upload_dir
):
self
.
_upload_dir
=
upload_dir
@
auth_required
@
auth_required
@
route
(
"/listen"
)
@
route
(
"/listen"
)
...
@@ -19,7 +21,7 @@ class MusicController(FlaskController):
...
@@ -19,7 +21,7 @@ class MusicController(FlaskController):
if
"song"
in
payload
:
if
"song"
in
payload
:
song
=
Song
.
objects
.
get
(
id
=
payload
[
"song"
])
song
=
Song
.
objects
.
get
(
id
=
payload
[
"song"
])
if
song
is
not
None
:
if
song
is
not
None
:
filename
=
"./uploads/"
+
str
(
song
.
id
)
+
".mp3"
filename
=
self
.
_upload_dir
+
str
(
song
.
id
)
+
".mp3"
if
os
.
path
.
isfile
(
filename
):
if
os
.
path
.
isfile
(
filename
):
def
generate
():
def
generate
():
with
open
(
filename
,
"rb"
)
as
fogg
:
with
open
(
filename
,
"rb"
)
as
fogg
:
...
@@ -45,7 +47,7 @@ class MusicController(FlaskController):
...
@@ -45,7 +47,7 @@ class MusicController(FlaskController):
def
song_has_file
(
self
,
id
,
payload
=
None
):
def
song_has_file
(
self
,
id
,
payload
=
None
):
song
=
Song
.
objects
.
get
(
id
=
id
)
song
=
Song
.
objects
.
get
(
id
=
id
)
if
song
is
not
None
:
if
song
is
not
None
:
filename
=
"./uploads/"
+
str
(
song
.
id
)
+
".mp3"
filename
=
self
.
_upload_dir
+
str
(
song
.
id
)
+
".mp3"
if
os
.
path
.
isfile
(
filename
):
if
os
.
path
.
isfile
(
filename
):
return
jsonify
({
"code"
:
200
,
"message"
:
"ok"
,
"data"
:
True
}),
200
return
jsonify
({
"code"
:
200
,
"message"
:
"ok"
,
"data"
:
True
}),
200
else
:
else
:
...
@@ -90,7 +92,7 @@ class MusicController(FlaskController):
...
@@ -90,7 +92,7 @@ class MusicController(FlaskController):
ext
=
get_ext
(
file
.
filename
)
ext
=
get_ext
(
file
.
filename
)
if
ext
is
not
None
:
if
ext
is
not
None
:
name
=
secure_filename
(
str
(
db_song
.
id
)
+
"."
+
ext
)
name
=
secure_filename
(
str
(
db_song
.
id
)
+
"."
+
ext
)
path
=
os
.
path
.
join
(
"./uploads"
,
name
)
path
=
os
.
path
.
join
(
self
.
_upload_dir
,
name
)
file
.
save
(
path
)
file
.
save
(
path
)
return
jsonify
({
"code"
:
200
,
"message"
:
"ok"
}),
200
return
jsonify
({
"code"
:
200
,
"message"
:
"ok"
}),
200
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment