Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Umbraco.

Check warning on line 1 in src/Umbraco.Infrastructure/PropertyEditors/FileUploadPropertyValueEditor.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Primitive Obsession

In this module, 50.0% of all function arguments are primitive types, threshold = 30.0%. The functions in this file have too many primitive types (e.g. int, double, float) in their function argument lists. Using many primitive types lead to the code smell Primitive Obsession. Avoid adding more primitive arguments.
// See LICENSE for more details.

using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -189,8 +189,7 @@
}

// get the filepath
// in case we are using the old path scheme, try to re-use numbers (bah...)
var filepath = _mediaFileManager.GetMediaPath(file.FileName, contentKey, propertyTypeKey); // fs-relative path
string filepath = GetMediaPath(file, dataTypeConfiguration, contentKey, propertyTypeKey);

using (Stream filestream = file.OpenReadStream())
{
Expand All @@ -201,9 +200,19 @@

// TODO: Here it would make sense to do the auto-fill properties stuff but the API doesn't allow us to do that right
// since we'd need to be able to return values for other properties from these methods
_mediaFileManager.FileSystem.AddFile(filepath, filestream, true); // must overwrite!
_mediaFileManager.FileSystem.AddFile(filepath, filestream, overrideIfExists: true); // must overwrite!
}

return filepath;
}

/// <summary>
/// Provides media path.
/// </summary>
/// <returns>File system relative path</returns>
protected virtual string GetMediaPath(TemporaryFileModel file, object? dataTypeConfiguration, Guid contentKey, Guid propertyTypeKey)
{
// in case we are using the old path scheme, try to re-use numbers (bah...)
return _mediaFileManager.GetMediaPath(file.FileName, contentKey, propertyTypeKey);
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Models.TemporaryFile;
using Umbraco.Cms.Core.Models.Validation;
using Umbraco.Extensions;

namespace Umbraco.Cms.Core.PropertyEditors;

internal class TemporaryFileUploadValidator : IValueValidator
public class TemporaryFileUploadValidator : IValueValidator
{
private readonly GetContentSettings _getContentSettings;
private readonly ParseTemporaryFileKey _parseTemporaryFileKey;
private readonly GetTemporaryFileModel _getTemporaryFileModel;
private readonly ValidateFileType? _validateFileType;

internal delegate ContentSettings GetContentSettings();
public delegate ContentSettings GetContentSettings();

internal delegate Guid? ParseTemporaryFileKey(object? editorValue);
public delegate Guid? ParseTemporaryFileKey(object? editorValue);

internal delegate TemporaryFileModel? GetTemporaryFileModel(Guid temporaryFileKey);
public delegate TemporaryFileModel? GetTemporaryFileModel(Guid temporaryFileKey);

internal delegate bool ValidateFileType(string extension, object? dataTypeConfiguration);
public delegate bool ValidateFileType(string extension, object? dataTypeConfiguration);

public TemporaryFileUploadValidator(
GetContentSettings getContentSettings,
Expand Down