diff --git a/cmd/import_synapse/main.go b/cmd/import_synapse/main.go index cd90df0ffd1d607ed5505d4155c7b329c2fc0b69..5855e4e2ec2c0a44edacd2cd5af593843b9090a4 100644 --- a/cmd/import_synapse/main.go +++ b/cmd/import_synapse/main.go @@ -156,7 +156,7 @@ func fetchMedia(req interface{}) interface{} { } defer cleanup.DumpAndCloseStream(body) - _, err = upload_controller.StoreDirect(nil, body, -1, record.ContentType, record.UploadName, record.UserId, payload.serverName, record.MediaId, common.KindLocalMedia, ctx) + _, err = upload_controller.StoreDirect(nil, body, -1, record.ContentType, record.UploadName, record.UserId, payload.serverName, record.MediaId, common.KindLocalMedia, ctx, false) if err != nil { logrus.Error(err.Error()) return nil diff --git a/controllers/data_controller/import_controller.go b/controllers/data_controller/import_controller.go index 05003e03f6079177f684818e18138ff1d184166a..7eec6e5bc1ff94b5ecf160e6950ab6be1010099c 100644 --- a/controllers/data_controller/import_controller.go +++ b/controllers/data_controller/import_controller.go @@ -229,7 +229,7 @@ func doImport(updateChannel chan *importUpdate, taskId int, importId string, ctx if found { ctx.Log.Info("Using file from memory") closer := util.BufferToStream(buf) - _, err := upload_controller.StoreDirect(nil, closer, record.SizeBytes, record.ContentType, record.FileName, userId, record.Origin, record.MediaId, kind, ctx) + _, err := upload_controller.StoreDirect(nil, closer, record.SizeBytes, record.ContentType, record.FileName, userId, record.Origin, record.MediaId, kind, ctx, true) if err != nil { ctx.Log.Errorf("Error importing file: %s", err.Error()) continue @@ -312,7 +312,7 @@ func doImport(updateChannel chan *importUpdate, taskId int, importId string, ctx continue } - _, err = upload_controller.StoreDirect(nil, r.Body, r.ContentLength, record.ContentType, record.FileName, userId, record.Origin, record.MediaId, kind, ctx) + _, err = upload_controller.StoreDirect(nil, r.Body, r.ContentLength, record.ContentType, record.FileName, userId, record.Origin, record.MediaId, kind, ctx, true) if err != nil { ctx.Log.Errorf("Error importing file: %s", err.Error()) continue diff --git a/controllers/download_controller/download_resource_handler.go b/controllers/download_controller/download_resource_handler.go index c63ce8e14c398e42c1d4bde701c2604ef6c734f0..66fcbefc1c1a8ed30364b0932feb52cbff36b664 100644 --- a/controllers/download_controller/download_resource_handler.go +++ b/controllers/download_controller/download_resource_handler.go @@ -140,7 +140,7 @@ func downloadResourceWorkFn(request *resource_handler.WorkRequest) interface{} { persistFile := func(fileStream io.ReadCloser) *workerDownloadResponse { defer cleanup.DumpAndCloseStream(fileStream) userId := upload_controller.NoApplicableUploadUser - media, err := upload_controller.StoreDirect(nil, fileStream, downloaded.ContentLength, downloaded.ContentType, downloaded.DesiredFilename, userId, info.origin, info.mediaId, common.KindRemoteMedia, ctx) + media, err := upload_controller.StoreDirect(nil, fileStream, downloaded.ContentLength, downloaded.ContentType, downloaded.DesiredFilename, userId, info.origin, info.mediaId, common.KindRemoteMedia, ctx, true) if err != nil { ctx.Log.Error("Error persisting file: ", err) return &workerDownloadResponse{err: err} diff --git a/controllers/upload_controller/upload_controller.go b/controllers/upload_controller/upload_controller.go index 9a5f05f60f95d57ae21666d98b45c76451533ada..034d5bebc522da06a7807322d298e6e8def8ec43 100644 --- a/controllers/upload_controller/upload_controller.go +++ b/controllers/upload_controller/upload_controller.go @@ -149,7 +149,7 @@ func UploadMedia(contents io.ReadCloser, contentLength int64, contentType string mediaId = fmt.Sprintf("ipfs:%s", info.Location[len("ipfs/"):]) } - return StoreDirect(existingFile, data, contentLength, contentType, filename, userId, origin, mediaId, common.KindLocalMedia, ctx) + return StoreDirect(existingFile, data, contentLength, contentType, filename, userId, origin, mediaId, common.KindLocalMedia, ctx, true) } func trackUploadAsLastAccess(ctx rcontext.RequestContext, media *types.Media) { @@ -202,7 +202,7 @@ func IsAllowed(contentType string, reportedContentType string, userId string, ct return allowed } -func StoreDirect(f *AlreadyUploadedFile, contents io.ReadCloser, expectedSize int64, contentType string, filename string, userId string, origin string, mediaId string, kind string, ctx rcontext.RequestContext) (*types.Media, error) { +func StoreDirect(f *AlreadyUploadedFile, contents io.ReadCloser, expectedSize int64, contentType string, filename string, userId string, origin string, mediaId string, kind string, ctx rcontext.RequestContext, filterUserDuplicates bool) (*types.Media, error) { var ds *datastore.DatastoreRef var info *types.ObjectInfo if f == nil { @@ -255,7 +255,7 @@ func StoreDirect(f *AlreadyUploadedFile, contents io.ReadCloser, expectedSize in // If the user is a real user (ie: actually uploaded media), then we'll see if there's // an exact duplicate that we can return. Otherwise we'll just pick the first record and // clone that. - if userId != NoApplicableUploadUser { + if filterUserDuplicates && userId != NoApplicableUploadUser { for _, record := range records { if record.Quarantined { ctx.Log.Warn("User attempted to upload quarantined content - rejecting")