diff --git a/migrations/000018_alter_files_table_ffprobe_data.down.sql b/migrations/000018_alter_files_table_ffprobe_data.down.sql index b489a96..7ea38d3 100644 --- a/migrations/000018_alter_files_table_ffprobe_data.down.sql +++ b/migrations/000018_alter_files_table_ffprobe_data.down.sql @@ -1,2 +1,2 @@ ALTER TABLE files -DROP IF EXISTS ffprobe; +DROP IF EXISTS ffprobe_data; diff --git a/migrations/000020_alter_files_table_transcode.down.sql b/migrations/000020_alter_files_table_transcode.down.sql new file mode 100644 index 0000000..1f13efa --- /dev/null +++ b/migrations/000020_alter_files_table_transcode.down.sql @@ -0,0 +1,4 @@ +ALTER TABLE tasks +DROP IF EXISTS old_md5, +DROP IF EXISTS old_ffprobe_data, +DROP IF EXISTS old_size bigint; diff --git a/migrations/000020_alter_files_table_transcode.up.sql b/migrations/000020_alter_files_table_transcode.up.sql new file mode 100644 index 0000000..1bcebe0 --- /dev/null +++ b/migrations/000020_alter_files_table_transcode.up.sql @@ -0,0 +1,4 @@ +ALTER TABLE libraries +ADD old_md5 uuid, +ADD old_ffprobe_data JSONB, +ADD old_size bigint; diff --git a/server/upload.go b/server/upload.go index 9c88a40..8fea6d5 100644 --- a/server/upload.go +++ b/server/upload.go @@ -175,7 +175,19 @@ func handleUpload(w http.ResponseWriter, r *http.Request) { 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) + _, err = tx.Exec(r.Context(), "UPDATE files SET old_md5 = md5, old_size = size WHERE id = $1", fileid) + if err != nil { + errorUpload(r, w, taskid, "Set File Hash", err) + return + } + + _, err = tx.Exec(r.Context(), "UPDATE files SET md5 = $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.Exec(r.Context(), "UPDATE files SET md5 = $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 @@ -188,6 +200,8 @@ func handleUpload(w http.ResponseWriter, r *http.Request) { } slog.InfoContext(r.Context(), "Original file Replaced with Uploaded File", "fileid", id, "dstPath", dstPath) + } else { + // TODO implement "old" fields for non replace libraries, scan also needs to use old field if it is is non replace and the file has been transcoded } }