diff --git a/app/__test__/_assets/.gitignore b/app/__test__/_assets/.gitignore index e540f5b..22bd3dc 100644 --- a/app/__test__/_assets/.gitignore +++ b/app/__test__/_assets/.gitignore @@ -1 +1,2 @@ -tmp/* \ No newline at end of file +tmp/* +!tmp/.gitkeep \ No newline at end of file diff --git a/app/__test__/_assets/tmp/.gitkeep b/app/__test__/_assets/tmp/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docs/extending/config.mdx b/docs/extending/config.mdx index d174b52..1684467 100644 --- a/docs/extending/config.mdx +++ b/docs/extending/config.mdx @@ -4,7 +4,7 @@ title: bknd.config.ts The central configuration file to extend bknd should be placed in the root of your project, so that the [CLI](/usage/cli#using-configuration-file-bknd-config) can automatically pick it up. It allows to: * define your database connection centrally -* pass in initial configuration or data seeds when booting the first time +* pass in [initial configuration](/usage/database#initial-structure) or [data seeds](/usage/database#seeding-the-database) when booting the first time * add plugins to the app * hook into system events * define custom routes and endpoints diff --git a/docs/modules/media.mdx b/docs/modules/media.mdx index e148a79..209cb42 100644 --- a/docs/modules/media.mdx +++ b/docs/modules/media.mdx @@ -16,3 +16,68 @@ on your environment). The media tools are designed to integrate effortlessly into your workflows, offering scalability and control without added complexity. + +### Pre-built support for S3 + +There are two ways to enable S3 or S3 compatible storage in bknd. + +1. Enable via the admin UI. + + Simply navigate to the **Media** tab of the bknd admin UI and enable the S3 media support. + Enter your AWS S3-compatible storage Access Key, Secret Access Key, and URL. + This will automatically configure the S3 adapter for you. + + **URL Format Examples:** + - **S3**: `https://{bucket}.s3.{region}.amazonaws.com` + - **R2 (Cloudflare)**: `https://{account_id}.r2.cloudflarestorage.com/{bucket}` + +2. Enable programmatically. + + To enable using a code-first approach, create an [Initial Structure](/usage/database#initial-structure) using the `initialConfig` option in your `bknd.config.ts` file. + +```typescript bknd.config.ts +import type { BkndConfig } from "bknd/adapter"; + +export default { + initialConfig: { + media: { + enabled: true, + adapter: { + type: "s3", + config: { + access_key: "", + secret_access_key: "", + url: "" + } + } + } + } +} satisfies BkndConfig; +``` + +### Local adapter for development + +For local development and testing, you can use the local file system adapter. This is particularly useful when working with Node.js environments. + +```typescript bknd.config.ts +import { registerLocalMediaAdapter } from "bknd/adapter/node"; +import type { BkndConfig } from "bknd/adapter"; + +// Register the local media adapter +const local = registerLocalMediaAdapter(); + +export default { + initialConfig: { + media: { + enabled: true, + adapter: local({ + path: "./public/uploads", // Files will be stored in this directory + }), + } + } +} satisfies BkndConfig; +``` + +This configuration will store uploaded files in the specified directory, +making them accessible through your application's public path (in this case) +or at `/api/media/file/{filename}`. diff --git a/docs/usage/introduction.mdx b/docs/usage/introduction.mdx index 11ecb7e..47fc955 100644 --- a/docs/usage/introduction.mdx +++ b/docs/usage/introduction.mdx @@ -78,7 +78,7 @@ see [Custom Connection](/usage/database#custom-connection) as a reference. If the connection object is omitted, the app will try to use an in-memory database. ### `initialConfig` -As initial configuration, you can either pass a partial configuration object or a complete one +As [initial configuration](/usage/database#initial-structure), you can either pass a partial configuration object or a complete one with a version number. The version number is used to automatically migrate the configuration up to the latest version upon boot. The default configuration looks like this: