diff --git a/server/task.go b/server/task.go index 8e32fa9..3d566a9 100644 --- a/server/task.go +++ b/server/task.go @@ -344,7 +344,7 @@ func assignQueuedTasks(ctx context.Context) error { assignRunning = false }() - rows, err := db.Query(ctx, "SELECT t.id as id, t.type as type, t.file_id as file_id, f.md5 as md5, t.data as data, fc.data as ffmpeg_command FROM tasks t INNER JOIN files f ON f.id = t.file_id INNER JOIN ffmpeg_commands fc ON fc.id = t.ffmpeg_command_id WHERE t.status = $1 AND f.status = $2 ORDER BY type DESC", constants.TASK_STATUS_QUEUED, constants.FILE_STATUS_EXISTS) + rows, err := db.Query(ctx, "SELECT t.id as id, t.type as type, t.file_id as file_id, f.md5 as md5, t.data as data, fc.data as ffmpeg_command FROM tasks t INNER JOIN files f ON f.id = t.file_id INNER JOIN ffmpeg_commands fc ON fc.id = t.ffmpeg_command_id WHERE t.status = $1 AND f.status = $2", constants.TASK_STATUS_QUEUED, constants.FILE_STATUS_EXISTS) if err != nil { return fmt.Errorf("Query Queued Tasks: %w", err) } diff --git a/server/upload.go b/server/upload.go index 0217a94..3028070 100644 --- a/server/upload.go +++ b/server/upload.go @@ -158,6 +158,12 @@ func handleUpload(w http.ResponseWriter, r *http.Request) { return } + _, err = tx.Exec(r.Context(), "UPDATE files SET hash = $2 WHERE id = $1", fileid, hash) + if err != nil { + errorUpload(r, w, taskid, "Set File Hash", err) + return + } + dstPath := filepath.Join(lPath, fPath) slog.InfoContext(r.Context(), "Replacing Original file With Uploaded File", "fileid", id, "path", path, "dstPath", dstPath) @@ -167,20 +173,6 @@ func handleUpload(w http.ResponseWriter, r *http.Request) { return } - info, err := os.Stat(dstPath) - if err != nil { - errorUpload(r, w, taskid, "Stat File", err) - return - } - modTime := info.ModTime().UTC().Round(time.Second) - size := info.Size() - - _, err = tx.Exec(r.Context(), "UPDATE files SET hash = $2, size = $3, mod_time = $3 WHERE id = $1", fileid, hash, size, modTime) - if err != nil { - errorUpload(r, w, taskid, "Set File Hash", err) - return - } - err = tx.Commit(r.Context()) if err != nil { errorUpload(r, w, taskid, "Commit File Hash", err)