-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathapp.js
76 lines (62 loc) · 2.32 KB
/
app.js
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
const sexpress = require('sexpress')
const { createClient } = require('@supabase/supabase-js')
/// BikeTag App specific configuration filters
const onPageDataRequest = function BikeTagPublicData(publicData, appConfig, subdomain) {
const subdomains = Object.keys(appConfig.subdomains)
publicData.supportedRegions = appConfig.supportedRegions
publicData.subdomains = Object.values(appConfig.subdomains).reduce(
(out, subdomainInformation, index) => {
const subdomainName = subdomains[index]
const subdomainConfig = publicData.subdomains[subdomainName] || {}
if (subdomainInformation.imgur) {
subdomainConfig.imgur = subdomainConfig.imgur || {}
subdomainConfig.imgur.imgurClientID = subdomainInformation.imgur.imgurClientID
subdomainConfig.imgur.albumHash = subdomainInformation.imgur.albumHash
subdomainConfig.imgur.imgurAuthorization =
subdomainInformation.imgur.imgurAuthorization
}
out[subdomainName] = subdomainConfig
out[subdomainName] = subdomainInformation
if (subdomain === subdomainName) {
publicData.page = subdomainInformation
}
return out
},
{},
)
return publicData
}
const onLoad = async function onLoad(config) {
if (config.notifications?.enabled) {
console.log('enabling push notifications for new posted BikeTags')
const supabase = createClient('localhost:5555', config.notifications?.gcmApiKey)
app.hook('notifications:subscribe', async (subscription) => {
const { data, error } = await supabase
.from('Players')
.insert([
subscription,
])
return !error ? data : error
})
app.hook('notifications:subscribers', async () => {
const { data, error } = await supabase
.from('Players')
.select()
return !error ? data : error
})
app.hook('notifications:unsubscribe', async (subscription) => {
const { data, error } = await supabase
.from('Players')
.delete()
.match(subscription)
})
app.hook('biketag:newtag', (subscription) => {
app.hook('notifications:notify', {subscription, title: 'A new tag has been played!', message: 'from something'})
})
}
}
const app = sexpress({
onPageDataRequest,
onLoad,
})
app.run()