@elqnt/react 1.0.8 → 1.0.9
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/dist/components/index.js +2 -120
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +1 -119
- package/dist/components/index.mjs.map +1 -1
- package/dist/components/upload/upload-actions.js +5 -3
- package/dist/components/upload/upload-actions.js.map +1 -1
- package/dist/components/upload/upload-actions.mjs +5 -3
- package/dist/components/upload/upload-actions.mjs.map +1 -1
- package/dist/index.js +2 -120
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -119
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
- package/dist/components/upload/upload-actions.d.mts +0 -20
- package/dist/components/upload/upload-actions.d.ts +0 -20
package/dist/components/index.js
CHANGED
|
@@ -5969,125 +5969,7 @@ var import_lucide_react16 = require("lucide-react");
|
|
|
5969
5969
|
var import_react17 = require("react");
|
|
5970
5970
|
var import_react_dropzone2 = require("react-dropzone");
|
|
5971
5971
|
var import_sonner2 = require("sonner");
|
|
5972
|
-
|
|
5973
|
-
// components/upload/upload-actions.ts
|
|
5974
|
-
var import_storage_blob = require("@azure/storage-blob");
|
|
5975
|
-
var import_client_s3 = require("@aws-sdk/client-s3");
|
|
5976
|
-
async function uploadFile(formData) {
|
|
5977
|
-
try {
|
|
5978
|
-
const file = formData.get("file");
|
|
5979
|
-
if (!file) {
|
|
5980
|
-
throw new Error("No file provided");
|
|
5981
|
-
}
|
|
5982
|
-
const STORAGE_CONNECTION_STRING = process.env.AZURE_STORAGE_CONNECTION_STRING;
|
|
5983
|
-
const STORAGE_CONTAINER_NAME = process.env.AZURE_STORAGE_CONTAINER_NAME;
|
|
5984
|
-
if (!STORAGE_CONNECTION_STRING || !STORAGE_CONTAINER_NAME) {
|
|
5985
|
-
throw new Error(
|
|
5986
|
-
"STORAGE_CONNECTION_STRING or STORAGE_CONTAINER_NAME not set"
|
|
5987
|
-
);
|
|
5988
|
-
}
|
|
5989
|
-
const fileExtension = file.name.split(".").pop()?.toLowerCase();
|
|
5990
|
-
const fileName = `${Date.now()}-${Math.random().toString(36).substring(2)}.${fileExtension}`;
|
|
5991
|
-
const contentType = getContentType(fileExtension);
|
|
5992
|
-
const buffer = Buffer.from(await file.arrayBuffer());
|
|
5993
|
-
const blobServiceClient = import_storage_blob.BlobServiceClient.fromConnectionString(
|
|
5994
|
-
STORAGE_CONNECTION_STRING
|
|
5995
|
-
);
|
|
5996
|
-
const containerClient = blobServiceClient.getContainerClient(
|
|
5997
|
-
STORAGE_CONTAINER_NAME
|
|
5998
|
-
);
|
|
5999
|
-
await containerClient.createIfNotExists();
|
|
6000
|
-
const blockBlobClient = containerClient.getBlockBlobClient(fileName);
|
|
6001
|
-
await blockBlobClient.upload(buffer, buffer.length, {
|
|
6002
|
-
blobHTTPHeaders: {
|
|
6003
|
-
blobContentType: contentType
|
|
6004
|
-
}
|
|
6005
|
-
});
|
|
6006
|
-
const fileUrl = blockBlobClient.url;
|
|
6007
|
-
return { success: true, fileUrl };
|
|
6008
|
-
} catch (error) {
|
|
6009
|
-
console.error("Upload error:", error);
|
|
6010
|
-
return {
|
|
6011
|
-
success: false,
|
|
6012
|
-
error: error instanceof Error ? error.message : "Failed to upload file"
|
|
6013
|
-
};
|
|
6014
|
-
}
|
|
6015
|
-
}
|
|
6016
|
-
function getContentType(fileExtension) {
|
|
6017
|
-
if (!fileExtension) return "application/octet-stream";
|
|
6018
|
-
const mimeTypes = {
|
|
6019
|
-
// Images
|
|
6020
|
-
png: "image/png",
|
|
6021
|
-
jpg: "image/jpeg",
|
|
6022
|
-
jpeg: "image/jpeg",
|
|
6023
|
-
gif: "image/gif",
|
|
6024
|
-
webp: "image/webp",
|
|
6025
|
-
svg: "image/svg+xml",
|
|
6026
|
-
// Documents
|
|
6027
|
-
pdf: "application/pdf",
|
|
6028
|
-
doc: "application/msword",
|
|
6029
|
-
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
6030
|
-
// Others
|
|
6031
|
-
txt: "text/plain",
|
|
6032
|
-
csv: "text/csv",
|
|
6033
|
-
json: "application/json"
|
|
6034
|
-
};
|
|
6035
|
-
return mimeTypes[fileExtension] || "application/octet-stream";
|
|
6036
|
-
}
|
|
6037
|
-
async function uploadToS3(formData) {
|
|
6038
|
-
try {
|
|
6039
|
-
const file = formData.get("file");
|
|
6040
|
-
if (!file) {
|
|
6041
|
-
throw new Error("No file provided");
|
|
6042
|
-
}
|
|
6043
|
-
const AWS_ACCESS_KEY_ID = process.env.LINODE_ACCESS_KEY;
|
|
6044
|
-
const AWS_SECRET_ACCESS_KEY = process.env.LINODE_SECRET_KEY;
|
|
6045
|
-
const S3_BUCKET_NAME = process.env.LINODE_BUCKET_NAME;
|
|
6046
|
-
let S3_ENDPOINT = process.env.LINODE_OBJECT_STORAGE_ENDPOINT;
|
|
6047
|
-
if (!AWS_ACCESS_KEY_ID || !AWS_SECRET_ACCESS_KEY || !S3_BUCKET_NAME || !S3_ENDPOINT) {
|
|
6048
|
-
throw new Error("S3 credentials or configuration not set");
|
|
6049
|
-
}
|
|
6050
|
-
const fileExtension = file.name.split(".").pop()?.toLowerCase();
|
|
6051
|
-
const fileName = `${Date.now()}-${Math.random().toString(36).substring(2)}.${fileExtension}`;
|
|
6052
|
-
const contentType = getContentType(fileExtension);
|
|
6053
|
-
const buffer = Buffer.from(await file.arrayBuffer());
|
|
6054
|
-
const s3Client = new import_client_s3.S3Client({
|
|
6055
|
-
endpoint: S3_ENDPOINT,
|
|
6056
|
-
region: "us-east-1",
|
|
6057
|
-
// Linode requires a region but it's not used with custom endpoint
|
|
6058
|
-
credentials: {
|
|
6059
|
-
accessKeyId: AWS_ACCESS_KEY_ID,
|
|
6060
|
-
secretAccessKey: AWS_SECRET_ACCESS_KEY
|
|
6061
|
-
},
|
|
6062
|
-
forcePathStyle: true,
|
|
6063
|
-
// Required for Linode Object Storage
|
|
6064
|
-
maxAttempts: 3,
|
|
6065
|
-
requestHandler: {
|
|
6066
|
-
timeout: 1e4
|
|
6067
|
-
// 10 seconds timeout
|
|
6068
|
-
}
|
|
6069
|
-
});
|
|
6070
|
-
const command = new import_client_s3.PutObjectCommand({
|
|
6071
|
-
Bucket: S3_BUCKET_NAME,
|
|
6072
|
-
Key: fileName,
|
|
6073
|
-
Body: buffer,
|
|
6074
|
-
ContentType: contentType,
|
|
6075
|
-
ACL: "public-read"
|
|
6076
|
-
// Make the object publicly readable
|
|
6077
|
-
});
|
|
6078
|
-
await s3Client.send(command);
|
|
6079
|
-
const fileUrl = `${S3_ENDPOINT}/${S3_BUCKET_NAME}/${fileName}`;
|
|
6080
|
-
return { success: true, fileUrl };
|
|
6081
|
-
} catch (error) {
|
|
6082
|
-
console.error("Upload error:", JSON.stringify(error, null, 2));
|
|
6083
|
-
return {
|
|
6084
|
-
success: false,
|
|
6085
|
-
error: error instanceof Error ? error.message : "Failed to upload file"
|
|
6086
|
-
};
|
|
6087
|
-
}
|
|
6088
|
-
}
|
|
6089
|
-
|
|
6090
|
-
// components/upload/upload-widget-v2.tsx
|
|
5972
|
+
var import_upload_actions = require("./upload/upload-actions");
|
|
6091
5973
|
var import_jsx_runtime81 = require("react/jsx-runtime");
|
|
6092
5974
|
function UploadWidgetV2({
|
|
6093
5975
|
accept,
|
|
@@ -6105,7 +5987,7 @@ function UploadWidgetV2({
|
|
|
6105
5987
|
const handleUpload = async (files) => {
|
|
6106
5988
|
setIsUploading(true);
|
|
6107
5989
|
try {
|
|
6108
|
-
const uploadFunction = uploadDestination === "s3" ? uploadToS3 : uploadFile;
|
|
5990
|
+
const uploadFunction = uploadDestination === "s3" ? import_upload_actions.uploadToS3 : import_upload_actions.uploadFile;
|
|
6109
5991
|
const uploadPromises = files.map(async (file) => {
|
|
6110
5992
|
const formData = new FormData();
|
|
6111
5993
|
formData.append("file", file);
|