-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPreRenderService.cs
More file actions
56 lines (47 loc) · 1.61 KB
/
Copy pathPreRenderService.cs
File metadata and controls
56 lines (47 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Threading.Tasks;
using ServiceStack;
using ServiceStack.OrmLite;
using TechStacks.ServiceModel;
namespace TechStacks.ServiceInterface;
public class PreRenderService(IMarkdownProvider markdown) : PostServicesBase(markdown)
{
string GetPath() => Request.RawUrl.StartsWith("/prerender")
? Request.RawUrl.Substring("/prerender".Length)
: Request.RawUrl;
// [Authenticate]
public async Task Put(StorePreRender request)
{
var user = GetUser();
var bytes = request.RequestStream.ReadFully();
var path = GetPath();
var updated = await Db.UpdateOnlyAsync(() =>
new PreRender {
Data = bytes,
ContentType = Request.ContentType,
Modified = DateTime.Now,
ModifiedBy = user.UserName,
},
where:x => x.Path == path);
if (updated == 0)
{
Db.Insert(new PreRender {
Path = path,
Data = bytes,
ContentType = Request.ContentType,
Created = DateTime.Now,
CreatedBy = user.UserName,
Modified = DateTime.Now,
ModifiedBy = user.UserName,
});
}
}
public async Task Get(GetPreRender request)
{
var path = GetPath();
var prerender = Db.SingleById<PreRender>(path);
if (prerender == null)
throw HttpError.NotFound(path);
await Response.WriteBytesToResponse(prerender.Data, prerender.ContentType);
}
}