迁移domite
This commit is contained in:
83
Assets/00.StaryEvo/Runtime/Utility/RemoteServices.cs
Normal file
83
Assets/00.StaryEvo/Runtime/Utility/RemoteServices.cs
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
/****************************************************
|
||||||
|
文件:RemoteServicesWithAuth.cs
|
||||||
|
作者:xosmo_
|
||||||
|
邮箱:
|
||||||
|
日期:2025/3/31 14:39:5
|
||||||
|
功能:
|
||||||
|
*****************************************************/
|
||||||
|
|
||||||
|
using YooAsset;
|
||||||
|
using System.Collections;
|
||||||
|
using Stary.Evo;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
|
public class RemoteServicesWithAuth : IRemoteServices
|
||||||
|
{
|
||||||
|
private readonly string _defaultHostServer;
|
||||||
|
private readonly string _fallbackHostServer;
|
||||||
|
private string _authToken;
|
||||||
|
private string _authServiceUrl;
|
||||||
|
|
||||||
|
public string CurrentToken { get; private set; }
|
||||||
|
|
||||||
|
public RemoteServicesWithAuth(string defaultHostServer,
|
||||||
|
string fallbackHostServer,
|
||||||
|
string authToken,
|
||||||
|
string authServiceUrl)
|
||||||
|
{
|
||||||
|
_defaultHostServer = defaultHostServer;
|
||||||
|
_fallbackHostServer = fallbackHostServer;
|
||||||
|
_authToken = authToken;
|
||||||
|
_authServiceUrl = authServiceUrl;
|
||||||
|
RefreshToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshToken()
|
||||||
|
{
|
||||||
|
// 这里实现具体的token刷新逻辑
|
||||||
|
CurrentToken = _authToken; // 简单示例直接使用初始token
|
||||||
|
// 实际项目应该通过authServiceUrl获取新token
|
||||||
|
}
|
||||||
|
|
||||||
|
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||||
|
{
|
||||||
|
// 在原始URL后附加鉴权参数
|
||||||
|
return $"{_defaultHostServer}/{fileName}?token={CurrentToken}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetRemoteFallbackURL(string fileName)
|
||||||
|
{
|
||||||
|
return $"{_fallbackHostServer}/{fileName}?token={CurrentToken}";
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnityWebRequest CreateRequest(string url)
|
||||||
|
// {
|
||||||
|
// var request = base.CreateRequest(url);
|
||||||
|
// request.SetRequestHeader("Authorization", $"Bearer {CurrentToken}");
|
||||||
|
// return request;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
using YooAsset;
|
||||||
|
|
||||||
|
namespace Stary.Evo
|
||||||
|
{
|
||||||
|
public class RemoteServices : IRemoteServices
|
||||||
|
{
|
||||||
|
private readonly string _defaultHostServer;
|
||||||
|
private readonly string _fallbackHostServer;
|
||||||
|
|
||||||
|
public RemoteServices(string defaultHostServer, string fallbackHostServer)
|
||||||
|
{
|
||||||
|
_defaultHostServer = defaultHostServer;
|
||||||
|
_fallbackHostServer = fallbackHostServer;
|
||||||
|
}
|
||||||
|
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||||
|
{
|
||||||
|
return $"{_defaultHostServer}/{fileName}";
|
||||||
|
}
|
||||||
|
string IRemoteServices.GetRemoteFallbackURL(string fileName)
|
||||||
|
{
|
||||||
|
return $"{_fallbackHostServer}/{fileName}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 31bc0d173f0687d4a9f3c114a2aaa659
|
||||||
|
timeCreated: 1741248220
|
||||||
59
Assets/00.StaryEvo/Runtime/Utility/RemoteServicesWithAuth.cs
Normal file
59
Assets/00.StaryEvo/Runtime/Utility/RemoteServicesWithAuth.cs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/****************************************************
|
||||||
|
文件:RemoteServicesWithAuth.cs
|
||||||
|
作者:xosmo_
|
||||||
|
邮箱:
|
||||||
|
日期:2025/3/31 14:39:5
|
||||||
|
功能:
|
||||||
|
*****************************************************/
|
||||||
|
|
||||||
|
using YooAsset;
|
||||||
|
using System.Collections;
|
||||||
|
using Stary.Evo;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
|
public class RemoteServicesWithAuth : IRemoteServices
|
||||||
|
{
|
||||||
|
private readonly string _defaultHostServer;
|
||||||
|
private readonly string _fallbackHostServer;
|
||||||
|
private string _authToken;
|
||||||
|
private string _authServiceUrl;
|
||||||
|
|
||||||
|
public string CurrentToken { get; private set; }
|
||||||
|
|
||||||
|
public RemoteServicesWithAuth(string defaultHostServer,
|
||||||
|
string fallbackHostServer,
|
||||||
|
string authToken,
|
||||||
|
string authServiceUrl)
|
||||||
|
{
|
||||||
|
_defaultHostServer = defaultHostServer;
|
||||||
|
_fallbackHostServer = fallbackHostServer;
|
||||||
|
_authToken = authToken;
|
||||||
|
_authServiceUrl = authServiceUrl;
|
||||||
|
RefreshToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RefreshToken()
|
||||||
|
{
|
||||||
|
// 这里实现具体的token刷新逻辑
|
||||||
|
CurrentToken = _authToken; // 简单示例直接使用初始token
|
||||||
|
// 实际项目应该通过authServiceUrl获取新token
|
||||||
|
}
|
||||||
|
|
||||||
|
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||||
|
{
|
||||||
|
// 在原始URL后附加鉴权参数
|
||||||
|
return $"{_defaultHostServer}/{fileName}?token={CurrentToken}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetRemoteFallbackURL(string fileName)
|
||||||
|
{
|
||||||
|
return $"{_fallbackHostServer}/{fileName}?token={CurrentToken}";
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnityWebRequest CreateRequest(string url)
|
||||||
|
// {
|
||||||
|
// var request = base.CreateRequest(url);
|
||||||
|
// request.SetRequestHeader("Authorization", $"Bearer {CurrentToken}");
|
||||||
|
// return request;
|
||||||
|
// }
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 595ab2ad4ef04194baaed976c83e976f
|
||||||
|
timeCreated: 1741319247
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "com.staryevo.main",
|
"name": "com.staryevo.main",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"displayName": "00.StaryEvo",
|
"displayName": "00.StaryEvo",
|
||||||
"description": "This is an Framework package",
|
"description": "This is an Framework package",
|
||||||
"unity": "2021.3",
|
"unity": "2021.3",
|
||||||
|
|||||||
Reference in New Issue
Block a user