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

Feat: Added Support for timeline preview #91

Merged
merged 7 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
### Version: 2.21.0
#### Date: March-03-2025

##### Feat:
- Added Support for Timeline Preview

### Version: 2.20.0
#### Date: Dec-19-2024

Expand Down
2 changes: 2 additions & 0 deletions Contentstack.Core/Configuration/LivePreviewConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public class LivePreviewConfig
internal string ContentTypeUID { get; set; }
internal string EntryUID { get; set; }
internal JObject PreviewResponse { get; set; }
internal string releaseId {get; set;}
internal string previewTimestamp {get; set;}
}
}
14 changes: 14 additions & 0 deletions Contentstack.Core/ContentstackClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ private async Task<JObject> GetLivePreviewData()
headerAll["authorization"] = this.LivePreviewConfig.ManagementToken;
} else if (!string.IsNullOrEmpty(this.LivePreviewConfig.PreviewToken)) {
headerAll["preview_token"] = this.LivePreviewConfig.PreviewToken;
} else if (!string.IsNullOrEmpty(this.LivePreviewConfig.releaseId)) {
headerAll["release_id"] = this.LivePreviewConfig.releaseId;
} else if (!string.IsNullOrEmpty(this.LivePreviewConfig.previewTimestamp)) {
headerAll["preview_timestamp"] = this.LivePreviewConfig.previewTimestamp;
} else {
throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig");
}
Expand Down Expand Up @@ -576,6 +580,16 @@ public async Task LivePreviewQueryAsync(Dictionary<string, string> query)
string hash = null;
query.TryGetValue("live_preview", out hash);
this.LivePreviewConfig.LivePreview = hash;
}
if (query.Keys.Contains("release_id")) {
string releaseId = null;
query.TryGetValue("release_id", out releaseId);
this.LivePreviewConfig.releaseId = releaseId;
}
if (query.Keys.Contains("preview_timestamp")) {
string previewTimestamp = null;
query.TryGetValue("preview_timestamp", out previewTimestamp);
this.LivePreviewConfig.previewTimestamp = previewTimestamp;
}
this.LivePreviewConfig.PreviewResponse = await GetLivePreviewData();
}
Expand Down
2 changes: 1 addition & 1 deletion Contentstack.Core/Internals/HttpRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task<string> ProcessRequest(string Url, Dictionary<string, object>
var request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "GET";
request.ContentType = "application/json";
request.Headers["x-user-agent"]="contentstack-delivery-dotnet/2.20.0";
request.Headers["x-user-agent"]="contentstack-delivery-dotnet/2.21.0";
request.Timeout = timeout;

if (proxy != null)
Expand Down
4 changes: 4 additions & 0 deletions Contentstack.Core/Models/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,10 @@ public async Task<T> Fetch<T>()
headerAll["authorization"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken;
} else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken)) {
headerAll["preview_token"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken;
} else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId)) {
headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId;
} else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp)) {
headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp;
} else {
throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig");
}
Expand Down
12 changes: 12 additions & 0 deletions Contentstack.Core/Models/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,10 @@ private async Task<JObject> Exec()
headerAll["authorization"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.ManagementToken;
} else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken)) {
headerAll["preview_token"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.PreviewToken;
} else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId)) {
headerAll["release_id"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.releaseId;
} else if (!string.IsNullOrEmpty(this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp)) {
headerAll["preview_timestamp"] = this.ContentTypeInstance.StackInstance.LivePreviewConfig.previewTimestamp;
} else {
throw new InvalidOperationException("Either ManagementToken or PreviewToken is required in LivePreviewConfig");
}
Expand All @@ -1866,6 +1870,14 @@ private async Task<JObject> Exec()
{
headerAll.Remove("preview_token");
}
if (!isLivePreview && headerAll.ContainsKey("release_id"))
{
headerAll.Remove("release_id");
}
if (!isLivePreview && headerAll.ContainsKey("preview_timestamp"))
{
headerAll.Remove("preview_timestamp");
}

mainJson.Add("environment", this.ContentTypeInstance.StackInstance.Config.Environment);
if (QueryValueJson != null && QueryValueJson.Count > 0)
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>2.20.0</Version>
<Version>2.21.0</Version>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2012-2024 Contentstack (http://app.contentstack.com). All Rights Reserved
Copyright (c) 2012-2025 Contentstack (http://app.contentstack.com). All Rights Reserved

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading