Skip to content
Open
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
13 changes: 13 additions & 0 deletions packages/file-input-provider-azure/azureblob.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createPlugin } from 'startupjs/registry'
import * as provider from './provider.js'

export default createPlugin({
name: 'file-input-provider-azureblob',
enabled: true,
order: 'system ui',
server: () => ({
fileStorageProviders: () => ({
azureblob: provider
})
})
})
8 changes: 8 additions & 0 deletions packages/file-input-provider-azure/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Azure Blob Storage provider for @startupjs-ui/file-input.
*
* Registration is handled automatically by the plugin system
* via azureblob.plugin.js. This module re-exports the provider
* for direct usage if needed.
*/
export * from './provider.js'
20 changes: 20 additions & 0 deletions packages/file-input-provider-azure/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@startupjs-ui/file-input-provider-azure",
"version": "0.1.16",
"description": "Azure Blob Storage provider plugin for @startupjs-ui/file-input",
"publishConfig": {
"access": "public"
},
"main": "index.js",
"type": "module",
"exports": {
".": "./index.js",
"./azureblob.plugin": "./azureblob.plugin.js"
},
"dependencies": {
"@azure/storage-blob": "^12.26.0"
},
"peerDependencies": {
"startupjs": "*"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { BlobServiceClient } from '@azure/storage-blob'

// Replace with your Azure Blob Storage connection string or Azurite connection string
const AZURE_BLOB_STORAGE_CONNECTION_STRING = process.env.AZURE_BLOB_STORAGE_CONNECTION_STRING
const AZURE_BLOB_STORAGE_CONNECTION_STRING =
process.env.AZURE_BLOB_STORAGE_CONNECTION_STRING
const CONTAINER_NAME = 'files' // Container name for storing blobs

let blobServiceClient
Expand All @@ -13,7 +14,9 @@ export function validateSupport () {
}
// Initialize the BlobServiceClient and ContainerClient once
if (!blobServiceClient) {
blobServiceClient = BlobServiceClient.fromConnectionString(AZURE_BLOB_STORAGE_CONNECTION_STRING)
blobServiceClient = BlobServiceClient.fromConnectionString(
AZURE_BLOB_STORAGE_CONNECTION_STRING
)
containerClient = blobServiceClient.getContainerClient(CONTAINER_NAME)
// Ensure container exists
containerClient.createIfNotExists().catch((err) => {
Expand All @@ -34,11 +37,17 @@ export async function getFileBlob (fileId, options = {}) {
const actualFileSize = properties.contentLength

if (range) {
console.log('[Azure Blob Storage] Using Range request for optimal streaming:', { fileId, range })
console.log(
'[Azure Blob Storage] Using Range request for optimal streaming:',
{ fileId, range }
)

// Validate range boundaries
if (range.start >= actualFileSize || range.start < 0) {
console.log('[Azure Blob Storage] Range start out of bounds:', { start: range.start, actualFileSize })
console.log('[Azure Blob Storage] Range start out of bounds:', {
start: range.start,
actualFileSize
})
throw new Error('Range start out of bounds')
}

Expand All @@ -47,7 +56,11 @@ export async function getFileBlob (fileId, options = {}) {

// Ensure end is not before start
if (adjustedEnd < range.start) {
console.log('[Azure Blob Storage] Invalid range:', { start: range.start, end: adjustedEnd, actualFileSize })
console.log('[Azure Blob Storage] Invalid range:', {
start: range.start,
end: adjustedEnd,
actualFileSize
})
throw new Error('Invalid range')
}

Expand All @@ -59,7 +72,10 @@ export async function getFileBlob (fileId, options = {}) {
})

// Download blob with range
const response = await blobClient.download(range.start, adjustedEnd - range.start + 1)
const response = await blobClient.download(
range.start,
adjustedEnd - range.start + 1
)
const chunks = []

for await (const chunk of response.readableStreamBody) {
Expand All @@ -78,7 +94,9 @@ export async function getFileBlob (fileId, options = {}) {
})

if (result.length === 0) {
console.warn('[Azure Blob Storage] Empty range response - this may indicate a problem')
console.warn(
'[Azure Blob Storage] Empty range response - this may indicate a problem'
)
}

return result
Expand Down
8 changes: 8 additions & 0 deletions packages/file-input-provider-mongo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* MongoDB GridFS storage provider for @startupjs-ui/file-input.
*
* Registration is handled automatically by the plugin system
* via mongo.plugin.js. This module re-exports the provider
* for direct usage if needed.
*/
export * from './provider.js'
13 changes: 13 additions & 0 deletions packages/file-input-provider-mongo/mongo.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createPlugin } from 'startupjs/registry'
import * as provider from './provider.js'

export default createPlugin({
name: 'file-input-provider-mongo',
enabled: true,
order: 'system ui',
server: () => ({
fileStorageProviders: () => ({
mongo: provider
})
})
})
20 changes: 20 additions & 0 deletions packages/file-input-provider-mongo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@startupjs-ui/file-input-provider-mongo",
"version": "0.1.16",
"description": "MongoDB GridFS storage provider plugin for @startupjs-ui/file-input",
"publishConfig": {
"access": "public"
},
"main": "index.js",
"type": "module",
"exports": {
".": "./index.js",
"./mongo.plugin": "./mongo.plugin.js"
},
"dependencies": {
"mongodb": "^6.12.0"
},
"peerDependencies": {
"startupjs": "*"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ export async function getFileBlob (fileId, options = {}) {
// Performance optimization: use Range requests for partial content
let downloadStream
if (range) {
console.log('[MongoDB GridFS] Using Range request for optimal streaming:', { fileId, range })
console.log(
'[MongoDB GridFS] Using Range request for optimal streaming:',
{ fileId, range }
)

// Validate range boundaries
const actualFileSize = files[0].length
if (range.start >= actualFileSize || range.start < 0) {
console.log('[MongoDB GridFS] Range start out of bounds:', { start: range.start, actualFileSize })
console.log('[MongoDB GridFS] Range start out of bounds:', {
start: range.start,
actualFileSize
})
return reject(new Error('Range start out of bounds'))
}

Expand All @@ -37,7 +43,11 @@ export async function getFileBlob (fileId, options = {}) {

// Ensure end is not before start
if (adjustedEnd < range.start) {
console.log('[MongoDB GridFS] Invalid range:', { start: range.start, end: adjustedEnd, actualFileSize })
console.log('[MongoDB GridFS] Invalid range:', {
start: range.start,
end: adjustedEnd,
actualFileSize
})
return reject(new Error('Invalid range'))
}

Expand Down Expand Up @@ -87,7 +97,9 @@ export async function getFileBlob (fileId, options = {}) {

// Validate that we got the expected data
if (result.length === 0) {
console.warn('[MongoDB GridFS] Empty range response - this may indicate a problem')
console.warn(
'[MongoDB GridFS] Empty range response - this may indicate a problem'
)
}
}
resolve(result)
Expand Down Expand Up @@ -126,7 +138,10 @@ export async function saveFileBlob (fileId, blob, options) {
const uploadStream = bucket.openUploadStream(fileId)

uploadStream.on('data', (chunk) => {
console.log('[MongoDB GridFS] Stream data received:', { fileId, chunkLength: chunk.length })
console.log('[MongoDB GridFS] Stream data received:', {
fileId,
chunkLength: chunk.length
})
})
uploadStream.on('end', () => {
console.log('[MongoDB GridFS] Stream end event:', fileId)
Expand Down Expand Up @@ -179,7 +194,7 @@ export async function deleteFile (fileId, options) {

const ERRORS = {
mongoNotAvailable: `
[@startupjs/ui] FileInput: MongoDB connection is not available.
[@startupjs-ui/file-input-provider-mongo] MongoDB connection is not available.
Make sure you have connected to MongoDB before using this function.
`,
fileNotFound: `
Expand Down
8 changes: 8 additions & 0 deletions packages/file-input-provider-s3/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* AWS S3 storage provider for @startupjs-ui/file-input.
*
* Registration is handled automatically by the plugin system
* via s3.plugin.js. This module re-exports the provider
* for direct usage if needed.
*/
export * from './provider.js'
20 changes: 20 additions & 0 deletions packages/file-input-provider-s3/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@startupjs-ui/file-input-provider-s3",
"version": "0.1.16",
"description": "AWS S3 storage provider plugin for @startupjs-ui/file-input",
"publishConfig": {
"access": "public"
},
"main": "index.js",
"type": "module",
"exports": {
".": "./index.js",
"./s3.plugin": "./s3.plugin.js"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.600.0"
},
"peerDependencies": {
"startupjs": "*"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { $, sub } from 'startupjs'
import { S3Client, GetObjectCommand, PutObjectCommand, DeleteObjectCommand, HeadObjectCommand } from '@aws-sdk/client-s3'
import {
S3Client,
GetObjectCommand,
PutObjectCommand,
DeleteObjectCommand,
HeadObjectCommand
} from '@aws-sdk/client-s3'

// AWS S3 Configuration from environment variables
const AWS_REGION = process.env.AWS_REGION
Expand Down Expand Up @@ -69,11 +75,18 @@ export async function getFileBlob (fileId, options = {}) {
const actualFileSize = headResponse.ContentLength

if (range) {
console.log('[AWS S3] Using Range request for optimal streaming:', { fileId, range, filePath })
console.log('[AWS S3] Using Range request for optimal streaming:', {
fileId,
range,
filePath
})

// Validate range boundaries
if (range.start >= actualFileSize || range.start < 0) {
console.log('[AWS S3] Range start out of bounds:', { start: range.start, actualFileSize })
console.log('[AWS S3] Range start out of bounds:', {
start: range.start,
actualFileSize
})
throw new Error('Range start out of bounds')
}

Expand All @@ -82,7 +95,11 @@ export async function getFileBlob (fileId, options = {}) {

// Ensure end is not before start
if (adjustedEnd < range.start) {
console.log('[AWS S3] Invalid range:', { start: range.start, end: adjustedEnd, actualFileSize })
console.log('[AWS S3] Invalid range:', {
start: range.start,
end: adjustedEnd,
actualFileSize
})
throw new Error('Invalid range')
}

Expand Down Expand Up @@ -117,7 +134,9 @@ export async function getFileBlob (fileId, options = {}) {
})

if (result.length === 0) {
console.warn('[AWS S3] Empty range response - this may indicate a problem')
console.warn(
'[AWS S3] Empty range response - this may indicate a problem'
)
}

return result
Expand Down
13 changes: 13 additions & 0 deletions packages/file-input-provider-s3/s3.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createPlugin } from 'startupjs/registry'
import * as provider from './provider.js'

export default createPlugin({
name: 'file-input-provider-s3',
enabled: true,
order: 'system ui',
server: () => ({
fileStorageProviders: () => ({
s3: provider
})
})
})
8 changes: 8 additions & 0 deletions packages/file-input-provider-sqlite/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* SQLite storage provider for @startupjs-ui/file-input.
*
* Registration is handled automatically by the plugin system
* via sqlite.plugin.js. This module re-exports the provider
* for direct usage if needed.
*/
export * from './provider.js'
17 changes: 17 additions & 0 deletions packages/file-input-provider-sqlite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@startupjs-ui/file-input-provider-sqlite",
"version": "0.1.16",
"description": "SQLite storage provider plugin for @startupjs-ui/file-input",
"publishConfig": {
"access": "public"
},
"main": "index.js",
"type": "module",
"exports": {
".": "./index.js",
"./sqlite.plugin": "./sqlite.plugin.js"
},
"peerDependencies": {
"startupjs": "*"
}
}
Loading