mirror of
https://github.com/vrcx-team/VRCX.git
synced 2026-04-06 00:32:02 +02:00
use cookies when fetching noty images
This commit is contained in:
@@ -238,9 +238,9 @@ namespace VRCX
|
||||
return CpuMonitor.Instance.CpuUsage;
|
||||
}
|
||||
|
||||
public string GetImage(string url, string fileId, string version)
|
||||
public string GetImage(string url, string fileId, string version, string appVersion)
|
||||
{
|
||||
return ImageCache.GetImage(url, fileId, version);
|
||||
return ImageCache.GetImage(url, fileId, version, appVersion);
|
||||
}
|
||||
|
||||
public void DesktopNotification(string BoldText, string Text, string Image)
|
||||
|
||||
@@ -9,8 +9,9 @@ namespace VRCX
|
||||
{
|
||||
private static readonly string cacheLocation = Path.Combine(Program.AppDataDirectory, "ImageCache");
|
||||
|
||||
public static string GetImage(string url, string fileId, string version)
|
||||
public static string GetImage(string url, string fileId, string version, string appVersion)
|
||||
{
|
||||
var imageHost = "api.vrchat.cloud";
|
||||
var directoryLocation = Path.Combine(cacheLocation, fileId);
|
||||
var fileLocation = Path.Combine(directoryLocation, $"{version}.png");
|
||||
|
||||
@@ -24,9 +25,22 @@ namespace VRCX
|
||||
Directory.Delete(directoryLocation, true);
|
||||
Directory.CreateDirectory(directoryLocation);
|
||||
|
||||
Uri uri = new Uri(url);
|
||||
if (uri.Host != imageHost)
|
||||
throw new ArgumentException("Invalid image host", url);
|
||||
|
||||
using (var client = new WebClient())
|
||||
{
|
||||
client.Headers.Add("user-agent", "VRCX");
|
||||
string cookieString = String.Empty;
|
||||
if (WebApi.Instance != null && WebApi.Instance._cookieContainer != null)
|
||||
{
|
||||
CookieCollection cookies = WebApi.Instance._cookieContainer.GetCookies(new Uri($"https://{imageHost}"));
|
||||
foreach (Cookie cookie in cookies)
|
||||
cookieString += $"{cookie.Name}={cookie.Value};";
|
||||
}
|
||||
|
||||
client.Headers.Add(HttpRequestHeader.Cookie, cookieString);
|
||||
client.Headers.Add("user-agent", appVersion);
|
||||
client.DownloadFile(url, fileLocation);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace VRCX
|
||||
public class WebApi
|
||||
{
|
||||
public static readonly WebApi Instance;
|
||||
private CookieContainer _cookieContainer;
|
||||
public CookieContainer _cookieContainer;
|
||||
private bool _cookieDirty;
|
||||
private Timer _timer;
|
||||
|
||||
|
||||
@@ -5008,14 +5008,30 @@ speechSynthesis.getVoices();
|
||||
var imageUrl = await this.notyGetImage(noty);
|
||||
var fileId = extractFileId(imageUrl);
|
||||
var fileVersion = extractFileVersion(imageUrl);
|
||||
if (fileId && fileVersion) {
|
||||
return AppApi.GetImage(imageUrl, fileId, fileVersion);
|
||||
} else if (imageUrl) {
|
||||
fileVersion = imageUrl.split('/').pop(); // 1416226261.thumbnail-500.png
|
||||
fileId = fileVersion.split('.').shift(); // 1416226261
|
||||
return AppApi.GetImage(imageUrl, fileId, fileVersion);
|
||||
var imageLocation = '';
|
||||
try {
|
||||
if (fileId && fileVersion) {
|
||||
imageLocation = await AppApi.GetImage(
|
||||
imageUrl,
|
||||
fileId,
|
||||
fileVersion,
|
||||
appVersion
|
||||
);
|
||||
} else if (imageUrl) {
|
||||
fileVersion = imageUrl.split('/').pop(); // 1416226261.thumbnail-500.png
|
||||
fileId = fileVersion.split('.').shift(); // 1416226261
|
||||
imageLocation = await AppApi.GetImage(
|
||||
imageUrl,
|
||||
fileId,
|
||||
fileVersion,
|
||||
appVersion
|
||||
);
|
||||
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
return '';
|
||||
return imageLocation;
|
||||
};
|
||||
|
||||
$app.methods.displayOverlayNotification = function (
|
||||
|
||||
Reference in New Issue
Block a user