d9033b2636
* wip * wip * wip * client versions init * wip * wip * wip * wip * wip * linting * remove log * comment client version script * lint * skeleton loader type fix * fix types * lint * fix types again * fix manifest not being served locally * remove preinstalled old client version * add constant for dev client version * linting * Dean PR Feedback * linting * pr feedback * wip * wip * clientVersions empty array * delete from git * empty array again * fix tests * pr feedback --------- Co-authored-by: Andrew Kingston <andrew@kingston.dev>
63 lines
2 KiB
TypeScript
63 lines
2 KiB
TypeScript
import Router from "@koa/router"
|
|
import * as controller from "../controllers/static"
|
|
import { budibaseTempDir } from "../../utilities/budibaseDir"
|
|
import authorized from "../../middleware/authorized"
|
|
import { permissions } from "@budibase/backend-core"
|
|
import env from "../../environment"
|
|
import { paramResource } from "../../middleware/resourceId"
|
|
import { devClientLibPath } from "../../utilities/fileSystem"
|
|
|
|
const { BUILDER, PermissionType, PermissionLevel } = permissions
|
|
|
|
const router: Router = new Router()
|
|
|
|
/* istanbul ignore next */
|
|
router.param("file", async (file: any, ctx: any, next: any) => {
|
|
ctx.file = file && file.includes(".") ? file : "index.html"
|
|
if (!ctx.file.startsWith("budibase-client")) {
|
|
return next()
|
|
}
|
|
// test serves from require
|
|
if (env.isTest()) {
|
|
const path = devClientLibPath()
|
|
ctx.devPath = path.split(ctx.file)[0]
|
|
} else if (env.isDev()) {
|
|
// Serving the client library from your local dir in dev
|
|
ctx.devPath = budibaseTempDir()
|
|
}
|
|
return next()
|
|
})
|
|
|
|
router
|
|
.get("/builder/:file*", controller.serveBuilder)
|
|
.get("/api/assets/client", controller.serveClientLibrary)
|
|
.post("/api/attachments/process", authorized(BUILDER), controller.uploadFile)
|
|
.post(
|
|
"/api/attachments/delete",
|
|
authorized(BUILDER),
|
|
controller.deleteObjects
|
|
)
|
|
.post("/api/beta/:feature", controller.toggleBetaUiFeature)
|
|
.post(
|
|
"/api/attachments/:tableId/upload",
|
|
paramResource("tableId"),
|
|
authorized(PermissionType.TABLE, PermissionLevel.WRITE),
|
|
controller.uploadFile
|
|
)
|
|
.post(
|
|
"/api/attachments/:tableId/delete",
|
|
paramResource("tableId"),
|
|
authorized(PermissionType.TABLE, PermissionLevel.WRITE),
|
|
controller.deleteObjects
|
|
)
|
|
.get("/app/preview", authorized(BUILDER), controller.serveBuilderPreview)
|
|
.get("/app/:appUrl/:path*", controller.serveApp)
|
|
.get("/:appId/:path*", controller.serveApp)
|
|
.post(
|
|
"/api/attachments/:datasourceId/url",
|
|
authorized(PermissionType.TABLE, PermissionLevel.READ),
|
|
controller.getSignedUploadURL
|
|
)
|
|
|
|
export default router
|