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
8 changes: 8 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,12 @@ curl -X POST
--form "file1=@my.vsix"
--form "file1=@your.vsix"
http://VSGALLERY_SERVER:5100/api/upload
```

To upload a file to the gallery server that requires an upload key

```
curl -X POST
--form "file=@my.vsix;filename=renamed.vsix"
http://VSGALLERY_SERVER:5100/api/upload/API_KEY
```
8 changes: 8 additions & 0 deletions SETUP IIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ The Gallery Settings like Storage location and some Gallery Configuration can be

the `~` in the derectory configuration means Web Application root directory.

To require a key to upload packages set the `UploadKey` for the gallery

```
<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" UploadKey="nXqjCmD5t6xr5nFEKZ3UgONQWUZYJf9G" />
</VsGallerySettings>
```

The default local physical structure
`.vsix` files, along with their download counts and ratings data are stored in a subfolder of the main service executable `VsixStorage/` (this subfolder is configurable). This makes taking backups and moving the service between machines super easy as the root folder contains the entire Microservice state and data.
Expand Down
1 change: 1 addition & 0 deletions VsGallery.Core/IConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public interface IGalleryConfiguration
string Description { get; }
bool TrackDownloads { get; }
bool TrackRatings { get; }
string UploadKey { get; }
}
}
14 changes: 14 additions & 0 deletions VsGallery.WebService/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ public bool TrackRatings
this[trackRatingsPropertyName] = value;
}
}

const string uploadKeyPropertyName = "UploadKey";
[ConfigurationProperty(uploadKeyPropertyName, DefaultValue = "", IsRequired = false)]
public string UploadKey
{
get
{
return this[uploadKeyPropertyName] as string;
}
set
{
this[uploadKeyPropertyName] = value;
}
}
}

public class Configuration : ConfigurationSection, IConfiguration
Expand Down
16 changes: 11 additions & 5 deletions VsGallery.WebService/Controllers/UploadController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ namespace VsGallery.WebService.Controllers
{
public class UploadController : ApiController
{
private IStorageConfiguration _configuration;
private IStorageConfiguration _storage;
private IGalleryConfiguration _gallery;

public UploadController()
{
_configuration = WebService.Configuration.Instance.Storage;
_storage = WebService.Configuration.Instance.Storage;
_gallery = WebService.Configuration.Instance.Gallery;
}


Expand All @@ -26,8 +28,12 @@ public UploadController()
/// </summary>
[HttpPost]
[HttpPut]
public IHttpActionResult AddOrUpdateVsix()
[Route("api/upload/{*key}")]
public IHttpActionResult AddOrUpdateVsix(string key)
{
if (!string.IsNullOrEmpty(_gallery.UploadKey) && key != _gallery.UploadKey)
return BadRequest("Invalid Key");

// Get the uploaded image from the Files collection
var requestFiles = HttpContext.Current.Request.Files;
var httpFiles = Enumerable.Range(0, requestFiles.Count).Select(i => requestFiles[i]).ToList();
Expand All @@ -43,13 +49,13 @@ public IHttpActionResult AddOrUpdateVsix()
// Get the complete file path
foreach(var httpFile in httpFiles)
{
var fileSavePath = Path.Combine(_configuration.UploadDirectory, httpFile.FileName);
var fileSavePath = Path.Combine(_storage.UploadDirectory, httpFile.FileName);

// 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, Path.Combine(_storage.VsixStorageDirectory, httpFile.FileName));
}

return Ok();
Expand Down
1 change: 1 addition & 0 deletions VsGallery.WebService/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<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" />
<!--<Gallery Guid="54F7969C-F561-4B16-9D6B-7325EDE0A3C1" Title="Super Productive Gallery" TrackDownloads="True" TrackRatings="True" UploadKey="nXqjCmD5t6xr5nFEKZ3UgONQWUZYJf9G" />-->
</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 @@ -82,6 +82,7 @@ public GalleryConfiguration(KeyDataCollection data) : base(data){}
public string Description => Get<string>(nameof(Description));
public bool TrackDownloads => Get<bool>(nameof(TrackDownloads));
public bool TrackRatings => Get<bool>(nameof(TrackRatings));
public string UploadKey => Get<string>(nameof(UploadKey));
}


Expand Down