@opensaas/stack-storage 0.43.0 → 0.44.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +445 -0
- package/README.md +62 -30
- package/dist/.build-hash +1 -0
- package/dist/fields/index.d.ts +9 -8
- package/dist/fields/index.d.ts.map +1 -1
- package/dist/fields/index.js +376 -153
- package/dist/fields/index.js.map +1 -1
- package/dist/providers/local.d.ts +8 -0
- package/dist/providers/local.d.ts.map +1 -1
- package/dist/providers/local.js +56 -5
- package/dist/providers/local.js.map +1 -1
- package/dist/runtime/index.d.ts +29 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +244 -29
- package/dist/runtime/index.js.map +1 -1
- package/dist/utils/asset-references.d.ts +13 -0
- package/dist/utils/asset-references.d.ts.map +1 -0
- package/dist/utils/asset-references.js +40 -0
- package/dist/utils/asset-references.js.map +1 -0
- package/dist/utils/image.d.ts +17 -0
- package/dist/utils/image.d.ts.map +1 -1
- package/dist/utils/image.js +69 -22
- package/dist/utils/image.js.map +1 -1
- package/dist/utils/metadata-trust.d.ts +30 -0
- package/dist/utils/metadata-trust.d.ts.map +1 -0
- package/dist/utils/metadata-trust.js +57 -0
- package/dist/utils/metadata-trust.js.map +1 -0
- package/dist/utils/multi-column.d.ts +7 -7
- package/dist/utils/multi-column.d.ts.map +1 -1
- package/dist/utils/multi-column.js +17 -34
- package/dist/utils/multi-column.js.map +1 -1
- package/dist/utils/upload.d.ts +58 -0
- package/dist/utils/upload.d.ts.map +1 -1
- package/dist/utils/upload.js +135 -11
- package/dist/utils/upload.js.map +1 -1
- package/package.json +20 -9
- package/.turbo/turbo-build.log +0 -4
- package/CLAUDE.md +0 -528
- package/src/config/index.ts +0 -30
- package/src/config/types.ts +0 -92
- package/src/fields/index.ts +0 -531
- package/src/index.ts +0 -14
- package/src/providers/index.ts +0 -1
- package/src/providers/local.ts +0 -79
- package/src/runtime/index.ts +0 -244
- package/src/runtime/registry.ts +0 -106
- package/src/utils/image.ts +0 -95
- package/src/utils/index.ts +0 -3
- package/src/utils/multi-column.ts +0 -425
- package/src/utils/upload.ts +0 -95
- package/tests/field-zod-schema.test.ts +0 -133
- package/tests/image-utils.test.ts +0 -498
- package/tests/local-provider.test.ts +0 -364
- package/tests/multi-column-fields.test.ts +0 -393
- package/tests/multi-column.test.ts +0 -453
- package/tests/opensaas-image-file-write-validation.test.ts +0 -294
- package/tests/provider-registry.test.ts +0 -201
- package/tests/upload-utils.test.ts +0 -313
- package/tsconfig.json +0 -9
- package/vitest.config.ts +0 -14
package/src/runtime/index.ts
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
import type { OpenSaasConfig } from '@opensaas/stack-core'
|
|
2
|
-
import type {
|
|
3
|
-
StorageProvider,
|
|
4
|
-
FileMetadata,
|
|
5
|
-
ImageMetadata,
|
|
6
|
-
ImageTransformationConfig,
|
|
7
|
-
} from '../config/types.js'
|
|
8
|
-
import { validateFile, getMimeType, type FileValidationOptions } from '../utils/upload.js'
|
|
9
|
-
import { getImageDimensions, processImageTransformations } from '../utils/image.js'
|
|
10
|
-
import { getStorageProviderFactory } from './registry.js'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Creates a storage provider instance from config.
|
|
14
|
-
*
|
|
15
|
-
* The provider `type` is resolved through the provider registry (see
|
|
16
|
-
* {@link registerStorageProvider}) rather than a closed `switch`. `'local'` is
|
|
17
|
-
* registered as a built-in default, so it works with no registration step.
|
|
18
|
-
* Optional providers (`@opensaas/stack-storage-s3`,
|
|
19
|
-
* `@opensaas/stack-storage-vercel`) and custom providers must be registered by
|
|
20
|
-
* the host before they can be constructed.
|
|
21
|
-
*
|
|
22
|
-
* @throws If the named provider is not present in `config.storage`.
|
|
23
|
-
* @throws If no provider factory has been registered for the config's `type`.
|
|
24
|
-
*/
|
|
25
|
-
export function createStorageProvider(
|
|
26
|
-
config: OpenSaasConfig,
|
|
27
|
-
providerName: string,
|
|
28
|
-
): StorageProvider {
|
|
29
|
-
if (!config.storage || !config.storage[providerName]) {
|
|
30
|
-
throw new Error(`Storage provider '${providerName}' not found in config`)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const providerConfig = config.storage[providerName]
|
|
34
|
-
|
|
35
|
-
const factory = getStorageProviderFactory(providerConfig.type)
|
|
36
|
-
if (!factory) {
|
|
37
|
-
throw new Error(
|
|
38
|
-
`Unknown storage provider type: ${providerConfig.type}. ` +
|
|
39
|
-
`Register it with registerStorageProvider('${providerConfig.type}', ...) from ` +
|
|
40
|
-
`'@opensaas/stack-storage/runtime' before use.`,
|
|
41
|
-
)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return factory(providerConfig)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Options for uploading a file
|
|
49
|
-
*/
|
|
50
|
-
export interface UploadFileOptions {
|
|
51
|
-
/** Validation options */
|
|
52
|
-
validation?: FileValidationOptions
|
|
53
|
-
/** Custom metadata */
|
|
54
|
-
metadata?: Record<string, string>
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Options for uploading an image with transformations
|
|
59
|
-
*/
|
|
60
|
-
export interface UploadImageOptions extends UploadFileOptions {
|
|
61
|
-
/** Image transformations to apply */
|
|
62
|
-
transformations?: Record<string, ImageTransformationConfig>
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Uploads a file to the specified storage provider
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ```typescript
|
|
70
|
-
* const metadata = await uploadFile(config, 'documents', {
|
|
71
|
-
* file,
|
|
72
|
-
* buffer,
|
|
73
|
-
* validation: {
|
|
74
|
-
* maxFileSize: 10 * 1024 * 1024, // 10MB
|
|
75
|
-
* acceptedMimeTypes: ['application/pdf']
|
|
76
|
-
* }
|
|
77
|
-
* })
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
export async function uploadFile(
|
|
81
|
-
config: OpenSaasConfig,
|
|
82
|
-
storageProviderName: string,
|
|
83
|
-
data: {
|
|
84
|
-
file: File
|
|
85
|
-
buffer: Buffer
|
|
86
|
-
},
|
|
87
|
-
options?: UploadFileOptions,
|
|
88
|
-
): Promise<FileMetadata> {
|
|
89
|
-
const { file, buffer } = data
|
|
90
|
-
|
|
91
|
-
if (options?.validation) {
|
|
92
|
-
const validation = validateFile(
|
|
93
|
-
{
|
|
94
|
-
size: file.size,
|
|
95
|
-
name: file.name,
|
|
96
|
-
type: file.type,
|
|
97
|
-
},
|
|
98
|
-
options.validation,
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
if (!validation.valid) {
|
|
102
|
-
throw new Error(validation.error)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const provider = createStorageProvider(config, storageProviderName)
|
|
107
|
-
|
|
108
|
-
const contentType = file.type || getMimeType(file.name)
|
|
109
|
-
|
|
110
|
-
const result = await provider.upload(buffer, file.name, {
|
|
111
|
-
contentType,
|
|
112
|
-
metadata: options?.metadata,
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
filename: result.filename,
|
|
117
|
-
originalFilename: file.name,
|
|
118
|
-
url: result.url,
|
|
119
|
-
mimeType: contentType,
|
|
120
|
-
size: result.size,
|
|
121
|
-
uploadedAt: new Date().toISOString(),
|
|
122
|
-
storageProvider: storageProviderName,
|
|
123
|
-
metadata: result.metadata,
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Uploads an image with optional transformations
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* ```typescript
|
|
132
|
-
* const metadata = await uploadImage(config, 'avatars', {
|
|
133
|
-
* file,
|
|
134
|
-
* buffer,
|
|
135
|
-
* validation: {
|
|
136
|
-
* maxFileSize: 5 * 1024 * 1024, // 5MB
|
|
137
|
-
* acceptedMimeTypes: ['image/jpeg', 'image/png', 'image/webp']
|
|
138
|
-
* },
|
|
139
|
-
* transformations: {
|
|
140
|
-
* thumbnail: { width: 100, height: 100, fit: 'cover' },
|
|
141
|
-
* profile: { width: 400, height: 400, fit: 'cover' }
|
|
142
|
-
* }
|
|
143
|
-
* })
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
export async function uploadImage(
|
|
147
|
-
config: OpenSaasConfig,
|
|
148
|
-
storageProviderName: string,
|
|
149
|
-
data: {
|
|
150
|
-
file: File
|
|
151
|
-
buffer: Buffer
|
|
152
|
-
},
|
|
153
|
-
options?: UploadImageOptions,
|
|
154
|
-
): Promise<ImageMetadata> {
|
|
155
|
-
const { file, buffer } = data
|
|
156
|
-
|
|
157
|
-
if (options?.validation) {
|
|
158
|
-
const validation = validateFile(
|
|
159
|
-
{
|
|
160
|
-
size: file.size,
|
|
161
|
-
name: file.name,
|
|
162
|
-
type: file.type,
|
|
163
|
-
},
|
|
164
|
-
options.validation,
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
if (!validation.valid) {
|
|
168
|
-
throw new Error(validation.error)
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
const provider = createStorageProvider(config, storageProviderName)
|
|
173
|
-
|
|
174
|
-
const contentType = file.type || getMimeType(file.name)
|
|
175
|
-
|
|
176
|
-
const { width, height } = await getImageDimensions(buffer)
|
|
177
|
-
|
|
178
|
-
const result = await provider.upload(buffer, file.name, {
|
|
179
|
-
contentType,
|
|
180
|
-
metadata: options?.metadata,
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
let transformations:
|
|
184
|
-
Record<string, { url: string; width: number; height: number; size: number }> | undefined
|
|
185
|
-
if (options?.transformations) {
|
|
186
|
-
transformations = await processImageTransformations(
|
|
187
|
-
buffer,
|
|
188
|
-
file.name,
|
|
189
|
-
options.transformations,
|
|
190
|
-
provider,
|
|
191
|
-
contentType,
|
|
192
|
-
)
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return {
|
|
196
|
-
filename: result.filename,
|
|
197
|
-
originalFilename: file.name,
|
|
198
|
-
url: result.url,
|
|
199
|
-
mimeType: contentType,
|
|
200
|
-
size: result.size,
|
|
201
|
-
width,
|
|
202
|
-
height,
|
|
203
|
-
uploadedAt: new Date().toISOString(),
|
|
204
|
-
storageProvider: storageProviderName,
|
|
205
|
-
metadata: result.metadata,
|
|
206
|
-
transformations,
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export async function deleteFile(
|
|
211
|
-
config: OpenSaasConfig,
|
|
212
|
-
storageProviderName: string,
|
|
213
|
-
filename: string,
|
|
214
|
-
): Promise<void> {
|
|
215
|
-
const provider = createStorageProvider(config, storageProviderName)
|
|
216
|
-
await provider.delete(filename)
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export async function deleteImage(config: OpenSaasConfig, metadata: ImageMetadata): Promise<void> {
|
|
220
|
-
const provider = createStorageProvider(config, metadata.storageProvider)
|
|
221
|
-
|
|
222
|
-
await provider.delete(metadata.filename)
|
|
223
|
-
|
|
224
|
-
if (metadata.transformations) {
|
|
225
|
-
for (const transformationResult of Object.values(metadata.transformations)) {
|
|
226
|
-
const filename = transformationResult.url.split('/').pop()
|
|
227
|
-
if (filename) {
|
|
228
|
-
await provider.delete(filename)
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export { parseFileFromFormData } from '../utils/upload.js'
|
|
235
|
-
|
|
236
|
-
// Provider registration API: hosts register optional/custom providers so
|
|
237
|
-
// createStorageProvider can construct them (see registry.ts).
|
|
238
|
-
export {
|
|
239
|
-
registerStorageProvider,
|
|
240
|
-
getStorageProviderFactory,
|
|
241
|
-
hasStorageProvider,
|
|
242
|
-
resetStorageProviderRegistry,
|
|
243
|
-
type StorageProviderFactory,
|
|
244
|
-
} from './registry.js'
|
package/src/runtime/registry.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { StorageProvider, BaseStorageConfig, LocalStorageConfig } from '../config/types.js'
|
|
2
|
-
import { LocalStorageProvider } from '../providers/local.js'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A factory that constructs a {@link StorageProvider} from its provider config.
|
|
6
|
-
*
|
|
7
|
-
* The factory is generic over the concrete config shape so a provider package
|
|
8
|
-
* can register with full type safety (e.g. `S3StorageConfig`), while the
|
|
9
|
-
* registry stores factories against the {@link BaseStorageConfig} contract that
|
|
10
|
-
* every provider config satisfies.
|
|
11
|
-
*
|
|
12
|
-
* @typeParam TConfig - The provider-specific config type (must extend
|
|
13
|
-
* {@link BaseStorageConfig}).
|
|
14
|
-
*/
|
|
15
|
-
export type StorageProviderFactory<TConfig extends BaseStorageConfig = BaseStorageConfig> = (
|
|
16
|
-
config: TConfig,
|
|
17
|
-
) => StorageProvider
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Internal registry mapping a provider `type` to its factory.
|
|
21
|
-
*
|
|
22
|
-
* Factories are stored against {@link BaseStorageConfig} because every provider
|
|
23
|
-
* config extends it. `registerStorageProvider` narrows the public input to the
|
|
24
|
-
* concrete config type, then widens it for storage — this conversion happens
|
|
25
|
-
* once, internally, so the public API stays free of `any`/casts.
|
|
26
|
-
*/
|
|
27
|
-
const registry = new Map<string, StorageProviderFactory>()
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Registers a storage provider factory for a given provider `type`.
|
|
31
|
-
*
|
|
32
|
-
* The host application calls this to opt in to a provider it uses — either one
|
|
33
|
-
* of the optional provider packages (`@opensaas/stack-storage-s3`,
|
|
34
|
-
* `@opensaas/stack-storage-vercel`) or a custom provider. Once registered,
|
|
35
|
-
* {@link createStorageProvider} can construct that provider when a field is
|
|
36
|
-
* bound to it.
|
|
37
|
-
*
|
|
38
|
-
* Registering an already-registered `type` overwrites the previous factory,
|
|
39
|
-
* allowing a host to replace a built-in (e.g. swap the default `'local'`
|
|
40
|
-
* provider) if needed.
|
|
41
|
-
*
|
|
42
|
-
* @typeParam TConfig - The provider-specific config type.
|
|
43
|
-
* @param type - The provider `type` discriminator used in storage config
|
|
44
|
-
* (e.g. `'s3'`, `'vercel-blob'`, `'cloudflare-r2'`).
|
|
45
|
-
* @param factory - A function that builds the provider from its config.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* import { registerStorageProvider } from '@opensaas/stack-storage/runtime'
|
|
50
|
-
* import { S3StorageProvider, type S3StorageConfig } from '@opensaas/stack-storage-s3'
|
|
51
|
-
*
|
|
52
|
-
* registerStorageProvider<S3StorageConfig>('s3', (config) => new S3StorageProvider(config))
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
export function registerStorageProvider<TConfig extends BaseStorageConfig>(
|
|
56
|
-
type: string,
|
|
57
|
-
factory: StorageProviderFactory<TConfig>,
|
|
58
|
-
): void {
|
|
59
|
-
// `factory` accepts a narrower `TConfig`; the registry stores it against the
|
|
60
|
-
// wider `BaseStorageConfig`. This widening wrapper is safe because
|
|
61
|
-
// `createStorageProvider` only ever invokes a factory with the config whose
|
|
62
|
-
// `type` selected it, so the runtime config always matches `TConfig`.
|
|
63
|
-
const widened: StorageProviderFactory = (config) => factory(config as TConfig)
|
|
64
|
-
registry.set(type, widened)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Returns the factory registered for a provider `type`, or `undefined` when no
|
|
69
|
-
* provider has been registered under that `type`.
|
|
70
|
-
*/
|
|
71
|
-
export function getStorageProviderFactory(type: string): StorageProviderFactory | undefined {
|
|
72
|
-
return registry.get(type)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Returns `true` when a provider factory is registered for the given `type`.
|
|
77
|
-
*/
|
|
78
|
-
export function hasStorageProvider(type: string): boolean {
|
|
79
|
-
return registry.has(type)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Resets the registry to only the built-in defaults.
|
|
84
|
-
*
|
|
85
|
-
* Primarily useful in tests to guarantee isolation between cases that register
|
|
86
|
-
* custom providers.
|
|
87
|
-
*/
|
|
88
|
-
export function resetStorageProviderRegistry(): void {
|
|
89
|
-
registry.clear()
|
|
90
|
-
registerBuiltinProviders()
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Registers the providers that ship with `@opensaas/stack-storage` itself.
|
|
95
|
-
*
|
|
96
|
-
* Currently only `'local'`, which keeps existing behaviour unchanged: hosts get
|
|
97
|
-
* local filesystem storage with no registration step. Optional providers
|
|
98
|
-
* (`s3`, `vercel-blob`) are NOT registered here — the host opts into those to
|
|
99
|
-
* avoid forcing the AWS/Vercel SDKs onto every storage user.
|
|
100
|
-
*/
|
|
101
|
-
function registerBuiltinProviders(): void {
|
|
102
|
-
registerStorageProvider<LocalStorageConfig>('local', (config) => new LocalStorageProvider(config))
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// Register built-in providers on module load so `'local'` works by default.
|
|
106
|
-
registerBuiltinProviders()
|
package/src/utils/image.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import sharp from 'sharp'
|
|
2
|
-
import type {
|
|
3
|
-
ImageTransformationConfig,
|
|
4
|
-
ImageTransformationResult,
|
|
5
|
-
StorageProvider,
|
|
6
|
-
} from '../config/types.js'
|
|
7
|
-
|
|
8
|
-
export async function getImageDimensions(
|
|
9
|
-
buffer: Buffer | Uint8Array,
|
|
10
|
-
): Promise<{ width: number; height: number }> {
|
|
11
|
-
const metadata = await sharp(buffer).metadata()
|
|
12
|
-
return {
|
|
13
|
-
width: metadata.width || 0,
|
|
14
|
-
height: metadata.height || 0,
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export async function transformImage(
|
|
19
|
-
buffer: Buffer | Uint8Array,
|
|
20
|
-
transformation: ImageTransformationConfig,
|
|
21
|
-
): Promise<Buffer> {
|
|
22
|
-
let image = sharp(buffer)
|
|
23
|
-
|
|
24
|
-
if (transformation.width || transformation.height) {
|
|
25
|
-
image = image.resize({
|
|
26
|
-
width: transformation.width,
|
|
27
|
-
height: transformation.height,
|
|
28
|
-
fit: transformation.fit || 'cover',
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (transformation.format) {
|
|
33
|
-
const options = {
|
|
34
|
-
quality: transformation.quality || 80,
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
switch (transformation.format) {
|
|
38
|
-
case 'jpeg':
|
|
39
|
-
image = image.jpeg(options)
|
|
40
|
-
break
|
|
41
|
-
case 'png':
|
|
42
|
-
image = image.png(options)
|
|
43
|
-
break
|
|
44
|
-
case 'webp':
|
|
45
|
-
image = image.webp(options)
|
|
46
|
-
break
|
|
47
|
-
case 'avif':
|
|
48
|
-
image = image.avif(options)
|
|
49
|
-
break
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return await image.toBuffer()
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export async function processImageTransformations(
|
|
57
|
-
buffer: Buffer | Uint8Array,
|
|
58
|
-
originalFilename: string,
|
|
59
|
-
transformations: Record<string, ImageTransformationConfig>,
|
|
60
|
-
storageProvider: StorageProvider,
|
|
61
|
-
contentType: string,
|
|
62
|
-
): Promise<Record<string, ImageTransformationResult>> {
|
|
63
|
-
const results: Record<string, ImageTransformationResult> = {}
|
|
64
|
-
|
|
65
|
-
for (const [name, config] of Object.entries(transformations)) {
|
|
66
|
-
const transformedBuffer = await transformImage(buffer, config)
|
|
67
|
-
|
|
68
|
-
const { width, height } = await getImageDimensions(transformedBuffer)
|
|
69
|
-
|
|
70
|
-
const ext = config.format ? `.${config.format}` : ''
|
|
71
|
-
const transformedFilename = `${originalFilename}-${name}${ext}`
|
|
72
|
-
|
|
73
|
-
const uploadResult = await storageProvider.upload(transformedBuffer, transformedFilename, {
|
|
74
|
-
contentType:
|
|
75
|
-
config.format === 'jpeg'
|
|
76
|
-
? 'image/jpeg'
|
|
77
|
-
: config.format === 'png'
|
|
78
|
-
? 'image/png'
|
|
79
|
-
: config.format === 'webp'
|
|
80
|
-
? 'image/webp'
|
|
81
|
-
: config.format === 'avif'
|
|
82
|
-
? 'image/avif'
|
|
83
|
-
: contentType,
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
results[name] = {
|
|
87
|
-
url: uploadResult.url,
|
|
88
|
-
width,
|
|
89
|
-
height,
|
|
90
|
-
size: uploadResult.size,
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return results
|
|
95
|
-
}
|
package/src/utils/index.ts
DELETED