Files
life-echo/app-expo/src/core/api/media-url.ts
Kevin 7ad52fce89 feat(profile): avatar presets, upload, nickname editing
- FastAPI: preset assets 01–08, GET list/static, PUT /me/avatar/preset,
  safer uploaded-avatar path validation, preset_avatars + HTTP tests.
- Expo: personal-info (library + presets), profile tab avatar,
  resolveApiMediaUrl, auth hooks cache sync, Web multipart helper,
  partial-save messaging + profile i18n.
- Includes existing edits to conversation screen and voice use-player.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-06 13:51:43 +08:00

15 lines
504 B
TypeScript

import { config } from '@/core/config';
/** 将 API 返回的相对路径(如 `/api/auth/avatars/x.jpg`)转为可请求的绝对 URL。 */
export function resolveApiMediaUrl(
pathOrUrl: string | null | undefined,
): string | null {
if (pathOrUrl == null || pathOrUrl === '') return null;
if (/^https?:\/\//i.test(pathOrUrl)) return pathOrUrl;
if (pathOrUrl.startsWith('/')) {
const base = config.apiBaseUrl.replace(/\/$/, '');
return `${base}${pathOrUrl}`;
}
return pathOrUrl;
}