diff --git a/Config.cs b/Config.cs index 42bae9d..ffffe54 100644 --- a/Config.cs +++ b/Config.cs @@ -5,6 +5,7 @@ namespace SharpPaste public class Config { public static string DBPATH = string.Format(@"{0}Databases/Paste.db", AppDomain.CurrentDomain.BaseDirectory); - public static string METADBPATH = string.Format(@"{0}Databases/Meta.db", AppDomain.CurrentDomain.BaseDirectory); + public static string ANALYTICSDBPATH = string.Format(@"{0}Databases/Analytics.db", AppDomain.CurrentDomain.BaseDirectory); + public static string METADBPATH = string.Format(@"{0}Databases/Meta.db", AppDomain.CurrentDomain.BaseDirectory); } } diff --git a/Models/EventModel.cs b/Models/EventModel.cs new file mode 100644 index 0000000..fa7b155 --- /dev/null +++ b/Models/EventModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace SharpPaste +{ + public class Event + { + public int Id { get; set; } + public string LongId { get; set; } + public DateTime Timestamp { get; set; } + public string Name { get; set; } + public string Data { get; set; } + } +} \ No newline at end of file diff --git a/README.md b/README.md index 20c3fdd..5e35085 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,9 @@ Please see the [readme-update branch](https://github.com/phonicmouse/SharpPaste/ | Version | Supported | |:--------------:|:------------------:| -| latest (5.8.0) | :white_check_mark: | -| 5.8.0 | :white_check_mark: | +| latest | :white_check_mark: | +| 5.12.0 | :white_check_mark: | +| 5.8.1 | :white_check_mark: | | 5.4.1 | :white_check_mark: | | 5.2.0 | :white_check_mark: | | 5.0.1 | :white_check_mark: | diff --git a/Router.cs b/Router.cs index 9368edf..d2713a6 100644 --- a/Router.cs +++ b/Router.cs @@ -18,7 +18,7 @@ public Router() { using (var db = new LiteDatabase(Config.DBPATH)) { - var collection = db.GetCollection("pastes"); + var collection = db.GetCollection("Pastes"); var paste = collection.FindOne(Query.EQ("LongId", parameters.longId.ToString())); if (paste == null) return HttpStatusCode.NotFound; return View["paste", paste]; @@ -29,7 +29,7 @@ public Router() { using (var db = new LiteDatabase(Config.DBPATH)) { - var collection = db.GetCollection("pastes"); + var collection = db.GetCollection("Pastes"); var paste = collection.FindOne(Query.EQ("LongId", parameters.longId.ToString())); if (paste == null) return HttpStatusCode.NotFound; return JsonConvert.SerializeObject(paste); @@ -42,7 +42,7 @@ public Router() using (var db = new LiteDatabase(Config.DBPATH)) { - var result = db.GetCollection("pastes").FindOne(Query.EQ("LongId", longId)); + var result = db.GetCollection("Pastes").FindOne(Query.EQ("LongId", longId)); return result.Body; } @@ -62,7 +62,7 @@ public Router() { using (var db = new LiteDatabase(Config.DBPATH)) { - var pastes = db.GetCollection("pastes"); + var pastes = db.GetCollection("Pastes"); string hashSeed = pastes.Count().ToString() + jsonPaste.Date.ToString() + jsonPaste.Title + jsonPaste.Body + jsonPaste.Language; string longId = Multibase.Base64.Encode(HexUtils.toByteArray(SHA.ComputeSHA256Hash(hashSeed)), false, true); @@ -96,6 +96,35 @@ public Router() return JsonConvert.SerializeObject(res); } }; + + Post["/event"] = parameters => + { + var body = Request.Body; + var length = (int)body.Length; + var data = new byte[length]; + + body.Read(data, 0, length); + + var jsonEvent = JsonConvert.DeserializeObject(Encoding.Default.GetString(data)); + + using (var db = new LiteDatabase(Config.ANALYTICSDBPATH)) + { + var events = db.GetCollection("Events"); + + string hashSeed = events.Count().ToString() + jsonEvent.Timestamp.ToString() + jsonEvent.Name + jsonEvent.Data; + string longId = Multibase.Base64.Encode(HexUtils.toByteArray(SHA.ComputeSHA256Hash(hashSeed)), false, true); + + var newEvent = new Event + { + LongId = longId, + Timestamp = DateTime.Now, + Name = jsonEvent.Name, + Data = jsonEvent.Data + }; + } + + return "SUCCESS"; + }; } } } \ No newline at end of file diff --git a/SharpPaste.csproj b/SharpPaste.csproj index bcca42c..634735c 100644 --- a/SharpPaste.csproj +++ b/SharpPaste.csproj @@ -109,6 +109,7 @@ +