@elqnt/react 1.0.7 → 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/index.mjs CHANGED
@@ -5906,125 +5906,7 @@ import { Loader2 as Loader26, UploadCloud } from "lucide-react";
5906
5906
  import { useState as useState14 } from "react";
5907
5907
  import { useDropzone as useDropzone2 } from "react-dropzone";
5908
5908
  import { toast as toast2 } from "sonner";
5909
-
5910
- // components/upload/upload-actions.ts
5911
- import { BlobServiceClient } from "@azure/storage-blob";
5912
- import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
5913
- async function uploadFile(formData) {
5914
- try {
5915
- const file = formData.get("file");
5916
- if (!file) {
5917
- throw new Error("No file provided");
5918
- }
5919
- const STORAGE_CONNECTION_STRING = process.env.AZURE_STORAGE_CONNECTION_STRING;
5920
- const STORAGE_CONTAINER_NAME = process.env.AZURE_STORAGE_CONTAINER_NAME;
5921
- if (!STORAGE_CONNECTION_STRING || !STORAGE_CONTAINER_NAME) {
5922
- throw new Error(
5923
- "STORAGE_CONNECTION_STRING or STORAGE_CONTAINER_NAME not set"
5924
- );
5925
- }
5926
- const fileExtension = file.name.split(".").pop()?.toLowerCase();
5927
- const fileName = `${Date.now()}-${Math.random().toString(36).substring(2)}.${fileExtension}`;
5928
- const contentType = getContentType(fileExtension);
5929
- const buffer = Buffer.from(await file.arrayBuffer());
5930
- const blobServiceClient = BlobServiceClient.fromConnectionString(
5931
- STORAGE_CONNECTION_STRING
5932
- );
5933
- const containerClient = blobServiceClient.getContainerClient(
5934
- STORAGE_CONTAINER_NAME
5935
- );
5936
- await containerClient.createIfNotExists();
5937
- const blockBlobClient = containerClient.getBlockBlobClient(fileName);
5938
- await blockBlobClient.upload(buffer, buffer.length, {
5939
- blobHTTPHeaders: {
5940
- blobContentType: contentType
5941
- }
5942
- });
5943
- const fileUrl = blockBlobClient.url;
5944
- return { success: true, fileUrl };
5945
- } catch (error) {
5946
- console.error("Upload error:", error);
5947
- return {
5948
- success: false,
5949
- error: error instanceof Error ? error.message : "Failed to upload file"
5950
- };
5951
- }
5952
- }
5953
- function getContentType(fileExtension) {
5954
- if (!fileExtension) return "application/octet-stream";
5955
- const mimeTypes = {
5956
- // Images
5957
- png: "image/png",
5958
- jpg: "image/jpeg",
5959
- jpeg: "image/jpeg",
5960
- gif: "image/gif",
5961
- webp: "image/webp",
5962
- svg: "image/svg+xml",
5963
- // Documents
5964
- pdf: "application/pdf",
5965
- doc: "application/msword",
5966
- docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
5967
- // Others
5968
- txt: "text/plain",
5969
- csv: "text/csv",
5970
- json: "application/json"
5971
- };
5972
- return mimeTypes[fileExtension] || "application/octet-stream";
5973
- }
5974
- async function uploadToS3(formData) {
5975
- try {
5976
- const file = formData.get("file");
5977
- if (!file) {
5978
- throw new Error("No file provided");
5979
- }
5980
- const AWS_ACCESS_KEY_ID = process.env.LINODE_ACCESS_KEY;
5981
- const AWS_SECRET_ACCESS_KEY = process.env.LINODE_SECRET_KEY;
5982
- const S3_BUCKET_NAME = process.env.LINODE_BUCKET_NAME;
5983
- let S3_ENDPOINT = process.env.LINODE_OBJECT_STORAGE_ENDPOINT;
5984
- if (!AWS_ACCESS_KEY_ID || !AWS_SECRET_ACCESS_KEY || !S3_BUCKET_NAME || !S3_ENDPOINT) {
5985
- throw new Error("S3 credentials or configuration not set");
5986
- }
5987
- const fileExtension = file.name.split(".").pop()?.toLowerCase();
5988
- const fileName = `${Date.now()}-${Math.random().toString(36).substring(2)}.${fileExtension}`;
5989
- const contentType = getContentType(fileExtension);
5990
- const buffer = Buffer.from(await file.arrayBuffer());
5991
- const s3Client = new S3Client({
5992
- endpoint: S3_ENDPOINT,
5993
- region: "us-east-1",
5994
- // Linode requires a region but it's not used with custom endpoint
5995
- credentials: {
5996
- accessKeyId: AWS_ACCESS_KEY_ID,
5997
- secretAccessKey: AWS_SECRET_ACCESS_KEY
5998
- },
5999
- forcePathStyle: true,
6000
- // Required for Linode Object Storage
6001
- maxAttempts: 3,
6002
- requestHandler: {
6003
- timeout: 1e4
6004
- // 10 seconds timeout
6005
- }
6006
- });
6007
- const command = new PutObjectCommand({
6008
- Bucket: S3_BUCKET_NAME,
6009
- Key: fileName,
6010
- Body: buffer,
6011
- ContentType: contentType,
6012
- ACL: "public-read"
6013
- // Make the object publicly readable
6014
- });
6015
- await s3Client.send(command);
6016
- const fileUrl = `${S3_ENDPOINT}/${S3_BUCKET_NAME}/${fileName}`;
6017
- return { success: true, fileUrl };
6018
- } catch (error) {
6019
- console.error("Upload error:", JSON.stringify(error, null, 2));
6020
- return {
6021
- success: false,
6022
- error: error instanceof Error ? error.message : "Failed to upload file"
6023
- };
6024
- }
6025
- }
6026
-
6027
- // components/upload/upload-widget-v2.tsx
5909
+ import { uploadFile, uploadToS3 } from "./upload/upload-actions";
6028
5910
  import { jsx as jsx81, jsxs as jsxs56 } from "react/jsx-runtime";
6029
5911
  function UploadWidgetV2({
6030
5912
  accept,