2022-03-22 13:23:22 +13:00
|
|
|
import Router from "@koa/router"
|
2022-03-20 14:13:54 +13:00
|
|
|
import * as controller from "../controllers/static"
|
|
|
|
import { budibaseTempDir } from "../../utilities/budibaseDir"
|
|
|
|
import authorized from "../../middleware/authorized"
|
|
|
|
import {
|
2021-04-02 02:38:31 +13:00
|
|
|
BUILDER,
|
|
|
|
PermissionTypes,
|
|
|
|
PermissionLevels,
|
2022-03-20 14:13:54 +13:00
|
|
|
} from "@budibase/backend-core/permissions"
|
|
|
|
import * as env from "../../environment"
|
|
|
|
import { paramResource } from "../../middleware/resourceId"
|
2020-04-15 02:14:57 +12:00
|
|
|
|
2022-03-22 13:23:22 +13:00
|
|
|
const router = new Router()
|
2020-04-15 02:14:57 +12:00
|
|
|
|
2021-03-11 06:55:42 +13:00
|
|
|
/* istanbul ignore next */
|
2022-03-22 13:23:22 +13:00
|
|
|
router.param("file", async (file: any, ctx: any, next: any) => {
|
2020-05-18 17:40:29 +12:00
|
|
|
ctx.file = file && file.includes(".") ? file : "index.html"
|
2021-03-26 05:08:09 +13:00
|
|
|
if (!ctx.file.startsWith("budibase-client")) {
|
|
|
|
return next()
|
|
|
|
}
|
|
|
|
// test serves from require
|
|
|
|
if (env.isTest()) {
|
|
|
|
ctx.devPath = require.resolve("@budibase/client").split(ctx.file)[0]
|
|
|
|
} else if (env.isDev()) {
|
|
|
|
// Serving the client library from your local dir in dev
|
2020-05-18 17:40:29 +12:00
|
|
|
ctx.devPath = budibaseTempDir()
|
|
|
|
}
|
2021-03-26 05:08:09 +13:00
|
|
|
return next()
|
2020-05-18 17:40:29 +12:00
|
|
|
})
|
2020-05-06 23:17:15 +12:00
|
|
|
|
2021-04-02 02:11:58 +13:00
|
|
|
// only used in development for retrieving the client library,
|
|
|
|
// in production the client lib is always stored in the object store.
|
2021-04-02 00:48:38 +13:00
|
|
|
if (env.isDev()) {
|
2021-04-02 02:11:58 +13:00
|
|
|
router.get("/api/assets/client", controller.serveClientLibrary)
|
2021-04-02 00:48:38 +13:00
|
|
|
}
|
|
|
|
|
2020-05-18 17:40:29 +12:00
|
|
|
router
|
2021-04-01 07:55:55 +13:00
|
|
|
// TODO: for now this builder endpoint is not authorized/secured, will need to be
|
|
|
|
.get("/builder/:file*", controller.serveBuilder)
|
2021-03-16 01:10:21 +13:00
|
|
|
.post("/api/attachments/process", authorized(BUILDER), controller.uploadFile)
|
2022-08-16 02:46:55 +12:00
|
|
|
.post(
|
|
|
|
"/api/attachments/delete",
|
|
|
|
authorized(BUILDER),
|
|
|
|
controller.deleteObjects
|
|
|
|
)
|
2022-06-07 10:30:36 +12:00
|
|
|
.post("/api/beta/:feature", controller.toggleBetaUiFeature)
|
2021-04-02 02:38:31 +13:00
|
|
|
.post(
|
2021-06-08 23:50:58 +12:00
|
|
|
"/api/attachments/:tableId/upload",
|
|
|
|
paramResource("tableId"),
|
2021-04-02 02:38:31 +13:00
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.WRITE),
|
|
|
|
controller.uploadFile
|
|
|
|
)
|
2022-08-12 22:29:57 +12:00
|
|
|
.post(
|
|
|
|
"/api/attachments/:tableId/delete",
|
|
|
|
paramResource("tableId"),
|
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.WRITE),
|
|
|
|
controller.deleteObjects
|
|
|
|
)
|
2020-06-13 07:42:55 +12:00
|
|
|
.get("/:appId/:path*", controller.serveApp)
|
2022-03-24 05:45:06 +13:00
|
|
|
.get("/app/:appUrl/:path*", controller.serveApp)
|
2022-01-14 06:18:24 +13:00
|
|
|
.post(
|
|
|
|
"/api/attachments/:datasourceId/url",
|
|
|
|
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
|
|
|
controller.getSignedUploadURL
|
|
|
|
)
|
2020-04-15 02:14:57 +12:00
|
|
|
|
2022-03-20 14:13:54 +13:00
|
|
|
export default router
|