From 375c18a6d2713ff19b22093eec57315992d8333f Mon Sep 17 00:00:00 2001
From: Codex Assistant <codex@example.com>
Date: 星期四, 06 十一月 2025 13:33:52 +0800
Subject: [PATCH] 增加评审下载
---
web/src/api/media.js | 58 +++++-----------------------------------------------------
1 files changed, 5 insertions(+), 53 deletions(-)
diff --git a/web/src/api/media.js b/web/src/api/media.js
index ac6a772..91f522b 100644
--- a/web/src/api/media.js
+++ b/web/src/api/media.js
@@ -1,5 +1,6 @@
// 濯掍綋鏌ヨ API
import { graphqlRequest, API_CONFIG } from '../config/api.ts';
+import { serverUrl } from '../utils/appConfig.js';
const GRAPHQL_ENDPOINT = API_CONFIG.GRAPHQL_ENDPOINT;
@@ -38,50 +39,12 @@
`;
export const getMediasByTarget = async (targetType, targetId) => {
- // 鑾峰彇JWT token
- const { getToken } = await import('@/utils/auth');
- const token = getToken();
- const headers = { 'Content-Type': 'application/json' };
- if (token) {
- headers['Authorization'] = `Bearer ${token}`;
- }
-
- const res = await fetch(GRAPHQL_ENDPOINT, {
- method: 'POST',
- headers: headers,
- body: JSON.stringify({
- query: MEDIAS_BY_TARGET_QUERY,
- variables: { targetType, targetId }
- })
- });
- const result = await res.json();
- if (result.errors) {
- throw new Error(result.errors[0].message);
- }
+ const result = await graphqlRequest(MEDIAS_BY_TARGET_QUERY, { targetType, targetId });
return result.data.mediasByTarget || [];
};
export const saveMedia = async (input) => {
- // 鑾峰彇JWT token
- const { getToken } = await import('@/utils/auth');
- const token = getToken();
- const headers = { 'Content-Type': 'application/json' };
- if (token) {
- headers['Authorization'] = `Bearer ${token}`;
- }
-
- const res = await fetch(GRAPHQL_ENDPOINT, {
- method: 'POST',
- headers: headers,
- body: JSON.stringify({
- query: SAVE_MEDIA_MUTATION,
- variables: { input }
- })
- });
- const result = await res.json();
- if (result.errors) {
- throw new Error(result.errors[0].message);
- }
+ const result = await graphqlRequest(SAVE_MEDIA_MUTATION, { input });
return result.data.saveMedia;
};
@@ -118,7 +81,7 @@
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
- const response = await fetch('http://localhost:8080/api/upload/image', {
+ const response = await fetch(`${serverUrl}/api/upload/image`, {
method: 'POST',
headers: headers,
body: formData,
@@ -215,17 +178,6 @@
// 缁熶竴鐨� V2 淇濆瓨鎺ュ彛锛堣繑鍥� { success, message, mediaId }锛夛紝绀轰緥锛�
// await saveMediaV2({ targetType: 'player', targetId: 123, path: 'avatar/xxx.jpg', fileName: 'avatar.jpg', fileExt: 'jpg', fileSize: 2048, mediaType: 1 })
export const saveMediaV2 = async (input) => {
- const res = await fetch(GRAPHQL_ENDPOINT, {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({
- query: SAVE_MEDIA_V2_MUTATION,
- variables: { input }
- })
- });
- const result = await res.json();
- if (result.errors) {
- throw new Error(result.errors[0].message);
- }
+ const result = await graphqlRequest(SAVE_MEDIA_V2_MUTATION, { input });
return result.data.saveMediaV2;
};
\ No newline at end of file
--
Gitblit v1.8.0