Skip to content

Commit 62fae48

Browse files
authored
fix: Handle no file category scenario (#867)
1 parent 5e182c3 commit 62fae48

4 files changed

Lines changed: 37 additions & 14 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@baseplate-dev/plugin-storage': patch
3+
---
4+
5+
Skip generating storage file handling code (upload services, presigned URLs, schemas, and upload components) when no file categories are configured

plugins/plugin-storage/src/storage/core/components/file-category-editor-form.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ function FileCategoryEditorForm({
7373
<SectionListSectionTitle>File Categories</SectionListSectionTitle>
7474
<SectionListSectionDescription>
7575
Configure file categories that define upload constraints, storage
76-
adapters, and authorization rules for file uploads.
76+
adapters, and authorization rules for file uploads. If no file
77+
categories are specified, storage file handling code (upload services,
78+
presigned URLs, and related schemas) will not be generated.
7779
</SectionListSectionDescription>
7880
</SectionListSectionHeader>
7981
<SectionListSectionContent className="storage:space-y-4">

plugins/plugin-storage/src/storage/core/components/storage-definition-editor.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ import {
2828
import { zodResolver } from '@hookform/resolvers/zod';
2929
import { useMemo } from 'react';
3030

31-
import type { StoragePluginDefinitionInput } from '../schema/plugin-definition.js';
31+
import type {
32+
StoragePluginDefinition,
33+
StoragePluginDefinitionInput,
34+
} from '../schema/plugin-definition.js';
3235

3336
import { createStoragePartialDefinition } from '../schema/models.js';
3437
import { createStoragePluginDefinitionSchema } from '../schema/plugin-definition.js';
@@ -58,7 +61,8 @@ export function StorageDefinitionEditor({
5861
'storage',
5962
),
6063
s3Adapters: [],
61-
} satisfies StoragePluginDefinitionInput;
64+
fileCategories: [],
65+
} satisfies StoragePluginDefinition;
6266
}, [definition, pluginMetadata?.config]);
6367

6468
const form = useResettableForm({

plugins/plugin-storage/src/storage/core/node.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@ export default createPluginModule({
3333
pluginKey,
3434
) as StoragePluginDefinition;
3535

36-
// add feature providers
37-
appCompiler.addChildrenToFeature(storage.storageFeatureRef, {
38-
storage: storageModuleGenerator({
39-
s3Adapters: storage.s3Adapters.map((a) => ({
40-
name: a.name,
41-
bucketConfigVar: a.bucketConfigVar,
42-
hostedUrlConfigVar: a.hostedUrlConfigVar,
43-
})),
44-
}),
45-
});
36+
// add feature providers (only when file categories are configured,
37+
// since nearly all storage module templates depend on categories)
38+
if (storage.fileCategories.length > 0) {
39+
appCompiler.addChildrenToFeature(storage.storageFeatureRef, {
40+
storage: storageModuleGenerator({
41+
s3Adapters: storage.s3Adapters.map((a) => ({
42+
name: a.name,
43+
bucketConfigVar: a.bucketConfigVar,
44+
hostedUrlConfigVar: a.hostedUrlConfigVar,
45+
})),
46+
}),
47+
});
48+
}
4649

4750
// Collect file transformers with resolved categories
4851
const transformers = projectDefinition.models.flatMap((m) =>
@@ -146,7 +149,16 @@ export default createPluginModule({
146149
pluginAppCompiler({
147150
pluginKey,
148151
appType: webAppEntryType,
149-
compile: ({ appCompiler, appDefinition }) => {
152+
compile: ({ appCompiler, appDefinition, projectDefinition }) => {
153+
const webStorage = PluginUtils.configByKeyOrThrow(
154+
projectDefinition,
155+
pluginKey,
156+
) as StoragePluginDefinition;
157+
158+
if (webStorage.fileCategories.length === 0) {
159+
return;
160+
}
161+
150162
if (
151163
!appDefinition.includeUploadComponents &&
152164
!appDefinition.adminApp.enabled

0 commit comments

Comments
 (0)