mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-19 14:53:50 +02:00
use cookies when fetching noty images
This commit is contained in:
@@ -238,9 +238,9 @@ namespace VRCX
|
|||||||
return CpuMonitor.Instance.CpuUsage;
|
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)
|
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");
|
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 directoryLocation = Path.Combine(cacheLocation, fileId);
|
||||||
var fileLocation = Path.Combine(directoryLocation, $"{version}.png");
|
var fileLocation = Path.Combine(directoryLocation, $"{version}.png");
|
||||||
|
|
||||||
@@ -24,9 +25,22 @@ namespace VRCX
|
|||||||
Directory.Delete(directoryLocation, true);
|
Directory.Delete(directoryLocation, true);
|
||||||
Directory.CreateDirectory(directoryLocation);
|
Directory.CreateDirectory(directoryLocation);
|
||||||
|
|
||||||
|
Uri uri = new Uri(url);
|
||||||
|
if (uri.Host != imageHost)
|
||||||
|
throw new ArgumentException("Invalid image host", url);
|
||||||
|
|
||||||
using (var client = new WebClient())
|
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);
|
client.DownloadFile(url, fileLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace VRCX
|
|||||||
public class WebApi
|
public class WebApi
|
||||||
{
|
{
|
||||||
public static readonly WebApi Instance;
|
public static readonly WebApi Instance;
|
||||||
private CookieContainer _cookieContainer;
|
public CookieContainer _cookieContainer;
|
||||||
private bool _cookieDirty;
|
private bool _cookieDirty;
|
||||||
private Timer _timer;
|
private Timer _timer;
|
||||||
|
|
||||||
|
|||||||
@@ -5008,14 +5008,30 @@ speechSynthesis.getVoices();
|
|||||||
var imageUrl = await this.notyGetImage(noty);
|
var imageUrl = await this.notyGetImage(noty);
|
||||||
var fileId = extractFileId(imageUrl);
|
var fileId = extractFileId(imageUrl);
|
||||||
var fileVersion = extractFileVersion(imageUrl);
|
var fileVersion = extractFileVersion(imageUrl);
|
||||||
if (fileId && fileVersion) {
|
var imageLocation = '';
|
||||||
return AppApi.GetImage(imageUrl, fileId, fileVersion);
|
try {
|
||||||
} else if (imageUrl) {
|
if (fileId && fileVersion) {
|
||||||
fileVersion = imageUrl.split('/').pop(); // 1416226261.thumbnail-500.png
|
imageLocation = await AppApi.GetImage(
|
||||||
fileId = fileVersion.split('.').shift(); // 1416226261
|
imageUrl,
|
||||||
return AppApi.GetImage(imageUrl, fileId, fileVersion);
|
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 (
|
$app.methods.displayOverlayNotification = function (
|
||||||
|
|||||||
Reference in New Issue
Block a user