From 38c02457a3e5bb51aedbbc2105399b6378207081 Mon Sep 17 00:00:00 2001 From: tenchooo Date: Sun, 1 Jul 2018 04:25:26 +0100 Subject: [PATCH 1/4] i have no idea --- Models/EventModel.cs | 11 +++++++++++ Router.cs | 10 ++++++++++ 2 files changed, 21 insertions(+) create mode 100644 Models/EventModel.cs diff --git a/Models/EventModel.cs b/Models/EventModel.cs new file mode 100644 index 0000000..bb960cf --- /dev/null +++ b/Models/EventModel.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace SharpPaste +{ + public class Event + { + } +} \ No newline at end of file diff --git a/Router.cs b/Router.cs index 9368edf..b8718ef 100644 --- a/Router.cs +++ b/Router.cs @@ -96,6 +96,16 @@ 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)); + }; } } } \ No newline at end of file From 19c556392cd244dcaf100b17b22d7d9fa206bbb6 Mon Sep 17 00:00:00 2001 From: Leonard Thomas Wall Date: Sun, 1 Jul 2018 04:28:23 +0100 Subject: [PATCH 2/4] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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: | From 5f860e0514803a8e4c765f52fdeefc30991811ae Mon Sep 17 00:00:00 2001 From: Leonard Thomas Wall Date: Sun, 1 Jul 2018 04:29:21 +0100 Subject: [PATCH 3/4] Update .travis.yml --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e02ce6e..4bad937 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,8 @@ language: csharp solution: SharpPaste.sln mono: - latest - - 5.8.0 + - 5.12.0 + - 5.8.1 - 5.4.1 - 5.2.0 - 5.0.1 From 311558cf9dfcc76d39e8bbf3b339b4b1200a5c0d Mon Sep 17 00:00:00 2001 From: tenchooo Date: Sun, 1 Jul 2018 15:00:21 +0100 Subject: [PATCH 4/4] asd --- Config.cs | 3 ++- Models/EventModel.cs | 5 +++++ Router.cs | 29 ++++++++++++++++++++++++----- SharpPaste.csproj | 1 + 4 files changed, 32 insertions(+), 6 deletions(-) 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 index bb960cf..fa7b155 100644 --- a/Models/EventModel.cs +++ b/Models/EventModel.cs @@ -7,5 +7,10 @@ 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/Router.cs b/Router.cs index b8718ef..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); @@ -97,7 +97,8 @@ public Router() } }; - Post["/event"] = parameters => { + Post["/event"] = parameters => + { var body = Request.Body; var length = (int)body.Length; var data = new byte[length]; @@ -105,6 +106,24 @@ public Router() 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"; }; } } diff --git a/SharpPaste.csproj b/SharpPaste.csproj index bcca42c..634735c 100644 --- a/SharpPaste.csproj +++ b/SharpPaste.csproj @@ -109,6 +109,7 @@ +