Compare commits

..

No commits in common. "main" and "v1.9.1" have entirely different histories.
main ... v1.9.1

View file

@ -121,43 +121,34 @@ func (c *Context) GetQueueClient() *asynq.Client {
return client
}
func (c *Context) GetUploadedFile(name string) (*UploadedFileInfo, error) {
func (c *Context) GetUploadedFile(name string) *UploadedFileInfo {
file, fileHeader, err := c.Request.httpRequest.FormFile(name)
if err != nil {
return nil, fmt.Errorf("error retrieving file: %v", err)
panic(fmt.Sprintf("error with file,[%v]", err.Error()))
}
defer file.Close()
// Extract the file extension
ext := strings.TrimPrefix(path.Ext(fileHeader.Filename), ".")
tmpFilePath := filepath.Join(os.TempDir(), fileHeader.Filename)
tmpFile, err := os.Create(tmpFilePath)
if err != nil {
return nil, fmt.Errorf("error creating temporary file: %v", err)
panic(fmt.Sprintf("error with file,[%v]", err.Error()))
}
defer tmpFile.Close()
// Copy the uploaded file content to the temporary file
buff := make([]byte, 100)
for {
n, err := file.Read(buff)
if err != nil && err != io.EOF {
return nil, fmt.Errorf("error reading uploaded file: %v", err)
panic("error with uploaded file")
}
if n == 0 {
break
}
_, err = tmpFile.Write(buff[:n])
if err != nil {
return nil, fmt.Errorf("error writing to temporary file: %v", err)
n, _ = tmpFile.Write(buff[:n])
}
}
// Get file info for the temporary file
tmpFileInfo, err := os.Stat(tmpFilePath)
if err != nil {
return nil, fmt.Errorf("error getting file info: %v", err)
panic(fmt.Sprintf("error with file,[%v]", err.Error()))
}
defer tmpFile.Close()
uploadedFileInfo := &UploadedFileInfo{
FullPath: tmpFilePath,
Name: fileHeader.Filename,
@ -165,7 +156,7 @@ func (c *Context) GetUploadedFile(name string) (*UploadedFileInfo, error) {
Extension: ext,
Size: int(tmpFileInfo.Size()),
}
return uploadedFileInfo, nil
return uploadedFileInfo
}
func (c *Context) MoveFile(sourceFilePath string, destFolderPath string) error {
@ -194,7 +185,7 @@ func (c *Context) MoveFile(sourceFilePath string, destFolderPath string) error {
for {
n, err := srcFile.Read(buff)
if err != nil && err != io.EOF {
return fmt.Errorf("error moving file: %v", sourceFilePath)
panic(fmt.Sprintf("error moving file %v", sourceFilePath))
}
if n == 0 {
break
@ -238,7 +229,7 @@ func (c *Context) CopyFile(sourceFilePath string, destFolderPath string) error {
for {
n, err := srcFile.Read(buff)
if err != nil && err != io.EOF {
return fmt.Errorf("error moving file: %v", sourceFilePath)
panic(fmt.Sprintf("error moving file %v", sourceFilePath))
}
if n == 0 {
break