diff options
| author | Heinrich 'Henrik' Langos <gumbo2000@noreply@mills.io> | 2023-01-17 00:48:29 +0100 |
|---|---|---|
| committer | Heinrich 'Henrik' Langos <gumbo2000@noreply@mills.io> | 2023-02-12 12:23:49 +0100 |
| commit | b8d8fe689ab8d116ffc879d91df65b9e28c9d623 (patch) | |
| tree | f05564ce45d8639a0a7f1a99460a3ae54f612373 /app/app.go | |
| parent | c7a41ce1b306ac786fa6a6821cb580aa4166c831 (diff) | |
refactor: Prepare to isolate handling of upload form from further processing
This will allow to extract the handling of uploaded files.
Once that is done, we can prepare to handle uploaded,
and imported files more similar.
Diffstat (limited to 'app/app.go')
| -rw-r--r-- | app/app.go | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -262,20 +262,21 @@ func (a *App) uploadHandler(respWriter http.ResponseWriter, request *http.Reques } // save uploaded data in upload directory - fileContentFromUpload, fileHeaderFromUpload, err := request.FormFile("video_file") + videoContentFromUpload, fileHeaderFromUpload, err := request.FormFile("video_file") if err != nil { err := fmt.Errorf("error processing form: %w", err) log.Error(err) http.Error(respWriter, err.Error(), http.StatusInternalServerError) return } - defer fileContentFromUpload.Close() + defer videoContentFromUpload.Close() + videoFilenameFromUpload := fileHeaderFromUpload.Filename // keeping the file extension from the upload file probably makes it easier for ffmpeg to // read the file for transcoding later uploadedFile, err := ioutil.TempFile( a.Config.Server.UploadPath, - fmt.Sprintf("tube-upload-*%s", filepath.Ext(fileHeaderFromUpload.Filename)), + fmt.Sprintf("tube-upload-*%s", filepath.Ext(videoFilenameFromUpload)), ) if err != nil { err := fmt.Errorf("error creating temporary file for uploading: %w", err) @@ -285,7 +286,7 @@ func (a *App) uploadHandler(respWriter http.ResponseWriter, request *http.Reques } defer os.Remove(uploadedFile.Name()) - _, err = io.Copy(uploadedFile, fileContentFromUpload) + _, err = io.Copy(uploadedFile, videoContentFromUpload) if err != nil { err := fmt.Errorf("error writing file: %w", err) log.Error(err) @@ -313,7 +314,7 @@ func (a *App) uploadHandler(respWriter http.ResponseWriter, request *http.Reques a.Library.Paths[targetLibraryDir].PreserveUploadFilename { newVideoAbsolutePath, err = securejoin.SecureJoin( a.Library.Paths[targetLibraryDir].Path, - fmt.Sprintf("%s.mp4", filenameWithoutExtension(fileHeaderFromUpload.Filename)), + fmt.Sprintf("%s.mp4", filenameWithoutExtension(videoFilenameFromUpload)), ) } else { newVideoAbsolutePath, err = securejoin.SecureJoin( |
