Skip to content

Commit 0eeab6d

Browse files
Merge pull request #195 from nefarius/nefarius/feature/attachments-in-change-feed
Implements fetching attachment data when requested in continuous change feed
2 parents 7d1978d + 01a970d commit 0eeab6d

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

src/CouchDB.Driver/CouchDatabase.cs

+3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ internal CouchDatabase(IFlurlClient flurlClient, CouchOptions options, QueryCont
8181
public async Task<TSource?> FindAsync(string docId, FindOptions options, CancellationToken cancellationToken = default)
8282
{
8383
IFlurlRequest request = NewRequest()
84+
.WithHeader("Accept", "application/json")
8485
.AppendPathSegment(Uri.EscapeDataString(docId));
8586

8687
IFlurlResponse? response = await SetFindOptions(request, options)
@@ -414,6 +415,7 @@ private async Task UpdateAttachments(TSource document, CancellationToken cancell
414415
public async Task<ChangesFeedResponse<TSource>> GetChangesAsync(ChangesFeedOptions? options = null, ChangesFeedFilter? filter = null, CancellationToken cancellationToken = default)
415416
{
416417
IFlurlRequest request = NewRequest()
418+
.WithHeader("Accept", "application/json")
417419
.AppendPathSegment("_changes");
418420

419421
if (options?.LongPoll == true)
@@ -448,6 +450,7 @@ public async IAsyncEnumerable<ChangesFeedResponseResult<TSource>> GetContinuousC
448450
var infiniteTimeout = TimeSpan.FromMilliseconds(Timeout.Infinite);
449451
IFlurlRequest request = NewRequest()
450452
.WithTimeout(infiniteTimeout)
453+
.WithHeader("Accept", "application/json")
451454
.AppendPathSegment("_changes")
452455
.SetQueryParam("feed", "continuous");
453456

src/CouchDB.Driver/ICouchDatabase.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ Task<ChangesFeedResponse<TSource>> GetChangesAsync(ChangesFeedOptions? options =
222222
/// <param name="cancellationToken">A cancellation token to stop receiving changes.</param>
223223
/// <returns>A IAsyncEnumerable that represents the asynchronous operation. The task result contains the feed change.</returns>
224224
IAsyncEnumerable<ChangesFeedResponseResult<TSource>> GetContinuousChangesAsync(
225-
ChangesFeedOptions options, ChangesFeedFilter filter,
225+
ChangesFeedOptions? options, ChangesFeedFilter? filter,
226226
CancellationToken cancellationToken);
227227

228228
/// <summary>

src/CouchDB.Driver/Types/CouchAttachment.cs

+57-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace CouchDB.Driver.Types
88
{
9+
/// <summary>
10+
/// Represents an attachment for a document.
11+
/// </summary>
912
public sealed class CouchAttachment
1013
{
1114
[JsonIgnore]
@@ -26,25 +29,78 @@ public sealed class CouchAttachment
2629
[JsonIgnore]
2730
public Uri Uri { get; internal set; }
2831

32+
/// <summary>
33+
/// Gets whether the attachment object contains stub info and no content.
34+
/// </summary>
2935
[DataMember]
3036
[JsonProperty("stub")]
3137
public bool Stub { get; set; }
3238

39+
/// <summary>
40+
/// Gets the attachment MIME type.
41+
/// </summary>
3342
[DataMember]
3443
[JsonProperty("content_type")]
3544
public string ContentType { get; set; }
3645

46+
/// <summary>
47+
/// Gets the content hash digest. It starts with prefix which announce hash type (md5-) and continues with
48+
/// Base64-encoded hash digest.
49+
/// </summary>
3750
[DataMember]
3851
[JsonProperty("digest")]
3952
public string Digest { get; private set; }
4053

54+
/// <summary>
55+
/// Gets the real attachment size in bytes. Not available if attachment content requested.
56+
/// </summary>
4157
[DataMember]
4258
[JsonProperty("length")]
43-
public int? Length { get; private set; }
59+
public long? Length { get; private set; }
4460

61+
/// <summary>
62+
/// Gets the revision number when attachment was added.
63+
/// </summary>
4564
[DataMember]
4665
[JsonProperty("revpos")]
4766
public int? RevPos { get; private set; }
67+
68+
/// <summary>
69+
/// Gets the compressed attachment size in bytes.
70+
/// </summary>
71+
/// <remarks>
72+
/// Available if content_type is in list of compressible types when the attachment was added and the following query
73+
/// parameters are specified:
74+
/// <list type="bullet">
75+
/// <item>
76+
/// <description>att_encoding_info=true when querying a document</description>
77+
/// </item>
78+
/// <item>
79+
/// <description>att_encoding_info=true&amp;include_docs=true when querying a changes feed or a view</description>
80+
/// </item>
81+
/// </list>
82+
/// </remarks>
83+
[DataMember]
84+
[JsonProperty("encoded_length")]
85+
public long? EncodedLength { get; private set; }
86+
87+
/// <summary>
88+
/// Gets the Base64-encoded content. Only populated if queried for and <see cref="Stub"/> is false.
89+
/// </summary>
90+
/// <remarks>
91+
/// Base64-encoded content. Available if attachment content is requested by using the following query parameters:
92+
/// <list type="bullet">
93+
/// <item>
94+
/// <description>attachments=true when querying a document</description>
95+
/// </item>
96+
/// <item>
97+
/// <description>attachments=true&amp;include_docs=true when querying a changes feed or a view</description>
98+
/// </item>
99+
/// </list>
100+
/// </remarks>
101+
[DataMember]
102+
[JsonProperty("data")]
103+
public string Data { get; private set; }
48104
}
49105
}
50106
#nullable restore

src/azure-pipelines.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
variables:
22
BuildConfiguration: Release
3-
PackageVersion: '3.4.0'
3+
PackageVersion: '3.5.0'
44

55
trigger:
66
branches:

0 commit comments

Comments
 (0)