Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions src/content/docs/es/storage-api/api-endpoint.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
---
i18nReady: true
title: API Endpoint
description: Learn about the API endpoints available in the StudioCMS Storage API.
Comment on lines +2 to +4
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Content is not translated — i18nReady: true is premature.

Same as the other ES files: all prose remains in English. Set i18nReady: false until the page body is actually translated into Spanish.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/content/docs/es/storage-api/api-endpoint.mdx` around lines 2 - 4, The
frontmatter currently sets i18nReady: true while the document body is still
English; change the frontmatter key i18nReady from true to false (i18nReady:
false) for this page (the block containing title: API Endpoint and description)
so the page is not marked as translated until the Spanish content is completed.

tableOfContents:
minHeadingLevel: 2
maxHeadingLevel: 4
sidebar:
order: 3
badge:
text: NEW
variant: success
---

import ReadMore from '~/components/ReadMore.astro';
import { Aside } from '@astrojs/starlight/components';

The Storage API exposes endpoints that can be accessed via HTTP requests. The following sections describe the available endpoints and their usage.

<Aside type="note" title="Uses locals for Authorization">
The Storage API endpoints make use of the Astro `locals` feature propagated by Middleware to handle authorization. Ensure that the browser or client making the requests is coming from a logged-in StudioCMS user with the appropriate permissions to perform storage operations.
</Aside>

### Method: PUT

To upload or update a file in the storage system, you can use the `PUT` method on the `/studiocms_api/storage/manager` endpoint.

```http title="Storage API - PUT /studiocms_api/storage/manager"
PUT /studiocms_api/storage/manager HTTP/1.1
Host: example.com
Content-Type: application/octet-stream
Accept: application/json
Headers:
x-storage-key: my-file.txt

<file-content>
```
Comment on lines +28 to +37
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Invalid HTTP syntax in the PUT request example.

The Headers: label with an indented x-storage-key on the next line is not valid HTTP wire format. Headers in an HTTP request are written as flat Key: Value lines, not under a Headers: section prefix. As written, this may confuse readers and is technically incorrect documentation.

🐛 Proposed fix
 PUT /studiocms_api/storage/manager HTTP/1.1
 Host: example.com
 Content-Type: application/octet-stream
 Accept: application/json
-Headers:
-  x-storage-key: my-file.txt
+x-storage-key: my-file.txt
 
 <file-content>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
```http title="Storage API - PUT /studiocms_api/storage/manager"
PUT /studiocms_api/storage/manager HTTP/1.1
Host: example.com
Content-Type: application/octet-stream
Accept: application/json
Headers:
x-storage-key: my-file.txt
<file-content>
```
PUT /studiocms_api/storage/manager HTTP/1.1
Host: example.com
Content-Type: application/octet-stream
Accept: application/json
x-storage-key: my-file.txt
<file-content>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/content/docs/es/storage-api/api-endpoint.mdx` around lines 28 - 37, The
HTTP example block contains an invalid "Headers:" label and an indented header
line; update the PUT example in the code block (Storage API - PUT
/studiocms_api/storage/manager) to use proper HTTP wire format by removing the
"Headers:" prefix and placing the header as a top-level header line (e.g.,
"x-storage-key: my-file.txt") alongside other headers like Host, Content-Type,
and Accept so each header is "Key: Value" on its own line.


#### Successful Response

```http title="Storage API - PUT Success Response"
HTTP/1.1 200 OK
Content-Type: application/json

{
"message": "string",
"key": "string"
}
```

#### Error Response

```http title="Storage API - PUT Error Response"
HTTP/1.1 4XX/5XX Error
Content-Type: application/json

{
"error": "string"
}
```

### Method: POST

```http title="Storage API - POST /studiocms_api/storage/manager"
POST /studiocms_api/storage/manager HTTP/1.1
Host: example.com
Content-Type: application/json
Accept: application/json

{
"action": "resolveUrl | publicUrl | upload | list | delete | rename | download | cleanup | mappings | test",
...additional parameters based on action...
}
```

