mirror of
https://github.com/kyantech/Palmr.git
synced 2026-01-09 06:02:28 +08:00
refactor: clean up file upload logic and remove unused variables
This commit is contained in:
parent
d0d5d012f0
commit
c0a7970330
@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useCallback, useState } from "react";
|
||||
import { IconCheck, IconFile, IconMail, IconUpload, IconUser, IconX } from "@tabler/icons-react";
|
||||
import { useTranslations } from "next-intl";
|
||||
import { useDropzone } from "react-dropzone";
|
||||
@ -15,7 +15,7 @@ import { Textarea } from "@/components/ui/textarea";
|
||||
import { useUppyUpload } from "@/hooks/useUppyUpload";
|
||||
import { getPresignedUrlForUploadByAlias, registerFileUploadByAlias } from "@/http/endpoints";
|
||||
import { formatFileSize } from "@/utils/format-file-size";
|
||||
import { FILE_STATUS, UPLOAD_CONFIG } from "../constants";
|
||||
import { UPLOAD_CONFIG } from "../constants";
|
||||
import { FileUploadSectionProps } from "../types";
|
||||
|
||||
export function FileUploadSection({ reverseShare, password, alias, onUploadSuccess }: FileUploadSectionProps) {
|
||||
@ -117,11 +117,6 @@ export function FileUploadSection({ reverseShare, password, alias, onUploadSucce
|
||||
disabled: isUploading,
|
||||
});
|
||||
|
||||
const handleUpload = async () => {
|
||||
if (!validateUploadRequirements()) return;
|
||||
startUpload();
|
||||
};
|
||||
|
||||
const validateUploadRequirements = (): boolean => {
|
||||
if (fileUploads.length === 0) {
|
||||
toast.error(t("reverseShares.upload.errors.selectAtLeastOneFile"));
|
||||
@ -144,6 +139,11 @@ export function FileUploadSection({ reverseShare, password, alias, onUploadSucce
|
||||
return true;
|
||||
};
|
||||
|
||||
const handleUpload = async () => {
|
||||
if (!validateUploadRequirements()) return;
|
||||
startUpload();
|
||||
};
|
||||
|
||||
const getCanUpload = (): boolean => {
|
||||
if (fileUploads.length === 0 || isUploading) return false;
|
||||
|
||||
@ -233,7 +233,7 @@ export function FileUploadSection({ reverseShare, password, alias, onUploadSucce
|
||||
return null;
|
||||
};
|
||||
|
||||
const renderFileItem = (upload: any, index: number) => (
|
||||
const renderFileItem = (upload: any) => (
|
||||
<div key={upload.id} className="flex items-center gap-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-lg">
|
||||
<IconFile className="h-5 w-5 text-gray-500 flex-shrink-0" />
|
||||
<div className="flex-1 min-w-0">
|
||||
|
||||
@ -225,15 +225,6 @@ export function UploadFileModal({ isOpen, onClose, onSuccess, currentFolderId }:
|
||||
}
|
||||
};
|
||||
|
||||
// Prevent closing while uploading
|
||||
const handleClose = () => {
|
||||
if (isUploading) {
|
||||
setShowConfirmation(true);
|
||||
} else {
|
||||
handleConfirmClose();
|
||||
}
|
||||
};
|
||||
|
||||
const handleConfirmClose = () => {
|
||||
// Cancel all uploads
|
||||
fileUploads.forEach((upload) => {
|
||||
@ -250,6 +241,15 @@ export function UploadFileModal({ isOpen, onClose, onSuccess, currentFolderId }:
|
||||
onClose();
|
||||
};
|
||||
|
||||
// Prevent closing while uploading
|
||||
const handleClose = () => {
|
||||
if (isUploading) {
|
||||
setShowConfirmation(true);
|
||||
} else {
|
||||
handleConfirmClose();
|
||||
}
|
||||
};
|
||||
|
||||
const handleContinueUploads = () => {
|
||||
setShowConfirmation(false);
|
||||
};
|
||||
|
||||
@ -77,9 +77,6 @@ export function useUppyUpload(options: UseUppyUploadOptions) {
|
||||
const [fileUploads, setFileUploads] = useState<FileUploadState[]>([]);
|
||||
const [isUploading, setIsUploading] = useState(false);
|
||||
|
||||
// Debug: unique ID for this hook instance
|
||||
const instanceId = useRef(`uppy-${Math.random().toString(36).substr(2, 9)}`);
|
||||
|
||||
// Store callbacks in refs to avoid recreating Uppy instance
|
||||
const onValidateRef = useRef(options.onValidate);
|
||||
const onBeforeUploadRef = useRef(options.onBeforeUpload);
|
||||
@ -167,7 +164,6 @@ export function useUppyUpload(options: UseUppyUploadOptions) {
|
||||
|
||||
// For multipart uploads (≥100MB)
|
||||
async createMultipartUpload(file: UppyFile<any, any>) {
|
||||
const fileSize = file.size || 0;
|
||||
try {
|
||||
// 1. Validate file
|
||||
if (onValidateRef.current) {
|
||||
@ -212,6 +208,7 @@ export function useUppyUpload(options: UseUppyUploadOptions) {
|
||||
//TODO: List parts (for resuming multipart uploads)
|
||||
async listParts(file: UppyFile<any, any>, { uploadId, key }: any) {
|
||||
console.log(`[Upload:Multipart] Listing parts for: ${file.name}`);
|
||||
console.log(`Upload ID: ${uploadId}, Key: ${key}`);
|
||||
// Para simplificar, não vamos implementar resumo de upload por enquanto
|
||||
// Retornamos array vazio indicando que não há partes já enviadas
|
||||
return [];
|
||||
@ -219,7 +216,7 @@ export function useUppyUpload(options: UseUppyUploadOptions) {
|
||||
|
||||
// Sign individual parts for multipart upload
|
||||
async signPart(file: UppyFile<any, any>, partData: any) {
|
||||
const { uploadId, key, partNumber, signal } = partData;
|
||||
const { uploadId, key, partNumber } = partData;
|
||||
|
||||
try {
|
||||
const response = await getMultipartPartUrl({
|
||||
@ -313,7 +310,7 @@ export function useUppyUpload(options: UseUppyUploadOptions) {
|
||||
};
|
||||
|
||||
// Upload success
|
||||
const handleSuccess = async (file: any, response: any) => {
|
||||
const handleSuccess = async (file: any) => {
|
||||
const objectName = file.meta.objectName;
|
||||
|
||||
try {
|
||||
@ -342,7 +339,7 @@ export function useUppyUpload(options: UseUppyUploadOptions) {
|
||||
};
|
||||
|
||||
// All uploads complete
|
||||
const handleComplete = (result: any) => {
|
||||
const handleComplete = () => {
|
||||
setIsUploading(false);
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user