-
-
Notifications
You must be signed in to change notification settings - Fork 80
/
app.moon
108 lines (76 loc) · 2.3 KB
/
app.moon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
lapis = require "lapis"
import assert_error from require "lapis.application"
import set_csrf from require "helpers.csrf"
import get, post, multi from require "helpers.app"
date = require "date"
class extends lapis.Application
@include "applications.admin"
layout: require "views.layout"
cookie_attributes: =>
expires = date(true)\adddays(365)\fmt "${http}"
attr = "Expires=#{expires}; Path=/; HttpOnly"
attr
@before_filter =>
import Users from require "models"
set_csrf @
@current_user = Users\read_session @
if @current_user
@current_user\update_last_active!
"/test": =>
"hello world", layout: "test_layout"
[song: "/song/:song_id/:slug"]: =>
[play_along: "/play-along"]: =>
"/(*)": =>
"/logout.json": post =>
@flow("login")\do_logout!
json: { success: true }
"/login.json": post =>
@flow("login")\do_login!
json: @flow("formatter")\session!
"/register.json": post =>
@flow("login")\do_register!
json: @flow("formatter")\session!
"/hits.json": post =>
@flow("hits")\register_hits!
json: { success: true }
"/stats.json": get =>
assert_error @current_user, "must be logged in"
stats = @flow("hits")\get_stats {
offset: @params.offset
}
stats = nil unless next stats
json: { success: true, :stats }
"/presets.json": get =>
assert_error @current_user, "must be logged in"
@flow("presets")\list_presets!
"/new-preset.json": post =>
@flow("presets")\create_preset!
"/songs.json": multi {
get: =>
switch @params.filter
when "played"
@flow("songs")\list_played_songs!
else
@flow("songs")\list_songs!
post: =>
assert_error @current_user, "must be logged in"
@flow("songs")\create_song!
}
"/songs/:song_id.lml": =>
song = @flow("songs")\find_song!
song.song, layout: false
"/songs/:song_id.json": multi {
get: =>
@flow("songs")\get_song!
delete: =>
assert_error @current_user, "must be logged in"
@flow("songs")\delete_song!
post: =>
assert_error @current_user, "must be logged in"
@flow("songs")\update_song!
}
"/songs/:song_id/stats.json": multi {
post: =>
assert_error @current_user, "must be logged in"
@flow("songs")\update_song_user_time!
}