Skip to content
Open
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
2 changes: 1 addition & 1 deletion VsGallery.Core/IConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public interface IStorageConfiguration
string VsixStorageDirectory { get; }
string UploadDirectory { get; }
string UploadMaxFileSize { get; }

bool OverwriteFiles { get; }
}

public interface IGalleryConfiguration
Expand Down
14 changes: 14 additions & 0 deletions VsGallery.WebService/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ public string UploadMaxFileSize
this[uploadMaxFileSizePropertyName] = value;
}
}

const string overwriteFilesPropertyName = "OverwriteFiles";
[ConfigurationProperty(overwriteFilesPropertyName, DefaultValue = "false", IsRequired = false)]
public bool OverwriteFiles
{
get
{
return (Boolean)this[overwriteFilesPropertyName];
}
set
{
this[overwriteFilesPropertyName] = value;
}
}
}

public class GalleryConfiguration : ConfigurationElement, IGalleryConfiguration
Expand Down
14 changes: 12 additions & 2 deletions VsGallery.WebService/Controllers/UploadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,25 @@ public IHttpActionResult AddOrUpdateVsix()
// Validate the uploaded image(optional)

// Get the complete file path
foreach(var httpFile in httpFiles)
foreach (var httpFile in httpFiles)
{
var fileSavePath = Path.Combine(_configuration.UploadDirectory, httpFile.FileName);

var destinationPath = Path.Combine(_configuration.VsixStorageDirectory, httpFile.FileName);

if (File.Exists(destinationPath))
{
if (!_configuration.OverwriteFiles)
return BadRequest($"File {httpFile.FileName} already exists.");

File.Delete(destinationPath);
}

// Save the uploaded file to "UploadedFiles" folder
httpFile.SaveAs(fileSavePath);

// Now move all the files uploaded to the main storage directory
File.Move(fileSavePath, Path.Combine(_configuration.VsixStorageDirectory, httpFile.FileName));
File.Move(fileSavePath, destinationPath);
}

return Ok();
Expand Down
4 changes: 2 additions & 2 deletions VsGallery.WebService/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
</configSections>

<VsGallerySettings>
<Storage VsixStorageDirectory="~/App_Data/VsixStorage" UploadDirectory="~/App_Data/VsixUploads" />
<Gallery Guid="54F7969C-F561-4B16-9D6B-7325EDE0A3C1" Title="Super Productive Gallery" TrackDownloads="True" TrackRatings="True" />
<Storage VsixStorageDirectory="~/App_Data/VsixStorage" UploadDirectory="~/App_Data/VsixUploads" OverwriteFiles="false" />
<Gallery Guid="54F7969C-F561-4B16-9D6B-7325EDE0A3C1" Title="Super Productive Gallery" TrackDownloads="True" TrackRatings="True" />
</VsGallerySettings>

<system.web>
Expand Down
1 change: 1 addition & 0 deletions vsgallery/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public class StorageConfiguration : BaseConfiguration, IStorageConfiguration
public string VsixStorageDirectory => Get<string>(nameof(VsixStorageDirectory));
public string UploadDirectory => Get<string>(nameof(UploadDirectory));
public string UploadMaxFileSize => Get<string>(nameof(UploadMaxFileSize));
public bool OverwriteFiles => Get<bool>(nameof(OverwriteFiles));

public StorageConfiguration(KeyDataCollection data) : base(data) { }
}
Expand Down