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