Skip to content

Commit

Permalink
closed #7 ,FINISHED! :>
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamarine5 committed Jan 2, 2022
1 parent 8041487 commit 12e93ad
Show file tree
Hide file tree
Showing 21 changed files with 144 additions and 55 deletions.
2 changes: 1 addition & 1 deletion Aesc.AwesomeKits/ArgsParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Collections.Generic;
using System.Text;

namespace Aesc.AwesomeKits
namespace Aesc.AwesomeKits.Util
{
public delegate void ParseValueDelegate(FieldInfo field, object obj, object value);
public class AescArgsParser
Expand Down
18 changes: 11 additions & 7 deletions Aesc.AwesomeKits/Bilibili.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
using Aesc.AwesomeKits;
using Newtonsoft.Json.Linq;

namespace Aesc.AwesomeKits
namespace Aesc.AwesomeKits.Net.WebStorage
{
public class BiliCommit
public class BiliCommitMsgPvder
{
public List<BiliReply> biliReplies;
public List<BiliReply> biliReplies = new List<BiliReply>();
public string commitText;
public BiliCommit(int id)
public BiliCommitMsgPvder(string id)
{
var commitTextJson = WebRequest.CreateHttp("https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/get_dynamic_detail?dynamic_id" + id)
var commitTextJson = WebRequest.CreateHttp("https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/get_dynamic_detail?dynamic_id=" + id)
.SendGet().ReadJsonObject()["data"]["card"]["card"].ToString();
commitText = JObject.Parse(commitTextJson)["item"]["content"].ToString();
var replyJsonArray = JArray.FromObject(WebRequest.CreateHttp("https://api.bilibili.com/x/v2/reply/main?jsonp=jsonp&next=0&type=17&mode=2&plat=1&oid" + id)
.SendGet().ReadJsonObject()["data"]["replies"].ToString());
var content = WebRequest.CreateHttp("https://api.bilibili.com/x/v2/reply/main?jsonp=jsonp&next=0&type=17&mode=2&plat=1&oid=" + id)
.SendGet().ReadJsonObject()["data"]["replies"].ToString();
Console.WriteLine(content);
var replyJsonArray = JArray.Parse(content);
foreach (var replyJson in replyJsonArray)
{
biliReplies.Add(new BiliReply()
Expand All @@ -26,6 +28,8 @@ public BiliCommit(int id)
});
}
}
public BiliCommitMsgPvder(long id) => new BiliCommitMsgPvder(id.ToString());

}
public struct BiliReply
{
Expand Down
9 changes: 5 additions & 4 deletions Aesc.AwesomeKits/Examples/ArgsParserExample.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using Aesc.AwesomeKits;
using Aesc.AwesomeKits.Util;
using System;
#pragma warning disable 0649
namespace Aesc.AwesomeKits.Examples
{
class ArgsParserExample
{
// If you want to test this program,
// Please rename this function to Main.
/// <summary>
/// <i>If you want to test this method, please rename this function to "Main"</i><br/><br/>
/// Seealso: <seealso cref="AescArgsParser"/>
/// </summary>
public static void ArgsParserExampleMain(string[] args)
{
Result result = AescArgsParser.Parse<Result>(args);
Expand All @@ -19,7 +21,6 @@ public static void ArgsParserExampleMain(string[] args)
}
public struct Result : IArgsParseResult
{

public string str;
public int inputInt;
public float testFloat;
Expand Down
18 changes: 18 additions & 0 deletions Aesc.AwesomeKits/Examples/NetdiskServiceExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Text;
using Aesc.AwesomeKits.Util;
using Aesc.AwesomeKits.Net.WebStorage;
using Aesc.AwesomeKits.Net;

namespace Aesc.AwesomeKits.Examples
{
class NetdiskServiceExample
{
public static void Main(string[] args)
{
var disk = new Huang1111Netdisk();
disk.Upload("C:\\Users\\44319\\Downloads\\genshin-gacha-export.zip");
}
}
}
8 changes: 6 additions & 2 deletions Aesc.AwesomeKits/Examples/TaskSchedulerExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
using System.Collections.Generic;
using System.Text;
using TaskScheduler;
using Aesc.AwesomeKits;
using Aesc.AwesomeKits.ComUtil;

namespace Aesc.AwesomeKits.Examples
{
class TaskSchedulerExample
{
public static void lMain(string[] args)
/// <summary>
/// <i>If you want to test this method, please rename this function to "Main"</i><br/><br/>
/// Seealso: <seealso cref="AescTaskScheduler"/>
/// </summary>
public static void TaskSchedulerMain(string[] args)
{
Console.WriteLine(args.Length);
Console.WriteLine(args[0]);
Expand Down
67 changes: 58 additions & 9 deletions Aesc.AwesomeKits/NetdiskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
using System.Net;
using Newtonsoft.Json.Linq;

namespace Aesc.AwesomeKits
namespace Aesc.AwesomeKits.Net.WebStorage
{
public interface IMessageProvider
{
public void GetMessage(string body);
}
public interface IImageHost
{
public void Upload(string imageFilepath);
Expand All @@ -22,13 +26,62 @@ public interface INetdiskDownloader
{
public void Download(string data, string filepath);
}
public class Huang111Netdisk : INetdiskDownloader
public class Huang1111Netdisk : INetdiskDownloader,INetdiskUploader
{
public string GetCookies()
{
BiliCommitMsgPvder biliCommit = new BiliCommitMsgPvder("610967597602910149");
return biliCommit.biliReplies[0].text;
}
public string ParseUrl(string key) =>
WebRequest.CreateHttp($"https://pan.huang1111.cn/api/v3/share/download/{key}").SendPut(null).ReadJsonObject()["data"].ToString();
WebRequest.CreateHttp($"https://pan.huang1111.cn/api/v3/share/download/{ key}").SendPut(null).ReadJsonObject()["data"].ToString();

public void Download(string key, string filepath) =>
WebRequest.CreateHttp(ParseUrl(key)).SendGet().WriteToFile(filepath);

public void Upload(string filename)
{
string defaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62";
string cookies = GetCookies();
var file = new System.IO.FileInfo(filename);
var webRequest = WebRequest.CreateHttp($"https://pan.huang1111.cn/api/v3/file/upload/credential?path=%2F&size={ file.Length }&name={ file.Name }&type=onedrive");
webRequest.Headers[HttpRequestHeader.Cookie] = cookies;
webRequest.Referer = "https://pan.huang1111.cn/home?path=%2F";
webRequest.UserAgent = defaultUserAgent;
var credentialResponce = webRequest.SendGet().ReadJsonObject()["data"];
string policy = credentialResponce["policy"].ToString();
if (policy == "")
{
var postWebRequest = WebRequest.CreateHttp("https://pan.huang1111.cn/api/v3/file/upload?chunk=0&chunks=1");
postWebRequest.Headers[HttpRequestHeader.Cookie] = cookies;
postWebRequest.Headers["x-cr-path"] = "/";
postWebRequest.Headers["x-cr-filename"] = file.Name;
postWebRequest.Referer = "https://pan.huang1111.cn/home?path=%2F";
postWebRequest.UserAgent = defaultUserAgent;
postWebRequest.ContentType = "application/octet-stream";
postWebRequest.Method = "POST";
string uploadResponce = postWebRequest.AddFile(filename).SendPost().ReadText();
Console.WriteLine(uploadResponce);
}
else
{
var putWebRequest = WebRequest.CreateHttp(policy);
putWebRequest.Referer = "https://pan.huang1111.cn/";
putWebRequest.ContentType = "application/octet-stream";
putWebRequest.UserAgent = defaultUserAgent;
putWebRequest.Headers[HttpRequestHeader.ContentRange] = $"bytes 0-{file.Length - 1}/{file.Length}";
putWebRequest.Method = "PUT";
string uploadResponce = putWebRequest.AddFile(filename).SendPut().ReadText();
var finishWebRequest = WebRequest.CreateHttp(credentialResponce["token"].ToString());
finishWebRequest.UserAgent = defaultUserAgent;
finishWebRequest.ContentType = "text/plain;charset=UTF-8";
finishWebRequest.Headers[HttpRequestHeader.Cookie] = cookies;
finishWebRequest.Referer = "https://pan.huang1111.cn/home?path=%2F";
finishWebRequest.Method = "POST";
var finishResponce = finishWebRequest.AddText(uploadResponce).SendPost().ReadJsonObject();
Console.WriteLine(finishResponce.ToString());
}
}
}
public class SMMSImageHost : IImageHost
{
Expand All @@ -45,7 +98,7 @@ public void Upload(string imageFilepath)
httpRequest.Timeout = 120000;
try
{
httpRequest.SendPostWithFile(imageFilepath, "smfile").ReadJsonObject();
httpRequest.AddFormdata(imageFilepath, "smfile").SendPost().ReadJsonObject();
}
catch (WebException e)
{
Expand All @@ -54,16 +107,12 @@ public void Upload(string imageFilepath)
}
}
}
public class QiniuNetdisk : INetdiskDownloader, INetdiskUploader
public class QiniuNetdisk : INetdiskUploader
{
Mac mac;
public QiniuNetdisk(string accessKey, string secretKey)
{
mac = new Mac(accessKey, secretKey);
}
public void Download(string data, string filepath)
{

}
public void Upload(string filename)
{
Expand Down
2 changes: 1 addition & 1 deletion Aesc.AwesomeKits/TaskScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using TaskScheduler;

namespace Aesc.AwesomeKits
namespace Aesc.AwesomeKits.ComUtil
{
public static class TriggerLinq
{
Expand Down
71 changes: 42 additions & 29 deletions Aesc.AwesomeKits/WebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,76 @@
using System.Net;
using System.Text;

namespace Aesc.AwesomeKits
namespace Aesc.AwesomeKits.Net
{
public static class WebRequestLinq
public static class WebRequestExtention
{
public static WebResponse SendGet(this HttpWebRequest webRequest)
public static WebResponse SendGet(this HttpWebRequest webRequest) => webRequest.SendRequest("GET");
public static WebResponse SendPost(this HttpWebRequest webRequest, string body="") => webRequest.AddText(body).SendRequest("POST");
public static WebResponse SendPut(this HttpWebRequest webRequest, string body="") => webRequest.AddText(body).SendRequest("PUT");
public static WebResponse SendRequest(this HttpWebRequest webRequest,string method)
{
webRequest.Method = "GET";
webRequest.Method = method;
return webRequest.GetResponse();
}
public static WebResponse SendPost(this HttpWebRequest webRequest, string body)
}
public static class WebRequestStreamExtention
{
public static HttpWebRequest AddText(this HttpWebRequest webRequest,string text,string encoding="UTF-8")
{
webRequest.Method = "POST";
if (text == "") return webRequest;
var stream = webRequest.GetRequestStream();
var bytes = Encoding.UTF8.GetBytes(body);
stream.Write(bytes, 0, bytes.Length);
stream.Close();
webRequest.ContentLength = bytes.Length;
return webRequest.GetResponse();
var bytes = Encoding.GetEncoding(encoding).GetBytes(text);
stream.Write(bytes);
return webRequest;
}
public static WebResponse SendPostWithFile(this HttpWebRequest webRequest, string filePath, string key)
// TODO: 完善Formdata
public static HttpWebRequest AddFormdata(this HttpWebRequest webRequest,string filePath,string key)
{
webRequest.Method = "POST";
var boundary = DateTime.Now.Ticks.ToString("x");
var startBoundary = Encoding.ASCII.GetBytes($"--{boundary}\r\n");
var endBoundary = Encoding.ASCII.GetBytes($"--{boundary}--\r\n");
var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
webRequest.ContentType = $"multipart/form-data; boundary={boundary}";
var memoryStream = new MemoryStream();
var splitFileContent = Encoding.ASCII.GetBytes($"Content-Disposition: form-data; name=\"{key}\"; filename=\"{Path.GetFileName(filePath)}\"\r\n" +
"Content-Type: application/octet-stream\r\n\r\n");

memoryStream.Write(startBoundary, 0, startBoundary.Length);
memoryStream.Write(splitFileContent, 0, splitFileContent.Length);
var stream = webRequest.GetRequestStream();
var splitFileContent = Encoding.ASCII.GetBytes(
$"Content-Disposition: form-data; name=\"{key}\"; filename=\"{Path.GetFileName(filePath)}\"\r\n" +
"Content-Type: application/octet-stream\r\n\r\n");
stream.Write(startBoundary, 0, startBoundary.Length);
stream.Write(splitFileContent, 0, splitFileContent.Length);
var fileBuffer = new byte[1024];
int totalSize = 0;
int size = fileStream.Read(fileBuffer, 0, fileBuffer.Length);
while (size > 0)
{
totalSize += size;
memoryStream.Write(fileBuffer, 0, size);
stream.Write(fileBuffer, 0, size);
size = fileStream.Read(fileBuffer, 0, fileBuffer.Length);
}
memoryStream.Write(endBoundary, 0, endBoundary.Length);
webRequest.ContentLength = memoryStream.Length;
return webRequest.GetResponse();
stream.Write(endBoundary, 0, endBoundary.Length);
webRequest.ContentLength = stream.Length;
return webRequest;
}
public static WebResponse SendPut(this HttpWebRequest webRequest,string body)
public static HttpWebRequest AddFile(this HttpWebRequest webRequest,string filePath)
{
webRequest.Method = "PUT";
if (body == "" || body == null)
var file = new FileInfo(filePath);
webRequest.ContentLength = file.Length;
var stream = webRequest.GetRequestStream();
var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
var fileBuffer = new byte[1024];
int totalSize = 0;
int size = fileStream.Read(fileBuffer, 0, fileBuffer.Length);
while (size > 0)
{

totalSize += size;
stream.Write(fileBuffer, 0, size);
size = fileStream.Read(fileBuffer, 0, fileBuffer.Length);
}
return webRequest.GetResponse();
fileStream.Close();
return webRequest;
}
}
public static class WebResponseLinq
public static class WebResponseExtention
{
public static string ReadText(this WebResponse webResponse)
{
Expand Down
Binary file not shown.
Binary file modified Aesc.AwesomeKits/bin/Debug/netcoreapp3.1/Aesc.AwesomeKits.pdb
Binary file not shown.
Binary file modified Aesc.AwesomeKits/bin/Release/netcoreapp3.1/Aesc.AwesomeKits.dll
Binary file not shown.
Binary file modified Aesc.AwesomeKits/bin/Release/netcoreapp3.1/Aesc.AwesomeKits.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
003719249b683fb55661c504ca858e7e0ef879f5
09f81b044c954e406ebdef2d1f40a1df49661be2
Binary file not shown.
Binary file not shown.
Binary file modified Aesc.AwesomeKits/obj/Debug/netcoreapp3.1/Aesc.AwesomeKits.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
677d4f6574f8c4f01a5e19de6eead97071ed44f5
aebe30ab71f97be36d179875d722b5f1759991c0
Binary file not shown.
Binary file modified Aesc.AwesomeKits/obj/Release/netcoreapp3.1/Aesc.AwesomeKits.dll
Binary file not shown.
Binary file modified Aesc.AwesomeKits/obj/Release/netcoreapp3.1/Aesc.AwesomeKits.exe
Binary file not shown.
Binary file modified Aesc.AwesomeKits/obj/Release/netcoreapp3.1/Aesc.AwesomeKits.pdb
Binary file not shown.

0 comments on commit 12e93ad

Please sign in to comment.