forked from Considerit/considerit-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve_nested.coffee
166 lines (118 loc) · 4.43 KB
/
serve_nested.coffee
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
local = false
port = 3006
global.upload_dir = 'static/uploads/'
require('dotenv').config
path: 'confs/consideritus.env'
slidergram_client_handlers = require('./server/slidergrams.coffee')
require './server/email'
auth_server = require './server/auth_server'
bus = require('statebus').serve({
port: port
file_store:
filename: 'db/nested'
backup_dir: 'db/backups/nested'
certs: if !local then {
private_key: 'certs/considerit-us/private-key'
certificate: 'certs/considerit-us/certificate'
}
client: (client) ->
slidergram_client_handlers(bus, client)
auth_server(bus, client)
client('point/*').to_delete = (key, t) ->
pnt = bus.fetch key
for sel in (pnt.selections or [])
bus.delete deslash(sel)
# delete children
for child in (pnt.children or [])
bus.delete deslash(child)
if pnt.parent
parent = bus.fetch(deslash(pnt.parent))
i = parent.children.findIndex (p) -> pnt.key == deslash(p)
if i > -1
parent.children.splice(i, 1)
bus.save(parent)
bus.delete key
t.done()
client.shadows(bus)
})
deslash = (key) ->
if key?[0] == '/'
key = key.substr(1)
else
key
for k,v of bus.cache
if k.match 'user/'
if v.pic?.match 'uploads'
v.pic = v.pic.replace('uploads', 'static')
bus.honk = false
express = require('express')
bus.http.use('/static', express.static('static'))
bus.http.use('/node_modules', express.static('node_modules'))
# get an index of all nested point lists
bus.http.get '/all', (r,res) =>
html = """
<script>
document.title = 'All Nested Docs'
</script>
<ul>"""
for k,v of bus.cache
if k.match '_root'
console.log v, v.children?[0], bus.cache[v.children?[0]]
if v.children?.length > 0 && (v.text && v.text != '' || v.children.length > 1 || bus.cache[deslash(v.children[0])].children?.length > 0)
forum = k.split('_')[0]
html += "<li><a target='_blank' href='#{forum}'>#{forum}</a></li>"
html += '</ul>'
res.send(html)
# server everything else as a named forum
bus.http.get '/*', (r,res) =>
local = r.host.indexOf('localhost') > -1
if local
prefix = ''
server = "statei://localhost:#{port}"
else
prefix = "https://considerit.us:#{port}"
server = "state://considerit.us:#{port}"
forum = r.url.split('/')[1]
html = """
<script type="coffeedom">
bus.honk = false
window.forum = "#{forum}"
#</script><script src="/node_modules/statebus/client.js" server="state://#{r.host}:#{port}"></script>
<script src="#{prefix}/client/fickle.coffee"></script>
<script src="#{prefix}/client/shared.coffee"></script>
<script src="#{prefix}/client/avatar.coffee" default-path="#{prefix}/static/uploads"></script>
<script src="#{prefix}/client/earl.coffee" history-aware-links root="#{forum}"></script>
<script src="#{prefix}/client/tooltips.coffee"></script>
<script src="#{prefix}/client/slidergrams.coffee"></script>
<script src="#{prefix}/client/state_dash.coffee"></script>
<script src="#{prefix}/client/auth.coffee"></script>
<script src="#{prefix}/client/presence.coffee"></script>
<script src="/client/discussion-nested.coffee"></script>
<script src="/client/app_nested.coffee"></script>
<script src="#{prefix}/static/vendor/md5.js"></script>
<script src="#{prefix}/static/vendor/d3.quadtree.js"></script>
<script src="#{prefix}/static/vendor/emojione.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-55365750-3', 'auto');
ga('send', 'pageview');
</script>
<script>
document.title = \"#{r.url.split('/')[1]}\"
</script>
"""
res.send(html)
migrate_data = ->
migrate = bus.fetch('migrations')
if !migrate.make_login_email
console.warn 'MIGRATING to email login!'
for key, usr of bus.cache
if key.match('user/') && key.split('/').length == 2 && usr.email
usr.login = usr.email
bus.save usr
migrate.make_login_email = true
bus.save migrate
migrate_data()