修改了api的地址
This commit is contained in:
16
index.html
16
index.html
@@ -138,6 +138,8 @@
|
|||||||
<script type="text/babel">
|
<script type="text/babel">
|
||||||
const { useState, useEffect, useRef, useMemo, useCallback } = React;
|
const { useState, useEffect, useRef, useMemo, useCallback } = React;
|
||||||
|
|
||||||
|
// Use relative path for API proxy to avoid CORS issues
|
||||||
|
// Nginx forwards /api/ to sync-server, which proxies /music-api to music-dl.sayqz.com
|
||||||
const API_BASE = "/api/music-api";
|
const API_BASE = "/api/music-api";
|
||||||
// Use relative path for sync service, assuming Nginx proxy is configured to forward /api/kv to the sync service
|
// Use relative path for sync service, assuming Nginx proxy is configured to forward /api/kv to the sync service
|
||||||
const SYNC_API_BASE = "/api";
|
const SYNC_API_BASE = "/api";
|
||||||
@@ -256,7 +258,7 @@
|
|||||||
const api = {
|
const api = {
|
||||||
search: async (keyword, source = 'netease', page = 1) => {
|
search: async (keyword, source = 'netease', page = 1) => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_BASE}/api/?type=search&keyword=${encodeURIComponent(keyword)}&source=${source}&page=${page}`);
|
const res = await fetch(`${API_BASE}?type=search&keyword=${encodeURIComponent(keyword)}&source=${source}&page=${page}`);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.code === 200) {
|
if (data.code === 200) {
|
||||||
const payload = data.data || {};
|
const payload = data.data || {};
|
||||||
@@ -269,14 +271,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
getSongUrl: (id, source, br = '320k') => {
|
getSongUrl: (id, source, br = '320k') => {
|
||||||
return `${API_BASE}/api/?source=${source}&id=${id}&type=url&br=${br}`;
|
return `${API_BASE}?source=${source}&id=${id}&type=url&br=${br}`;
|
||||||
},
|
},
|
||||||
getPicUrl: (id, source) => {
|
getPicUrl: (id, source) => {
|
||||||
return `${API_BASE}/api/?source=${source}&id=${id}&type=pic`;
|
return `${API_BASE}?source=${source}&id=${id}&type=pic`;
|
||||||
},
|
},
|
||||||
getLrc: async (id, source) => {
|
getLrc: async (id, source) => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_BASE}/api/?source=${source}&id=${id}&type=lrc`);
|
const res = await fetch(`${API_BASE}?source=${source}&id=${id}&type=lrc`);
|
||||||
const text = await res.text();
|
const text = await res.text();
|
||||||
return text;
|
return text;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -309,7 +311,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_BASE}/api/?source=${source}&type=toplists`);
|
const res = await fetch(`${API_BASE}/?source=${source}&type=toplists`);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.code === 200) {
|
if (data.code === 200) {
|
||||||
// 兼容多种返回结构:data本身是数组,或者data.list是数组
|
// 兼容多种返回结构:data本身是数组,或者data.list是数组
|
||||||
@@ -326,7 +328,7 @@
|
|||||||
},
|
},
|
||||||
getTopListSongs: async (id, source) => {
|
getTopListSongs: async (id, source) => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_BASE}/api/?source=${source}&id=${id}&type=toplist`);
|
const res = await fetch(`${API_BASE}/?source=${source}&id=${id}&type=toplist`);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.code === 200) {
|
if (data.code === 200) {
|
||||||
const list = Array.isArray(data.data) ? data.data : (data.data.list || data.data.tracks || []);
|
const list = Array.isArray(data.data) ? data.data : (data.data.list || data.data.tracks || []);
|
||||||
@@ -340,7 +342,7 @@
|
|||||||
},
|
},
|
||||||
getPlaylist: async (id, source = 'netease') => {
|
getPlaylist: async (id, source = 'netease') => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_BASE}/api/?type=playlist&id=${id}&source=${source}`);
|
const res = await fetch(`${API_BASE}/?type=playlist&id=${id}&source=${source}`);
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.code === 200 && data.data && Array.isArray(data.data.list)) {
|
if (data.code === 200 && data.data && Array.isArray(data.data.list)) {
|
||||||
return normalizeSongList(data.data.list);
|
return normalizeSongList(data.data.list);
|
||||||
|
|||||||
Reference in New Issue
Block a user