mirror of
https://github.com/spaytac/linkdingsync.git
synced 2026-01-21 16:54:45 +00:00
**update** faced some issues while updating linkding bookmarks, changed the httpclient call.
This commit is contained in:
parent
8ef4963a9b
commit
207f5ef58c
@ -13,8 +13,7 @@ namespace Linkding.Client
|
||||
Task AddBookmarkAsync(BookmarkCreatePayload bookmark);
|
||||
|
||||
Task UpdateBookmarkCollectionAsync(IEnumerable<Bookmark> bookmarks);
|
||||
Task UpdateBookmarkCollectionAsync(IEnumerable<BookmarkUpdatePayload> bookmarks);
|
||||
Task UpdateBookmarkAsync(BookmarkUpdatePayload bookmark);
|
||||
Task UpdateBookmarkAsync(int id, BookmarkUpdatePayload bookmark);
|
||||
Task<BookmarksResult> GetBookmarkResultsAsync(int limit = 100, int offset = 0);
|
||||
Task<BookmarksResult> GetBookmarkResultsAsync(string url);
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ namespace Core.Entities.Linkding
|
||||
{
|
||||
public class BookmarkUpdatePayload : BookmarkBase
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public int Id { get; set; }
|
||||
// [JsonPropertyName("id")]
|
||||
// public int Id { get; set; }
|
||||
}
|
||||
}
|
||||
@ -14,7 +14,7 @@ public class UpdateTargetLinkdingHandler : ILinkdingSyncTaskHandler
|
||||
{
|
||||
var linkdingBookmarks = await linkdingService.GetAllBookmarksAsync();
|
||||
var addedBookmarks = new List<BookmarkCreatePayload>();
|
||||
var updatedBookmarks = new List<BookmarkUpdatePayload>();
|
||||
var updatedBookmarks = new List<Bookmark>();
|
||||
|
||||
if (linkdingBookmarks.Count() > 0)
|
||||
{
|
||||
@ -37,7 +37,7 @@ public class UpdateTargetLinkdingHandler : ILinkdingSyncTaskHandler
|
||||
!linkdingBookmark.Description.Equals(bookmark.Description.Trim(), StringComparison.OrdinalIgnoreCase) ||
|
||||
linkdingBookmark.TagNames.Count() != bookmark.TagNames.Count()))
|
||||
{
|
||||
updatedBookmarks.Add(bookmark.MapToUpdatePayload());
|
||||
updatedBookmarks.Add(bookmark);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -46,7 +46,7 @@ public class UpdateTargetLinkdingHandler : ILinkdingSyncTaskHandler
|
||||
|
||||
if (difference.Count() > 0)
|
||||
{
|
||||
updatedBookmarks.Add(bookmark.MapToUpdatePayload());
|
||||
updatedBookmarks.Add(bookmark);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,4 +22,10 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Services\Linkding.Client\Linkding.Client.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="data\config.yml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@ -1,39 +0,0 @@
|
||||
urlTagMapping:
|
||||
- name: microsoft_azure
|
||||
url: https://github.com/azure
|
||||
- name: microsoft_azuread
|
||||
url: https://github.com/AzureAD
|
||||
- name: microsoft_dotnet
|
||||
url: https://github.com/dotnet-architecture
|
||||
|
||||
taggingRule:
|
||||
- name: reddit
|
||||
pattern: https://(?:www\.)?(reddit)\.com(?:/r/)?([ a-zA-Z0-9\-\+_ ]+)?(?:/.*)?
|
||||
replace: $1,$2
|
||||
- name: microsoft
|
||||
pattern: https://([ a-zA-Z0-9 ]+)?[ \. ]?(microsoft)\.com(?:/.*)?
|
||||
replace: $1,$2
|
||||
- name: microsoft_docs
|
||||
pattern: "https://(?:docs)\.(?:microsoft)\.com[ / ]?(?: [ a-zA-Z0-9\-\+_ ]+)(?:/)?([ a-zA-Z0-9\-\+_ ]+)?(?:/)?([ a-zA-Z0-9\-\+_ ]+)?(?:/.*)?"
|
||||
replace: $1,$2
|
||||
- name: youtube
|
||||
pattern: https://[ [ a-zA-Z0-9 ]+\. ]?(youtube)\.com(?:/.*)?
|
||||
replace: $1
|
||||
- name: ebay
|
||||
pattern: https://[ [ a-zA-Z0-9 ]+\. ]?(ebay)\.(com|de|fr)(?:/.*)?
|
||||
replace: $1
|
||||
- name: amazon
|
||||
pattern: https://[ [ a-zA-Z0-9 ]+\. ]?(amazon)\.(com|de|fr)(?:/.*)?
|
||||
replace: $1
|
||||
- name: docker
|
||||
pattern: https://([ a-zA-Z0-9 ]+)?[ \. ]?(docker)\.com(?:/.*)?
|
||||
replace: $1,$2
|
||||
- name: xbox
|
||||
pattern: https://[ [ a-zA-Z0-9 ]+\. ]?(xbox)\.com(?:/.*)?
|
||||
replace: $1
|
||||
- name: github
|
||||
pattern: https://([ a-zA-Z0-9 ]+)?[ \. ]?(github)\.com[ / ]?([ a-zA-Z0-9\-\+_ ]+)(?:/)?([ a-zA-Z0-9\-\+_ ]+)?(?:/.*)?
|
||||
replace: $2,$3,$4
|
||||
- name: github.io
|
||||
pattern: https://([ a-zA-Z0-9 ]+)\.(github)\.io[ / ]?([ a-zA-Z0-9\-\+_ ]+)(?:/)?([ a-zA-Z0-9\-\+_ ]+)?(?:/.*)?
|
||||
replace: $2,$3,$4
|
||||
39
src/Linkding/data/config.yml
Normal file
39
src/Linkding/data/config.yml
Normal file
@ -0,0 +1,39 @@
|
||||
urlTagMapping:
|
||||
- name: microsoft
|
||||
url: https://github.com/azure
|
||||
- name: microsoft
|
||||
url: https://github.com/AzureAD
|
||||
- name: microsoft
|
||||
url: https://github.com/dotnet-architecture
|
||||
|
||||
taggingRule:
|
||||
- name: reddit
|
||||
pattern: https://(?:www\.)?(reddit)\.com(?:/r/)?([a-zA-Z0-9\-\+_]+)?(?:/.*)?
|
||||
replace: $1,$2
|
||||
- name: microsoft
|
||||
pattern: https://([a-zA-Z0-9]+)?[\.]?(microsoft)\.com(?:/.*)?
|
||||
replace: $1,$2
|
||||
- name: microsoft_docs
|
||||
pattern: 'https://(?:docs)\.(?:microsoft)\.com[/]?(?: [a-zA-Z0-9\-\+_]+)(?:/)?([a-zA-Z0-9\-\+_]+)?(?:/)?([a-zA-Z0-9\-\+_]+)?(?:/.*)?'
|
||||
replace: $1,$2
|
||||
- name: youtube
|
||||
pattern: https://[[a-zA-Z0-9]+\.]?(youtube)\.com(?:/.*)?
|
||||
replace: $1
|
||||
- name: ebay
|
||||
pattern: https://[[a-zA-Z0-9]+\.]?(ebay)\.(com|de|fr)(?:/.*)?
|
||||
replace: $1
|
||||
- name: amazon
|
||||
pattern: https://[[a-zA-Z0-9]+\.]?(amazon)\.(com|de|fr)(?:/.*)?
|
||||
replace: $1
|
||||
- name: docker
|
||||
pattern: https://([a-zA-Z0-9]+)?[\.]?(docker)\.com(?:/.*)?
|
||||
replace: $1,$2
|
||||
- name: xbox
|
||||
pattern: https://[[a-zA-Z0-9]+\.]?(xbox)\.com(?:/.*)?
|
||||
replace: $1
|
||||
- name: github
|
||||
pattern: https://([ a-zA-Z0-9 ]+)?[ \. ]?(github)\.com[ / ]?([ a-zA-Z0-9\-\+_ ]+)(?:/)?([ a-zA-Z0-9\-\+_ ]+)?(?:/.*)?
|
||||
replace: $2,$3,$4
|
||||
- name: github.io
|
||||
pattern: https://([ a-zA-Z0-9 ]+)\.(github)\.io[ / ]?([ a-zA-Z0-9\-\+_ ]+)(?:/)?([ a-zA-Z0-9\-\+_ ]+)?(?:/.*)?
|
||||
replace: $1,$2,$3
|
||||
@ -1,5 +1,7 @@
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Http.Json;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using AutoMapper;
|
||||
using Core.Entities.Linkding;
|
||||
using Linkding.Client.Options;
|
||||
@ -89,6 +91,21 @@ public class LinkdingService : ILinkdingService
|
||||
|
||||
public async Task AddBookmarkAsync(BookmarkCreatePayload bookmark)
|
||||
{
|
||||
var content = JsonSerializer.Serialize(bookmark);
|
||||
var requestContent = new StringContent(content, Encoding.UTF8, "application/json");
|
||||
var uri = $"/api/bookmarks/";
|
||||
|
||||
try
|
||||
{
|
||||
var response = await _client.PostAsync(uri, requestContent);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
// throw;
|
||||
}
|
||||
|
||||
var result = await _client.PostAsJsonAsync($"/api/bookmarks/", bookmark);
|
||||
if (result.IsSuccessStatusCode)
|
||||
{
|
||||
@ -107,7 +124,7 @@ public class LinkdingService : ILinkdingService
|
||||
try
|
||||
{
|
||||
var payload = _mapper.Map<Bookmark, BookmarkUpdatePayload>(bookmark);
|
||||
await UpdateBookmarkAsync(payload);
|
||||
await UpdateBookmarkAsync(bookmark.Id, payload);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -117,24 +134,21 @@ public class LinkdingService : ILinkdingService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpdateBookmarkCollectionAsync(IEnumerable<BookmarkUpdatePayload> bookmarks)
|
||||
public async Task UpdateBookmarkAsync(int id, BookmarkUpdatePayload bookmark)
|
||||
{
|
||||
foreach (var bookmark in bookmarks)
|
||||
{
|
||||
await UpdateBookmarkAsync(bookmark);
|
||||
}
|
||||
}
|
||||
var content = JsonSerializer.Serialize(bookmark);
|
||||
var requestContent = new StringContent(content, Encoding.UTF8, "application/json");
|
||||
var uri = $"/api/bookmarks/{id}/";// Path.Combine("api/bookmarks", $"{id}");
|
||||
|
||||
public async Task UpdateBookmarkAsync(BookmarkUpdatePayload bookmark)
|
||||
try
|
||||
{
|
||||
var result = await _client.PutAsJsonAsync($"/api/bookmarks/{bookmark.Id}/", bookmark);
|
||||
if (result.IsSuccessStatusCode)
|
||||
{
|
||||
|
||||
var response = await _client.PutAsync(uri, requestContent);
|
||||
response.EnsureSuccessStatusCode();
|
||||
}
|
||||
else
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Console.WriteLine(e);
|
||||
// throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -27,4 +27,10 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="data\config.yml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user