Fixed possibility for same URLs.tags/2.0.3
@@ -6,7 +6,7 @@ | |||
<div class="container"> | |||
<div class="row api"> | |||
<h2><b>Paste</b></h2> | |||
<h2><b>Paste Service</b></h2> | |||
<hr> | |||
<p>This is a description of the API commands available for the Paste service.</p> | |||
<h3>Submit a Paste</h3> | |||
@@ -132,7 +132,7 @@ | |||
</tbody> | |||
</table> | |||
<h4>Response</h4> | |||
<pre><code>{"result":{"id":<var>id</var> "url":"<var>url</var>", "title":"<var>title</var>", "syntax":"<var>auto-detect</var>", "expiration":"<var>datetime</var>", "password":"<var>password</var>"}}}</code></pre> | |||
<pre><code>{"result":{"id":<var>id</var> "url":"<var>url</var>", "title":"<var>title</var>", "syntax":"<var>auto-detect</var>", "expiration":"<var>datetime</var>", "password":"<var>password</var>"}}</code></pre> | |||
<table> | |||
<thead> | |||
<tr> | |||
@@ -211,7 +211,7 @@ | |||
</tbody> | |||
</table> | |||
<h4>Example</h4> | |||
<pre><code>$ curl --data "title=Paste%20Title&expireUnit=view&expireLength=3" --data-urlencode "code=This%20is%20my%20test%20code." @Url.SubRouteUrl("api", "API.v1.Paste")</code></pre> | |||
<pre><code>$ curl --data "title=Paste%20Title&expireUnit=view&expireLength=3" --data-urlencode "code=This is my test code." @Url.SubRouteUrl("api", "API.v1.Paste")</code></pre> | |||
<p> | |||
This will submit the paste with a title and expiration when the paste has viewed 3 times. | |||
</p> |
@@ -111,6 +111,11 @@ namespace Teknik.Areas.Paste.Controllers | |||
{ | |||
Models.Paste paste = PasteHelper.CreatePaste(model.Content, model.Title, model.Syntax, model.ExpireUnit, model.ExpireLength ?? 1, model.Password, model.Hide); | |||
if (model.ExpireUnit == "view") | |||
{ | |||
paste.Views = -1; | |||
} | |||
db.Pastes.Add(paste); | |||
db.SaveChanges(); | |||
@@ -13,12 +13,20 @@ namespace Teknik.Areas.Paste | |||
{ | |||
public static Models.Paste CreatePaste(string content, string title = "", string syntax = "auto-detect", string expireUnit = "never", int expireLength = 1, string password = "", bool hide = false) | |||
{ | |||
TeknikEntities db = new TeknikEntities(); | |||
Config config = Config.Load(); | |||
Models.Paste paste = new Models.Paste(); | |||
Models.Paste paste = db.Pastes.Create(); | |||
paste.DatePosted = DateTime.Now; | |||
paste.Url = Utility.RandomString(config.PasteConfig.UrlLength); | |||
paste.MaxViews = 0; | |||
paste.Views = -1; | |||
paste.Views = 0; | |||
// Generate random url | |||
string url = Utility.RandomString(config.PasteConfig.UrlLength); | |||
while (db.Pastes.Where(p => p.Url == url) != null) | |||
{ | |||
url = Utility.RandomString(config.PasteConfig.UrlLength); | |||
} | |||
paste.Url = url; | |||
// Figure out the expire date (null if 'never' or 'visit') | |||
switch (expireUnit.ToLower()) |