1
0
Fork 0
mirror of synced 2024-06-21 11:51:00 +12:00
budibase/packages/server/src/api/controllers/analytics.ts

36 lines
992 B
TypeScript
Raw Normal View History

import { events } from "@budibase/backend-core"
2022-08-10 22:01:54 +12:00
import { AnalyticsPingRequest, PingSource } from "@budibase/types"
import { DocumentType, isDevAppID } from "../../db/utils"
2022-08-10 22:01:54 +12:00
import { context } from "@budibase/backend-core"
export const isEnabled = async (ctx: any) => {
2022-06-01 08:04:41 +12:00
const enabled = await events.analytics.enabled()
ctx.body = {
2022-06-01 08:04:41 +12:00
enabled,
}
}
2022-08-10 22:01:54 +12:00
export const ping = async (ctx: any) => {
const body = ctx.request.body as AnalyticsPingRequest
switch (body.source) {
case PingSource.APP: {
const db = context.getAppDB({ skip_setup: true })
const appInfo = await db.get(DocumentType.APP_METADATA)
2022-08-10 22:01:54 +12:00
let appId = context.getAppId()
if (isDevAppID(appId)) {
2022-08-10 22:29:11 +12:00
await events.serve.servedAppPreview(appInfo, body.timezone)
2022-08-10 22:01:54 +12:00
} else {
2022-08-10 22:29:11 +12:00
await events.serve.servedApp(appInfo, body.timezone)
2022-08-10 22:01:54 +12:00
}
break
}
case PingSource.BUILDER: {
2022-08-10 22:29:11 +12:00
await events.serve.servedBuilder(body.timezone)
2022-08-10 22:01:54 +12:00
break
}
}
ctx.status = 200
}