适配气站工作人员与用户受保护头像

This commit is contained in:
czl231
2026-08-18 20:28:01 +08:00
parent 084eccc3ec
commit fd2a2b38e3
11 changed files with 228 additions and 49 deletions

View File

@@ -1,12 +1,12 @@
/**
* 功能:平台总后台头像上传与鉴权读取客户端。
* 版本v1.1.0
* 功能:气站管理端头像上传与气站范围内鉴权读取客户端。
* 版本v1.2.0
*/
import { getToken } from '@/utils/auth';
const platformApiBaseURL =
const gasApiBaseURL =
import.meta.env.VITE_API_BASE_URL ||
'http://localhost:12426/heqi/platform/v1';
'http://localhost:12426/heqi/gas/v1';
export type AvatarUploadReply = {
uri: string;
@@ -17,13 +17,13 @@ export type AvatarUploadReply = {
type ApiEnvelope<T> = { code?: number; message?: string; details?: T };
/** 生成服务根路径 URL确保上传请求不会错误拼接平台 API 前缀。 */
/** 生成服务根路径 URL确保上传请求不会错误拼接气站 API 前缀。 */
function serviceURL(path: string) {
const platformURL = new URL(platformApiBaseURL, window.location.origin);
return new URL(path, platformURL.origin).toString();
const gasURL = new URL(gasApiBaseURL, window.location.origin);
return new URL(path, gasURL.origin).toString();
}
/** 返回与现有平台请求一致的 JWT 请求头。 */
/** 返回与现有气站请求一致的 JWT 请求头。 */
function authorizationHeaders(): Record<string, string> {
const token = getToken();
return token ? { Authorization: token } : {};
@@ -52,7 +52,7 @@ async function load(
signal?: AbortSignal,
): Promise<Blob | undefined> {
const response = await fetch(
`${platformApiBaseURL}${resource}/${encodeURIComponent(identity)}/avatar`,
`${gasApiBaseURL}${resource}/${encodeURIComponent(identity)}/avatar`,
{ headers: authorizationHeaders(), signal },
);
if (response.status === 404) return undefined;