| | |
| | | `; |
| | | |
| | | 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; |
| | | }; |
| | | |
| | |
| | | // 统一的 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; |
| | | }; |