Skip to content

Commit

Permalink
NetKAN: Search Github assets to only download zipfile.
Browse files Browse the repository at this point in the history
- Doesn't include tests, because I'm a terrible person
- Closes #290
  • Loading branch information
pjf committed Nov 9, 2014
1 parent 215025e commit 73ed033
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions CKAN/NetKAN/Github/GithubRelease.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using log4net;
Expand All @@ -23,8 +24,25 @@ public GithubRelease (JObject parsed_json)
{
version = new Version( parsed_json["tag_name"].ToString() );
author = parsed_json["author"]["login"].ToString();
size = (long) parsed_json["assets"][0]["size"];
download = new Uri( parsed_json["assets"][0]["browser_download_url"].ToString() );

// GH #290, we need to look for the first asset which is a zip, otherwise we
// end up picking up manuals, pictures of cats, and all sorts of other things.

JToken asset = parsed_json["assets"]
.Children()
.Where(asset_info => asset_info["content_type"].ToString() == "application/x-zip-compressed")
.FirstOrDefault();

if (asset == null)
{
// TODO: A proper kraken, please!
throw new Kraken("Cannot find download");
}

size = (long) asset["size"];
download = new Uri( asset["browser_download_url"].ToString() );

log.DebugFormat("Download {0} is {1} bytes", download, size);
}

override public void InflateMetadata(JObject metadata, string filename, object context)
Expand Down

0 comments on commit 73ed033

Please sign in to comment.