#### Actions

- `resolveUrl`
- **Params:** `{ identifier: string }`
- **Response:** [`UrlMetadata`](#urlmetadata)
- `publicUrl`
- **Params:** `{ key: string }`
- **Response:** [`UrlMetadata`](#urlmetadata) `& { identifier: string }`
- `upload`
- **Params:** `{ key: string, contentType: string }`
- **Response:** `{ url: string, key: string }`
- `list`
- **Params:** `{ prefix?: string, key?: string }`
- **Response:** `{ files:` [`File[]`](#file) `}`
- `delete`
- **Params:** `{ key: string }`
- **Response:** `{ success: boolean }`
- `rename`
- **Params:** `{ key: string, newKey: string }`
- **Response:** `{ success: boolean, newKey: string }`
- `download`
- **Params:** `{ key: string }`
- **Response:** `{ url: string }`
- `cleanup`
- **Params:** `N/A`
- **Response:** `{ deletedCount: number }`
- `mappings`
- **Params:** `N/A`
- **Response:** `{ mappings:` [`UrlMetadata[]`](#urlmetadata) `}`
- `test`
- **Params:** `N/A`
- **Response:** `{ success: boolean, message: string, provider: string }`

#### Error Response

```http title="Storage API - POST Error Response"
HTTP/1.1 4XX/5XX Error
Content-Type: application/json

{
"error": "string"
}
```

## Types

### UrlMetadata

```ts
export interface UrlMetadata {
url: string;
isPermanent: boolean;
expiresAt?: number; // Unix timestamp in ms
}
```

### File

```ts
export interface File {
key: string | undefined;
size: number | undefined;
lastModified: Date | undefined;
}
```
93 changes: 93 additions & 0 deletions src/content/docs/es/storage-api/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
i18nReady: true
title: Overview
description: Learn about the Storage API in StudioCMS
Comment on lines +2 to +4
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Content is not translated — i18nReady: true is premature.

All prose remains in English. Set i18nReady: false until the Spanish translation is complete.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/content/docs/es/storage-api/index.mdx` around lines 2 - 4, The
frontmatter flag i18nReady is set to true but the page body (title/description
and prose) is still in English; change the frontmatter key i18nReady from true
to false until the Spanish translation is completed and verified (update
i18nReady back to true once you add the translated content for title/description
and all prose).

tableOfContents:
minHeadingLevel: 2
maxHeadingLevel: 4
sidebar:
order: 1
badge:
text: NEW
variant: success
---

import ReadMore from '~/components/ReadMore.astro';
import { Aside } from '@astrojs/starlight/components';

The Storage API in StudioCMS provides a unified way to manage and interact with various storage backends. It abstracts the complexities of different storage systems, allowing developers to work with a consistent interface regardless of the underlying technology.

## How it Works

The Storage API is designed to be flexible and extensible. It supports multiple storage backends, including local file systems, cloud storage services, and databases. Developers can choose the storage backend that best fits their needs and easily switch between them without changing their application code.

## Manager plugins

The Storage API uses manager plugins to handle different storage backends. Each manager plugin implements a specific storage system and provides methods for common operations such as reading, writing, and deleting files.

An example of a manager built-in to StudioCMS is the `no-op` manager, which performs no operations and tells StudioCMS not to enable any of its storage features.

### Example of the No-op Manager

```ts twoslash title="NoOpStorageService.ts"
import type {
AuthorizationType,
ContextDriverDefinition,
StorageAPIEndpointFn,
StorageApiBuilderDefinition,
UrlMappingServiceDefinition,
} from 'studiocms/storage-manager/definitions';

/**
* A No-Op Storage Service that implements the StorageApiBuilderDefinition interface.
*
* This service provides placeholder implementations for storage API endpoints,
* returning a 501 Not Implemented response for both POST and PUT requests.
*
* @typeParam C - The context type.
* @typeParam R - The response type.
*/
export default class NoOpStorageService<C, R> implements
StorageApiBuilderDefinition<C, R> {
driver: ContextDriverDefinition<C, R>;
urlMappingService: UrlMappingServiceDefinition;

constructor(
driver: ContextDriverDefinition<C, R>,
urlMappingService: UrlMappingServiceDefinition
) {
this.driver = driver;
this.urlMappingService = urlMappingService;
}

#sharedResponse() {
return { data: { error: 'noStorageConfigured' }, status: 501 };
}

getPOST(_?: AuthorizationType): StorageAPIEndpointFn<C, R> {
return this.driver.handleEndpoint(async () => this.#sharedResponse());
}

getPUT(_?: AuthorizationType): StorageAPIEndpointFn<C, R> {
return this.driver.handleEndpoint(async () => this.#sharedResponse());
}
}
```

### Configuring a Manager

To configure a storage manager in StudioCMS, you need to specify the desired manager plugin in your StudioCMS configuration file. To do so you must install the manager plugin package and then add it to the `storageManager` property in your `studiocms.config.*` file.

```ts twoslash title="studiocms.config.mjs" {5}
import { defineStudioCMSConfig } from "studiocms/config";
import s3Storage from '@studiocms/s3-storage';

export default defineStudioCMSConfig({
storageManager: s3Storage(),
// other configuration options
})
```

<ReadMore>
For available storage manager plugins, see the [Package catalog](/en/package-catalog#storage-managers).
</ReadMore>
55 changes: 55 additions & 0 deletions src/content/docs/es/storage-api/javascript-helpers.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
i18nReady: true
title: JavaScript Helpers
description: Learn about the JavaScript helpers available in the StudioCMS Storage API.
tableOfContents:
Comment on lines +2 to +5
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Content is not translated — i18nReady: true is premature.

All prose text (title, description, and the full page body) is in English. In Starlight-based docs, i18nReady: true on a translated page signals the translation is complete and in sync with the English source. Marking this as ready while the content is still entirely in English will suppress any "needs translation" UI indicator and mislead users expecting Spanish content.

Either translate the content before setting i18nReady: true, or set it to false until translation is complete.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/content/docs/es/storage-api/javascript-helpers.mdx` around lines 2 - 5,
The frontmatter flag i18nReady is set to true while the page content (title,
description, body) is still in English; update the frontmatter key i18nReady to
false until the Spanish translation is complete or replace the English text with
the translated Spanish content and then set i18nReady: true—look for the
i18nReady field in the document's frontmatter (the top metadata block containing
title/description) and change its boolean appropriately.

minHeadingLevel: 2
maxHeadingLevel: 4
sidebar:
order: 2
badge:
text: NEW
variant: success
---

import ReadMore from '~/components/ReadMore.astro';
import { Aside } from '@astrojs/starlight/components';

The StudioCMS Storage API provides several JavaScript helpers to facilitate interaction with storage backends. These helpers simplify tasks such as resolving storage identifiers and keys, as well as providing type definitions for better type safety and code completion.

## JavaScript helpers

```ts twoslash title="storage-api-example.ts"
import {
resolveStorageIdentifier,
resolveStorageKey,
} from 'studiocms/storage-api';

const storageIdentifier = await resolveStorageIdentifier('storage-file://my-file.txt', {
baseUrl: 'https://example.com/', // Use the value of `site` from "astro:config/server"
});

const storageKey = await resolveStorageKey('my-file.txt', {
baseUrl: 'https://example.com/', // Use the value of `site` from "astro:config/server"
});
```

## JavaScript Types

```ts twoslash title="storage-api-types.ts"
import type {
ContextJsonBody,
AuthorizationType,
ParsedContext,
UrlMetadata,
UrlMapping,
ContextHandler,
ContextHandlerFn,
ContextDriverDefinition,
StorageAPIEndpointFn,
StorageApiBuilderDefinition,
UrlMappingDatabaseDefinition,
UrlMappingServiceDefinition,
APICoreDefinition
} from 'studiocms/storage-api';
```