Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
T
Taiko Web
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
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
nanahira
Taiko Web
Commits
fe90a356
Commit
fe90a356
authored
Mar 17, 2020
by
Bui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
generate hashes on server
parent
5a68978e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
5 deletions
+54
-5
app.py
app.py
+37
-1
config.example.py
config.example.py
+4
-1
public/src/css/admin.css
public/src/css/admin.css
+4
-0
templates/admin.html
templates/admin.html
+1
-1
templates/admin_song_detail.html
templates/admin_song_detail.html
+8
-2
No files found.
app.py
View file @
fe90a356
#!/usr/bin/env python3
#!/usr/bin/env python3
import
base64
import
bcrypt
import
bcrypt
import
hashlib
import
config
import
config
import
json
import
json
import
re
import
re
import
requests
import
schema
import
schema
import
os
import
os
...
@@ -28,10 +31,34 @@ db = client[config.MONGO['database']]
...
@@ -28,10 +31,34 @@ db = client[config.MONGO['database']]
db
.
users
.
create_index
(
'username'
,
unique
=
True
)
db
.
users
.
create_index
(
'username'
,
unique
=
True
)
db
.
songs
.
create_index
(
'id'
,
unique
=
True
)
db
.
songs
.
create_index
(
'id'
,
unique
=
True
)
class
HashException
(
Exception
):
pass
def
api_error
(
message
):
def
api_error
(
message
):
return
jsonify
({
'status'
:
'error'
,
'message'
:
message
})
return
jsonify
({
'status'
:
'error'
,
'message'
:
message
})
def
generate_hash
(
id
,
form
):
md5
=
hashlib
.
md5
()
if
form
[
'type'
]
==
'tja'
:
urls
=
[
'
%
s
%
s/main.tja'
%
(
config
.
SONGS_BASEURL
,
id
)]
else
:
urls
=
[]
for
diff
in
[
'easy'
,
'normal'
,
'hard'
,
'oni'
,
'ura'
]:
if
form
[
'course_'
+
diff
]:
urls
.
append
(
'
%
s
%
s/
%
s.osu'
%
(
config
.
SONGS_BASEURL
,
id
,
diff
))
for
url
in
urls
:
resp
=
requests
.
get
(
url
)
if
resp
.
status_code
!=
200
:
raise
Exception
(
'Invalid response from
%
s (status code
%
s)'
%
(
resp
.
url
,
resp
.
status_code
))
md5
.
update
(
resp
.
content
)
return
base64
.
b64encode
(
md5
.
digest
())[:
-
2
]
.
decode
(
'utf-8'
)
def
login_required
(
f
):
def
login_required
(
f
):
@
wraps
(
f
)
@
wraps
(
f
)
def
decorated_function
(
*
args
,
**
kwargs
):
def
decorated_function
(
*
args
,
**
kwargs
):
...
@@ -69,7 +96,8 @@ def get_config():
...
@@ -69,7 +96,8 @@ def get_config():
'songs_baseurl'
:
config
.
SONGS_BASEURL
,
'songs_baseurl'
:
config
.
SONGS_BASEURL
,
'assets_baseurl'
:
config
.
ASSETS_BASEURL
,
'assets_baseurl'
:
config
.
ASSETS_BASEURL
,
'email'
:
config
.
EMAIL
,
'email'
:
config
.
EMAIL
,
'accounts'
:
config
.
ACCOUNTS
'accounts'
:
config
.
ACCOUNTS
,
'custom_js'
:
config
.
CUSTOM_JS
}
}
if
not
config_out
.
get
(
'songs_baseurl'
):
if
not
config_out
.
get
(
'songs_baseurl'
):
...
@@ -218,6 +246,14 @@ def route_admin_songs_id_post(id):
...
@@ -218,6 +246,14 @@ def route_admin_songs_id_post(id):
output
[
'preview'
]
=
float
(
request
.
form
.
get
(
'preview'
))
or
None
output
[
'preview'
]
=
float
(
request
.
form
.
get
(
'preview'
))
or
None
output
[
'volume'
]
=
float
(
request
.
form
.
get
(
'volume'
))
or
None
output
[
'volume'
]
=
float
(
request
.
form
.
get
(
'volume'
))
or
None
output
[
'maker_id'
]
=
int
(
request
.
form
.
get
(
'maker_id'
))
or
None
output
[
'maker_id'
]
=
int
(
request
.
form
.
get
(
'maker_id'
))
or
None
output
[
'hash'
]
=
request
.
form
.
get
(
'hash'
)
if
request
.
form
.
get
(
'gen_hash'
):
try
:
output
[
'hash'
]
=
generate_hash
(
id
,
request
.
form
)
except
HashException
as
e
:
flash
(
'An error occurred:
%
s'
%
str
(
e
),
'error'
)
return
redirect
(
'/admin/songs/
%
s'
%
id
)
db
.
songs
.
update_one
({
'id'
:
id
},
{
'$set'
:
output
})
db
.
songs
.
update_one
({
'id'
:
id
},
{
'$set'
:
output
})
flash
(
'Changes saved.'
)
flash
(
'Changes saved.'
)
...
...
config.example.py
View file @
fe90a356
...
@@ -10,9 +10,12 @@ EMAIL = 'taiko@example.com'
...
@@ -10,9 +10,12 @@ EMAIL = 'taiko@example.com'
# Whether to use the user account system.
# Whether to use the user account system.
ACCOUNTS
=
True
ACCOUNTS
=
True
# Custom JavaScript file to load with the simulator.
CUSTOM_JS
=
''
# MongoDB server settings.
# MongoDB server settings.
MONGO
=
{
MONGO
=
{
'host'
:
[
'
localhost
:27017'
],
'host'
:
[
'
127.0.0.1
:27017'
],
'database'
:
'taiko'
'database'
:
'taiko'
}
}
...
...
public/src/css/admin.css
View file @
fe90a356
...
@@ -131,6 +131,10 @@ h1 small {
...
@@ -131,6 +131,10 @@ h1 small {
color
:
white
;
color
:
white
;
}
}
.message-error
{
background
:
#b92222
;
}
.save-song
{
.save-song
{
font-size
:
22pt
;
font-size
:
22pt
;
width
:
120px
;
width
:
120px
;
...
...
templates/admin.html
View file @
fe90a356
...
@@ -13,7 +13,7 @@
...
@@ -13,7 +13,7 @@
<a
href=
"/admin/songs"
>
Songs
</a>
<a
href=
"/admin/songs"
>
Songs
</a>
</div>
</div>
</header>
</header>
<main>
<main>
<div
class=
"container"
>
<div
class=
"container"
>
{% block content %}{% endblock %}
{% block content %}{% endblock %}
...
...
templates/admin_song_detail.html
View file @
fe90a356
{% extends 'admin.html' %}
{% extends 'admin.html' %}
{% block content %}
{% block content %}
<h1>
{{ song.title }}
<small>
(ID: {{ song.id }})
</small></h1>
<h1>
{{ song.title }}
<small>
(ID: {{ song.id }})
</small></h1>
{% for
message in get_flashed_messages(
) %}
{% for
cat, message in get_flashed_messages(with_categories=true
) %}
<div
class=
"message"
>
{{ message }}
</div>
<div
class=
"message
{% if cat %} message-{{cat}}{% endif %}
"
>
{{ message }}
</div>
{% endfor %}
{% endfor %}
<div
class=
"song-form"
>
<div
class=
"song-form"
>
<form
method=
"post"
>
<form
method=
"post"
>
...
@@ -115,6 +115,11 @@
...
@@ -115,6 +115,11 @@
</select>
</select>
</div>
</div>
<div
class=
"form-field"
>
<p><label
for=
"hash"
>
Hash
</label></p>
<input
type=
"text"
id=
"hash"
value=
"{{song.hash}}"
name=
"hash"
>
<span
class=
"checkbox"
><input
type=
"checkbox"
name=
"gen_hash"
id=
"gen_hash"
{
><label
for=
"gen_hash"
>
Generate
</label></span>
</div>
<button
type=
"submit"
class=
"save-song"
>
Save
</button>
<button
type=
"submit"
class=
"save-song"
>
Save
</button>
</form>
</form>
{% if admin.user_level >= 100 %}
{% if admin.user_level >= 100 %}
...
@@ -124,3 +129,4 @@
...
@@ -124,3 +129,4 @@
{% endif %}
{% endif %}
</div>
</div>
{% endblock %}
{% endblock %}
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