Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New features #97

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
16 changes: 16 additions & 0 deletions Models/EventModel.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
37 changes: 33 additions & 4 deletions Router.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public Router()
{
using (var db = new LiteDatabase(Config.DBPATH))
{
var collection = db.GetCollection<Paste>("pastes");
var collection = db.GetCollection<Paste>("Pastes");
var paste = collection.FindOne(Query.EQ("LongId", parameters.longId.ToString()));
if (paste == null) return HttpStatusCode.NotFound;
return View["paste", paste];
Expand All @@ -29,7 +29,7 @@ public Router()
{
using (var db = new LiteDatabase(Config.DBPATH))
{
var collection = db.GetCollection<Paste>("pastes");
var collection = db.GetCollection<Paste>("Pastes");
var paste = collection.FindOne(Query.EQ("LongId", parameters.longId.ToString()));
if (paste == null) return HttpStatusCode.NotFound;
return JsonConvert.SerializeObject(paste);
Expand All @@ -42,7 +42,7 @@ public Router()

using (var db = new LiteDatabase(Config.DBPATH))
{
var result = db.GetCollection<Paste>("pastes").FindOne(Query.EQ("LongId", longId));
var result = db.GetCollection<Paste>("Pastes").FindOne(Query.EQ("LongId", longId));

return result.Body;
}
Expand All @@ -62,7 +62,7 @@ public Router()
{
using (var db = new LiteDatabase(Config.DBPATH))
{
var pastes = db.GetCollection<Paste>("pastes");
var pastes = db.GetCollection<Paste>("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);
Expand Down Expand Up @@ -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<Event>(Encoding.Default.GetString(data));

using (var db = new LiteDatabase(Config.ANALYTICSDBPATH))
{
var events = db.GetCollection<Event>("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";
};
}
}
}
1 change: 1 addition & 0 deletions SharpPaste.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="HexUtils.cs" />
<Compile Include="Models\EventModel.cs" />
<Compile Include="Models\UploadResponseModel.cs" />
<Compile Include="Bootstrapper.cs" />
<Compile Include="Config.cs" />
Expand Down