Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Commit

Permalink
迁移一部分代码
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiichiamane committed May 18, 2019
1 parent b8eaab6 commit a67fc28
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 56 deletions.
23 changes: 12 additions & 11 deletions PixivFSUWP/Data/CurrentUser.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using FSharp.Data;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Data.Json;

namespace PixivFSUWP.Data
{
Expand All @@ -19,18 +20,18 @@ public class CurrentUser
public string Avatar50 { get; set; }
public string Avatar170 { get; set; }

public static CurrentUser FromJsonValue(JsonValue Source)
public static CurrentUser FromJsonValue(JsonObject Source)
{
CurrentUser toret = new CurrentUser();
toret.ID = Source.TryGetProperty("id").Value.AsInteger();
toret.Username = Source.TryGetProperty("name").Value.AsString();
toret.UserAccount = Source.TryGetProperty("account").Value.AsString();
toret.Email = Source.TryGetProperty("mail_address").Value.AsString();
toret.IsMailAuthorized= Source.TryGetProperty("is_mail_authorized").Value.AsBoolean();
toret.IsPremium = Source.TryGetProperty("is_premium").Value.AsBoolean();
toret.Avatar16 = Source.TryGetProperty("profile_image_urls").Value.TryGetProperty("px_16x16").Value.AsString();
toret.Avatar50 = Source.TryGetProperty("profile_image_urls").Value.TryGetProperty("px_50x50").Value.AsString();
toret.Avatar170 = Source.TryGetProperty("profile_image_urls").Value.TryGetProperty("px_170x170").Value.AsString();
toret.ID = Convert.ToInt32(Source["id"].GetString());
toret.Username = Source["name"].GetString();
toret.UserAccount = Source["account"].GetString();
toret.Email = Source["mail_address"].GetString();
toret.IsMailAuthorized = Source["is_mail_authorized"].GetBoolean();
toret.IsPremium = Source["is_premium"].GetBoolean();
toret.Avatar16 = Source["profile_image_urls"].GetObject()["px_16x16"].GetString();
toret.Avatar50 = Source["profile_image_urls"].GetObject()["px_50x50"].GetString();
toret.Avatar170 = Source["profile_image_urls"].GetObject()["px_170x170"].GetString();
return toret;
}
}
Expand Down
9 changes: 4 additions & 5 deletions PixivFSUWP/Data/OverAll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using System.IO;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using PixivFS;
using PixivFSCS;
using Windows.ApplicationModel.Core;
using Windows.ApplicationModel.UserActivities;
using Windows.Security.Credentials;
Expand All @@ -15,6 +13,7 @@
using Windows.UI.Xaml.Media.Imaging;
using AdaptiveCards;
using Windows.UI.Shell;
using PixivCS;

namespace PixivFSUWP.Data
{
Expand Down Expand Up @@ -49,9 +48,9 @@ public static void RefreshFollowingList()

public static async Task<MemoryStream> DownloadImage(string Uri)
{
var resStream = await Task.Run(() => new PixivAppAPI(GlobalBaseAPI).csfriendly_no_auth_requests_call_stream("GET",
Uri, new List<Tuple<string, string>>() { ("Referer", "https://app-api.pixiv.net/").ToTuple() })
.ResponseStream);
var resStream = await (await new PixivAppAPI(GlobalBaseAPI).RequestCall("GET",
Uri, new Dictionary<string, string>() { { "Referer", "https://app-api.pixiv.net/" } })).
Content.ReadAsStreamAsync();
var memStream = new MemoryStream();
await resStream.CopyToAsync(memStream);
memStream.Position = 0;
Expand Down
68 changes: 32 additions & 36 deletions PixivFSUWP/LoginPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using PixivFS;
using PixivFSCS;
using System.Threading.Tasks;
using System.Diagnostics;
using Windows.Security.Credentials;
using PixivCS;
using static PixivFSUWP.Data.OverAll;
using FSharp.Data;
using Windows.Data.Json;

// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板

Expand Down Expand Up @@ -84,43 +83,40 @@ private void BtnLogin_Click(object sender, RoutedEventArgs e)

private async void Login()
{
stkTxts.Visibility = Visibility.Collapsed;
stkBtns.Visibility = Visibility.Collapsed;
btnTrouble.Visibility = Visibility.Collapsed;
ringProgress.IsActive = true;
grdLoading.Visibility = Visibility.Visible;
bool success;
JsonObject res = null;
//异步执行登录
var logintask = Task.Run(() =>
try
{
JsonValue res = null;
try
{
if (useToken)
res = GlobalBaseAPI.csfriendly_auth(refresh_token: refreshToken);
else
res = GlobalBaseAPI.csfriendly_auth(username, password);
return (true, res);
}
catch
if (useToken)
res = await GlobalBaseAPI.Auth(RefreshToken: refreshToken);
else
res = await GlobalBaseAPI.Auth(username, password);
success = true;
}
catch
{
success = false;
if (useToken)
{
if (useToken)
useToken = false;
try
{
res = await GlobalBaseAPI.Auth(username, password);
success = true;
}
catch
{
useToken = false;
try
{
res = GlobalBaseAPI.csfriendly_auth(username, password);
return (true, res);
}
catch
{
return (false, res);
}
success = false;
}
return (false, res);
}
});
stkTxts.Visibility = Visibility.Collapsed;
stkBtns.Visibility = Visibility.Collapsed;
btnTrouble.Visibility = Visibility.Collapsed;
ringProgress.IsActive = true;
grdLoading.Visibility = Visibility.Visible;
(var loginres, var jsonres) = await logintask;
if (loginres)
}
if (success)
{
//登录成功
//储存凭证
Expand All @@ -134,12 +130,12 @@ private async void Login()
finally
{
vault.Add(new PasswordCredential(passwordResource, username, password));
vault.Add(new PasswordCredential(refreshTokenResource, username, Data.OverAll.GlobalBaseAPI.refresh_token));
vault.Add(new PasswordCredential(refreshTokenResource, username, Data.OverAll.GlobalBaseAPI.RefreshToken));
}
//登陆完毕后加载默认的收藏集合
BookmarkList = new Data.BookmarkIllustsCollection();
//保存当前的身份信息
currentUser = Data.CurrentUser.FromJsonValue(jsonres.TryGetProperty("response").Value.TryGetProperty("user").Value);
currentUser = Data.CurrentUser.FromJsonValue(res["response"].GetObject()["user"].GetObject());
Frame.Navigate(typeof(MainPage));
}
else btnTrouble.Visibility = Visibility.Visible;
Expand Down
5 changes: 1 addition & 4 deletions PixivFSUWP/PixivFSUWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,7 @@
<PackageReference Include="Microsoft.Toolkit.Uwp">
<Version>5.1.1</Version>
</PackageReference>
<PackageReference Include="PixivFS">
<Version>0.1.5</Version>
</PackageReference>
<PackageReference Include="PixivFSCS">
<PackageReference Include="PixivCS">
<Version>0.1.5</Version>
</PackageReference>
<PackageReference Include="Win2D.uwp">
Expand Down

0 comments on commit a67fc28

Please sign in to comment.