From e39b865c1bf04964c3d7e7db1a35c1e25e8e865c Mon Sep 17 00:00:00 2001 From: Travis Ralston <travpc@gmail.com> Date: Fri, 27 Dec 2019 12:04:00 -0700 Subject: [PATCH] Track the user ID for exports/imports Fixes https://github.com/turt2live/matrix-media-repo/issues/212 --- controllers/data_controller/export_controller.go | 3 +++ controllers/data_controller/import_controller.go | 8 +++++++- templating/models.go | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/controllers/data_controller/export_controller.go b/controllers/data_controller/export_controller.go index 7ec542a6..22639b56 100644 --- a/controllers/data_controller/export_controller.go +++ b/controllers/data_controller/export_controller.go @@ -32,6 +32,7 @@ type manifestRecord struct { Origin string `json:"origin"` MediaId string `json:"media_id"` CreatedTs int64 `json:"created_ts"` + Uploader string `json:"uploader"` } type manifest struct { @@ -267,6 +268,7 @@ func compileArchive(exportId string, entityId string, archiveDs *datastore.Datas Origin: m.Origin, MediaId: m.MediaId, CreatedTs: m.CreationTs, + Uploader: m.UserId, } indexModel.Media = append(indexModel.Media, &templating.ExportIndexMediaModel{ ExportID: exportId, @@ -280,6 +282,7 @@ func compileArchive(exportId string, entityId string, archiveDs *datastore.Datas ContentType: m.ContentType, UploadTs: m.CreationTs, UploadDateHuman: util.FromMillis(m.CreationTs).Format(time.UnixDate), + Uploader: m.UserId, }) } manifest := &manifest{ diff --git a/controllers/data_controller/import_controller.go b/controllers/data_controller/import_controller.go index c769d489..51a4029a 100644 --- a/controllers/data_controller/import_controller.go +++ b/controllers/data_controller/import_controller.go @@ -271,12 +271,18 @@ func doImport(updateChannel chan *importUpdate, taskId int, importId string, ctx break } + // Use the user ID (if any) as the uploader as a default. If this is an import + // for a server then we use the recorded one, if any is available. + uploader := userId + if userId == "" { + uploader = record.Uploader + } media := &types.Media{ Origin: record.Origin, MediaId: record.MediaId, UploadName: record.FileName, ContentType: record.ContentType, - UserId: userId, + UserId: uploader, Sha256Hash: record.Sha256, SizeBytes: record.SizeBytes, DatastoreId: ds.DatastoreId, diff --git a/templating/models.go b/templating/models.go index d047e0da..486f2f4b 100644 --- a/templating/models.go +++ b/templating/models.go @@ -26,6 +26,7 @@ type ExportIndexMediaModel struct { UploadDateHuman string Sha256Hash string ContentType string + Uploader string } type ExportIndexModel struct { -- GitLab