express-storage
Version:
A simple and powerful file upload and storage management package for Express.js applications. Supports multiple storage drivers including S3, GCS, OCI, and local storage with presigned URL support.
84 lines • 3.06 kB
JavaScript
// OCI SDK imports - simplified for now
// Note: OCI SDK structure may vary, this is a placeholder implementation
import { BaseStorageDriver } from './base.driver.js';
/**
* Oracle Cloud Infrastructure storage driver (placeholder implementation)
*/
export class OCIStorageDriver extends BaseStorageDriver {
constructor(config) {
super(config);
this.bucketName = config.bucketName;
this.region = config.ociRegion;
}
/**
* Upload file to OCI (placeholder)
*/
async upload(file) {
try {
// Validate file
const validationErrors = this.validateFile(file);
if (validationErrors.length > 0) {
return this.createErrorResult(validationErrors.join(', '));
}
// Generate unique filename
const fileName = this.generateFileName(file.originalname);
// Placeholder implementation
const fileUrl = `https://objectstorage.${this.region}.oraclecloud.com/b/${this.bucketName}/o/${fileName}`;
return this.createSuccessResult(fileName, fileUrl);
}
catch (error) {
return this.createErrorResult(error instanceof Error ? error.message : 'Failed to upload file to OCI');
}
}
/**
* Generate presigned upload URL (placeholder)
*/
async generateUploadUrl(_fileName) {
return this.createPresignedErrorResult('OCI presigned URLs not implemented yet');
}
/**
* Generate presigned view URL (placeholder)
*/
async generateViewUrl(_fileName) {
return this.createPresignedErrorResult('OCI presigned URLs not implemented yet');
}
/**
* Delete file from OCI (placeholder)
*/
async delete(_fileName) {
// Placeholder implementation
return true;
}
}
/**
* Oracle Cloud Infrastructure presigned driver
*/
export class OCIPresignedStorageDriver extends OCIStorageDriver {
constructor(config) {
super(config);
}
/**
* Override upload to return presigned URL instead of direct upload
*/
async upload(file) {
try {
// Validate file
const validationErrors = this.validateFile(file);
if (validationErrors.length > 0) {
return this.createErrorResult(validationErrors.join(', '));
}
// Generate unique filename
const fileName = this.generateFileName(file.originalname);
// Generate presigned upload URL
const presignedResult = await this.generateUploadUrl(fileName);
if (!presignedResult.success) {
return this.createErrorResult(presignedResult.error || 'Failed to generate presigned URL');
}
return this.createSuccessResult(fileName, presignedResult.uploadUrl);
}
catch (error) {
return this.createErrorResult(error instanceof Error ? error.message : 'Failed to generate presigned URL');
}
}
}
//# sourceMappingURL=oci.driver.js.map