From ecf4ea58266945da3ab5da3ec1a03f0cb5ed0a81 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 4 Dec 2024 16:45:56 +0000 Subject: [PATCH] Static API typing. --- .../src/api/controllers/static/index.ts | 28 ++++++++++++++----- packages/types/src/api/web/app/index.ts | 1 + packages/types/src/api/web/app/static.ts | 25 +++++++++++++++++ 3 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 packages/types/src/api/web/app/static.ts diff --git a/packages/server/src/api/controllers/static/index.ts b/packages/server/src/api/controllers/static/index.ts index 1bf04e94f0..0dd5e77c50 100644 --- a/packages/server/src/api/controllers/static/index.ts +++ b/packages/server/src/api/controllers/static/index.ts @@ -27,7 +27,13 @@ import { Ctx, DocumentType, Feature, + GetSignedUploadUrlRequest, + GetSignedUploadUrlResponse, ProcessAttachmentResponse, + ServeAppResponse, + ServeBuilderPreviewResponse, + ServeClientLibraryResponse, + ToggleBetaFeatureResponse, UserCtx, } from "@budibase/types" import { @@ -38,7 +44,9 @@ import { import send from "koa-send" import { getThemeVariables } from "../../../constants/themes" -export const toggleBetaUiFeature = async function (ctx: Ctx) { +export const toggleBetaUiFeature = async function ( + ctx: Ctx +) { const cookieName = `beta:${ctx.params.feature}` if (ctx.cookies.get(cookieName)) { @@ -66,13 +74,13 @@ export const toggleBetaUiFeature = async function (ctx: Ctx) { } } -export const serveBuilder = async function (ctx: Ctx) { +export const serveBuilder = async function (ctx: Ctx) { const builderPath = join(TOP_LEVEL_PATH, "builder") await send(ctx, ctx.file, { root: builderPath }) } export const uploadFile = async function ( - ctx: Ctx<{}, ProcessAttachmentResponse> + ctx: Ctx ) { const file = ctx.request?.files?.file if (!file) { @@ -144,7 +152,7 @@ const requiresMigration = async (ctx: Ctx) => { return latestMigrationApplied !== latestMigration } -export const serveApp = async function (ctx: UserCtx) { +export const serveApp = async function (ctx: UserCtx) { if (ctx.url.includes("apple-touch-icon.png")) { ctx.redirect("/builder/bblogo.png") return @@ -249,7 +257,9 @@ export const serveApp = async function (ctx: UserCtx) { } } -export const serveBuilderPreview = async function (ctx: Ctx) { +export const serveBuilderPreview = async function ( + ctx: Ctx +) { const db = context.getAppDB({ skip_setup: true }) const appInfo = await db.get(DocumentType.APP_METADATA) @@ -268,7 +278,9 @@ export const serveBuilderPreview = async function (ctx: Ctx) { } } -export const serveClientLibrary = async function (ctx: Ctx) { +export const serveClientLibrary = async function ( + ctx: Ctx +) { const version = ctx.request.query.version if (Array.isArray(version)) { @@ -297,7 +309,9 @@ export const serveClientLibrary = async function (ctx: Ctx) { } } -export const getSignedUploadURL = async function (ctx: Ctx) { +export const getSignedUploadURL = async function ( + ctx: Ctx +) { // Ensure datasource is valid let datasource try { diff --git a/packages/types/src/api/web/app/index.ts b/packages/types/src/api/web/app/index.ts index 49d888d629..e2f8532dfe 100644 --- a/packages/types/src/api/web/app/index.ts +++ b/packages/types/src/api/web/app/index.ts @@ -18,3 +18,4 @@ export * from "./layout" export * from "./deployment" export * from "./role" export * from "./webhook" +export * from "./static" diff --git a/packages/types/src/api/web/app/static.ts b/packages/types/src/api/web/app/static.ts new file mode 100644 index 0000000000..bcd901d1e1 --- /dev/null +++ b/packages/types/src/api/web/app/static.ts @@ -0,0 +1,25 @@ +import { App } from "../../../documents" +import stream from "node:stream" + +export interface ToggleBetaFeatureResponse { + message: string +} + +export type ServeAppResponse = string + +interface BuilderPreview extends App { + builderPreview: boolean +} + +export type ServeBuilderPreviewResponse = BuilderPreview | string + +export type ServeClientLibraryResponse = stream.Readable + +export interface GetSignedUploadUrlRequest { + bucket: string + key: string +} +export interface GetSignedUploadUrlResponse { + signedUrl?: string + publicUrl?: string +}