Skip to content

Commit 8a9faea

Browse files
committed
✨feat(sources): 支持多个谱面源
1 parent e33e13f commit 8a9faea

11 files changed

Lines changed: 62 additions & 49 deletions

File tree

.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# 谱面列表
2+
CHARTS_SOURCE=https://charts.phicm.focalors.ltd
3+
# 谱面列表(CF)
4+
CHARTS_SOURCE_CF=https://cf.charts.phicm.focalors.ltd
5+
# 谱面列表(Vercel)
6+
CHARTS_SOURCE_VERCEL=https://vercel.charts.phicm.focalors.ltd

config/webpack.prod.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = (env) => {
1616
test: /\.js$/,
1717
loader: 'string-replace-loader',
1818
options: {
19-
search: /https:\/\/charts\.phicommunity\.com\.cn/gi,
19+
search: /https:\/\/charts\.focalors\.ltd/gi,
2020
replace: chartsSource,
2121
},
2222
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
},
4141
"dependencies": {
4242
"dom-element-factory": "^1.5.0",
43+
"dotenv": "^17.2.1",
4344
"oggmented": "^1.0.1",
4445
"stackblur-canvas": "^2.5.0",
4546
"workbox-core": "^6.5.1",

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/LevelOver/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import B15B from 'assets/images/B15B.svg';
1313
import C15C from 'assets/images/C15C.svg';
1414
import F15F from 'assets/images/F15F.svg';
1515
import { gameLevels } from '../constants.js';
16+
import { chartSource } from '../utils/chartSource.js';
1617

1718
window.addEventListener('DOMContentLoaded', () => {
1819
const actx = new (window.AudioContext ||
@@ -156,7 +157,7 @@ window.addEventListener('DOMContentLoaded', () => {
156157
// }
157158
// gradeImage
158159
// 获取歌曲信息
159-
fetch('https://charts.phicm.focalors.ltd/' + play + '/meta.json')
160+
fetch(chartSource + '/' + play + '/meta.json')
160161
.then((response) => response.json())
161162
.then((data) => {
162163
window.window.playResult = {
@@ -228,7 +229,7 @@ window.addEventListener('DOMContentLoaded', () => {
228229
document.body.setAttribute(
229230
'style',
230231
`--background:url(${encodeURI(
231-
'https://charts.phicm.focalors.ltd/' +
232+
chartSource + '/' +
232233
window.playResult.play +
233234
'/' +
234235
window.playResult.songInfo.illustration
@@ -239,7 +240,7 @@ window.addEventListener('DOMContentLoaded', () => {
239240
.setAttribute(
240241
'src',
241242
encodeURI(
242-
'https://charts.phicm.focalors.ltd/' +
243+
chartSource + '/' +
243244
play +
244245
'/' +
245246
window.playResult.songInfo.illustration

src/getChart/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import './style.css';
2+
import { chartSource } from '../utils/chartSource.js';
23

34
window.addEventListener('DOMContentLoaded', () => {
45
let loadingEmbedFrame = document.createElement('iframe');
@@ -73,7 +74,7 @@ window.addEventListener('DOMContentLoaded', () => {
7374
}
7475
});
7576
fetch(
76-
'https://charts.phicm.focalors.ltd/content.json'
77+
chartSource + '/content.json'
7778
)
7879
.then((res) => res.json())
7980
.then((response) => {
@@ -95,7 +96,7 @@ window.addEventListener('DOMContentLoaded', () => {
9596
for (let i = 0; i < window.songCodeNameList.length; i++) {
9697
fetch(
9798
encodeURI(
98-
'https://charts.phicm.focalors.ltd/' +
99+
chartSource + '/' +
99100
window.songCodeNameList[i] +
100101
'/meta.json'
101102
)
@@ -152,7 +153,7 @@ window.addEventListener('DOMContentLoaded', () => {
152153
);
153154
fetch(
154155
encodeURI(
155-
'https://charts.phicm.focalors.ltd/' +
156+
chartSource + '/' +
156157
metaObj.codename +
157158
'/' +
158159
metaObj.illustration

src/loadingChartScreen/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import './style.css';
22
import tips from 'assets/tips.json';
3+
import { chartSource } from '../utils/chartSource.js';
34

45
window.addEventListener('DOMContentLoaded', () => {
56
const rndNum = parseInt(Math.random() * (tips.length + 1), 10);
@@ -12,7 +13,7 @@ window.addEventListener('DOMContentLoaded', () => {
1213
const chart = parsedURLParams.get('c');
1314
const level = parsedURLParams.get('l').toLowerCase();
1415
fetch(
15-
encodeURI('https://charts.phicm.focalors.ltd/' + chart + '/meta.json')
16+
encodeURI(chartSource + '/' + chart + '/meta.json')
1617
)
1718
.then((response) => response.json())
1819
.then((songInfoObj) => {
@@ -34,7 +35,7 @@ window.addEventListener('DOMContentLoaded', () => {
3435
.setAttribute(
3536
'src',
3637
encodeURI(
37-
'https://charts.phicm.focalors.ltd/' +
38+
chartSource + '/' +
3839
chart +
3940
'/' +
4041
songInfoObj.illustration
@@ -44,7 +45,7 @@ window.addEventListener('DOMContentLoaded', () => {
4445
'style',
4546
'--background: url(' +
4647
encodeURI(
47-
'https://charts.phicm.focalors.ltd/' +
48+
chartSource + '/' +
4849
chart +
4950
'/' +
5051
songInfoObj.illustration

src/songSelect/SongList.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { gameLevels } from '../constants.js';
22
import selectSongItem_mp3 from 'assets/audio/selectSongItem.mp3';
3-
import {DB} from '../utils/DB.js';
3+
import { DB } from '../utils/DB.js';
4+
import { chartSource } from '../utils/chartSource.js';
45

56
function SongList({ defaultLevel = 'ez' }) {
67
const listElement = document.createElement('div');
@@ -103,7 +104,7 @@ function SongList({ defaultLevel = 'ez' }) {
103104
currentLevelSelected = [nextLevel];
104105
}
105106
fetch(
106-
`https://charts.phicm.focalors.ltd/${codename}/${songMeta['illustration']}`
107+
`${chartSource}/${codename}/${songMeta['illustration']}`
107108
)
108109
.then((response) => response.blob())
109110
.then((blob) => {
@@ -115,14 +116,14 @@ function SongList({ defaultLevel = 'ez' }) {
115116
document.querySelector('img.illustration').src = imgUrl;
116117
})
117118
.catch((err) => {
118-
console.err(
119+
console.error(
119120
'获取曲绘失败!',
120-
`url: https://charts.phicm.focalors.ltd/${codename}/${songMeta['illustration']}`,
121+
`url: ${chartSource}/${codename}/${songMeta['illustration']}`,
121122
err
122123
);
123124
});
124125
fetch(
125-
`https://charts.phicm.focalors.ltd/${codename}/${songMeta['musicFile']}`
126+
`${chartSource}/${codename}/${songMeta['musicFile']}`
126127
)
127128
.then((response) => response.blob())
128129
.then((blob) => {
@@ -195,9 +196,9 @@ function SongList({ defaultLevel = 'ez' }) {
195196
});
196197
})
197198
.catch((err) => {
198-
console.err(
199+
console.error(
199200
'获取歌曲失败!',
200-
`url: https://charts.phicm.focalors.ltd/${codename}/${songMeta['musicFile']}`,
201+
`url: ${chartSource}/${codename}/${songMeta['musicFile']}`,
201202
err
202203
);
203204
});

src/songSelect/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { SongList } from './SongList.js';
22
// import { gameLevels } from '../constants.js';
33
import Start_mp3 from 'assets/audio/Start.mp3';
44
import './style.css';
5+
import { chartSource } from '../utils/chartSource.js';
56

67
const songList = SongList({ defaultLevel: 'ez' });
78

@@ -85,7 +86,7 @@ window.addEventListener('DOMContentLoaded', () => {
8586
for (let i = 0; i < window.songCodeNameList.length; i++) {
8687
fetch(
8788
encodeURI(
88-
'https://charts.phicm.focalors.ltd/' +
89+
chartSource + '/' +
8990
window.songCodeNameList[i] +
9091
'/meta.json'
9192
)

src/utils/chartSource.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const chartSource = isCloudflarePages()
2+
? 'https://cf.charts.phicm.focalors.ltd'
3+
: isVercel()
4+
? 'https://vercel.charts.phicm.focalors.ltd'
5+
: 'https://charts.phicm.focalors.ltd';
6+
7+
function isCloudflarePages() {
8+
return window.location.hostname.includes('cf');
9+
}
10+
function isVercel() {
11+
return window.location.hostname.includes('vercel');
12+
}

0 commit comments

Comments
 (0)