feature: airdrop share favorites
This commit is contained in:
@@ -18,10 +18,10 @@ namespace Pixiview.Utils
|
||||
public static readonly string PersonalFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
|
||||
public static readonly string CacheFolder = Environment.GetFolderPath(Environment.SpecialFolder.InternetCache);
|
||||
|
||||
private const string favoriteFile = "favorites.json";
|
||||
private const string imageFolder = "img-original";
|
||||
private const string previewFolder = "img-master";
|
||||
private const string illustFile = "illust.json";
|
||||
private const string favoriteFile = "favorites.json";
|
||||
|
||||
private const string pagesFolder = "pages";
|
||||
private const string preloadsFolder = "preloads";
|
||||
@@ -45,38 +45,40 @@ namespace Pixiview.Utils
|
||||
}
|
||||
}
|
||||
|
||||
public static List<IllustItem> Favorites => GetFavoriteObject().Illusts;
|
||||
public static string FavoritesPath => Path.Combine(PersonalFolder, favoriteFile);
|
||||
|
||||
private static IllustFavorite favoriteObject;
|
||||
public static IllustFavorite FavoriteObject
|
||||
|
||||
public static IllustFavorite GetFavoriteObject(bool force = false)
|
||||
{
|
||||
get
|
||||
lock (sync)
|
||||
{
|
||||
lock (sync)
|
||||
if (force || favoriteObject == null)
|
||||
{
|
||||
if (favoriteObject == null)
|
||||
var favorites = LoadFavoritesIllusts();
|
||||
if (favorites != null)
|
||||
{
|
||||
var favorites = LoadFavoritesIllusts();
|
||||
if (favorites != null)
|
||||
{
|
||||
favoriteObject = favorites;
|
||||
}
|
||||
else
|
||||
{
|
||||
favoriteObject = new IllustFavorite
|
||||
{
|
||||
Illusts = new List<IllustItem>()
|
||||
};
|
||||
}
|
||||
favoriteObject = favorites;
|
||||
}
|
||||
else
|
||||
{
|
||||
favoriteObject = new IllustFavorite
|
||||
{
|
||||
Illusts = new List<IllustItem>()
|
||||
};
|
||||
}
|
||||
return favoriteObject;
|
||||
}
|
||||
return favoriteObject;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<IllustItem> Favorites => FavoriteObject.Illusts;
|
||||
|
||||
private static IllustFavorite LoadFavoritesIllusts()
|
||||
public static IllustFavorite LoadFavoritesIllusts(string file = null)
|
||||
{
|
||||
var file = Path.Combine(PersonalFolder, favoriteFile);
|
||||
if (file == null)
|
||||
{
|
||||
file = FavoritesPath;
|
||||
}
|
||||
lock (sync)
|
||||
{
|
||||
return ReadObject<IllustFavorite>(file);
|
||||
@@ -85,10 +87,10 @@ namespace Pixiview.Utils
|
||||
|
||||
public static void SaveFavoritesIllusts()
|
||||
{
|
||||
var file = Path.Combine(PersonalFolder, favoriteFile);
|
||||
var file = FavoritesPath;
|
||||
lock (sync)
|
||||
{
|
||||
var data = FavoriteObject;
|
||||
var data = GetFavoriteObject();
|
||||
data.LastFavoriteUtc = DateTime.UtcNow;
|
||||
WriteObject(file, data);
|
||||
}
|
||||
@@ -236,9 +238,9 @@ namespace Pixiview.Utils
|
||||
Configs.UrlIllustList,
|
||||
Configs.Referer,
|
||||
force: force);
|
||||
if (result.error)
|
||||
if (result == null || result.error)
|
||||
{
|
||||
App.DebugPrint($"error when load illust data: {result.message} ({force})");
|
||||
App.DebugPrint($"error when load illust data: {result?.message} ({force})");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -276,9 +278,9 @@ namespace Pixiview.Utils
|
||||
string.Format(Configs.UrlIllustPage, id),
|
||||
string.Format(Configs.UrlIllust, id),
|
||||
force: force);
|
||||
if (result.error)
|
||||
if (result == null || result.error)
|
||||
{
|
||||
App.DebugPrint($"error when load page data: {result.message} ({force})");
|
||||
App.DebugPrint($"error when load page data: {result?.message} ({force})");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -290,22 +292,22 @@ namespace Pixiview.Utils
|
||||
string.Format(Configs.UrlIllustUserAll, userId),
|
||||
string.Format(Configs.UrlIllustUser, userId),
|
||||
force: force);
|
||||
if (list.error)
|
||||
if (list == null || list.error)
|
||||
{
|
||||
App.DebugPrint($"error when load user data: {list.message} ({force})");
|
||||
App.DebugPrint($"error when load user data: {list?.message} ({force})");
|
||||
}
|
||||
|
||||
// TODO
|
||||
var ids = string.Join("&ids%5B%5D=", list.body.illusts.Keys.Take(20));
|
||||
var ids = string.Join("", list.body.illusts.Keys.Take(20).Select(id => $"ids%5B%5D={id}&"));
|
||||
|
||||
var result = LoadObject<IllustUserData>(
|
||||
null,
|
||||
string.Format(Configs.UrlIllustUserArtworks, userId, ids, 1),
|
||||
string.Format(Configs.UrlIllustUser, userId),
|
||||
force: force);
|
||||
if (result.error)
|
||||
if (result == null || result.error)
|
||||
{
|
||||
App.DebugPrint($"error when load user illust data: {result.message} ({force})");
|
||||
App.DebugPrint($"error when load user illust data: {result?.message} ({force})");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -451,20 +453,21 @@ namespace Pixiview.Utils
|
||||
}
|
||||
var client = new HttpClient(handler)
|
||||
{
|
||||
BaseAddress = new Uri($"{uri.Scheme}://{uri.Host}")
|
||||
BaseAddress = new Uri($"{uri.Scheme}://{uri.Host}"),
|
||||
Timeout = TimeSpan.FromSeconds(30)
|
||||
};
|
||||
return TryCount(() =>
|
||||
{
|
||||
using (var request = new HttpRequestMessage(HttpMethod.Get, uri.PathAndQuery)
|
||||
{
|
||||
Version = new Version(2, 0)
|
||||
Version = new Version(2, 0),
|
||||
})
|
||||
{
|
||||
var headers = request.Headers;
|
||||
headerAction(headers);
|
||||
headers.Add("accept-language", Configs.AcceptLanguage);
|
||||
headers.Add("accept-encoding", Configs.AcceptEncoding);
|
||||
return client.SendAsync(request).Result;
|
||||
return client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead).Result;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -485,7 +488,7 @@ namespace Pixiview.Utils
|
||||
public const string SuffixPreload = " id=\"meta-preload-data\" content='";
|
||||
public const int SuffixPreloadLength = 33; // SuffixPreload.Length
|
||||
public const string UrlIllustUserAll = "https://www.pixiv.net/ajax/user/{0}/profile/all?lang=zh";
|
||||
public const string UrlIllustUserArtworks = "https://www.pixiv.net/ajax/user/{0}/profile/illusts?ids%5B%5D={1}&work_category=illustManga&is_first_page={2}&lang=zh";
|
||||
public const string UrlIllustUserArtworks = "https://www.pixiv.net/ajax/user/{0}/profile/illusts?{1}work_category=illustManga&is_first_page={2}&lang=zh";
|
||||
public const string UrlIllustUser = "https://www.pixiv.net/users/{0}/artworks";
|
||||
public const string UrlIllustPage = "https://www.pixiv.net/ajax/illust/{0}/pages?lang=zh";
|
||||
public const string UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36";
|
||||
|
||||
Reference in New Issue
Block a user