fix: 音频文件切换为minio外链

This commit is contained in:
streakingman 2022-11-10 07:57:54 +08:00
parent ffabf6805f
commit 680811c50c
5 changed files with 35 additions and 74 deletions

View File

@ -94,9 +94,6 @@ ps: 如果您的项目托管在公共仓库中,请注意保护密钥,本地
`config` 表用来存储自定义配置的 json 字符串,需要新增 `content` `config` 表用来存储自定义配置的 json 字符串,需要新增 `content`
`file` 表则是为了节省 vercel 流量,将一些默认文件转为 base64 字符串存到了数据库中,需要添加三列
![img.png](database-file.png)
`rank` 表,储存排名信息 `rank` 表,储存排名信息
![img.png](datebase-rank.png) ![img.png](datebase-rank.png)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

View File

@ -5,11 +5,7 @@ import './styles/global.scss';
import './styles/utils.scss'; import './styles/utils.scss';
import Bmob from 'hydrogen-js-sdk'; import Bmob from 'hydrogen-js-sdk';
import { import {
DEFAULT_BGM_STORAGE_KEY,
domRelatedOptForTheme, domRelatedOptForTheme,
LAST_LEVEL_STORAGE_KEY,
LAST_SCORE_STORAGE_KEY,
LAST_TIME_STORAGE_KEY,
parsePathCustomThemeId, parsePathCustomThemeId,
PLAYING_THEME_ID_STORAGE_KEY, PLAYING_THEME_ID_STORAGE_KEY,
resetScoreStorage, resetScoreStorage,
@ -77,9 +73,8 @@ Bmob.initialize(
import.meta.env.VITE_BMOB_SECCODE import.meta.env.VITE_BMOB_SECCODE
); );
const loadTheme = () => { // 请求主题
// 请求主题 if (customThemeIdFromPath) {
if (customThemeIdFromPath) {
const storageTheme = localStorage.getItem(customThemeIdFromPath); const storageTheme = localStorage.getItem(customThemeIdFromPath);
if (storageTheme) { if (storageTheme) {
try { try {
@ -109,26 +104,6 @@ const loadTheme = () => {
errorTip(error); errorTip(error);
}); });
} }
} else {
successTrans(getDefaultTheme());
}
};
// 音效资源请求
if (!localStorage.getItem(DEFAULT_BGM_STORAGE_KEY)) {
const query = Bmob.Query('file');
query.equalTo('type', '==', 'default');
query
.find()
.then((results) => {
for (const file of results as any) {
localStorage.setItem(file.name, file.base64);
}
loadTheme();
})
.catch(({ error }) => {
errorTip(error);
});
} else { } else {
loadTheme(); successTrans(getDefaultTheme());
} }

View File

@ -1,9 +1,4 @@
import { Theme } from '../interface'; import { Theme } from '../interface';
import {
DEFAULT_BGM_STORAGE_KEY,
DEFAULT_CLICK_SOUND_STORAGE_KEY,
DEFAULT_TRIPLE_SOUND_STORAGE_KEY,
} from '../../utils';
const icons = <const>[ const icons = <const>[
`🎨`, `🎨`,
@ -36,16 +31,13 @@ export const getDefaultTheme: () => Theme<DefaultSoundNames> = () => {
sounds: [ sounds: [
{ {
name: 'button-click', name: 'button-click',
src: src: 'https://minio.streakingman.com/solvable-sheep-game/sound-button-click.mp3',
localStorage.getItem(DEFAULT_CLICK_SOUND_STORAGE_KEY) || '',
}, },
{ {
name: 'triple', name: 'triple',
src: src: 'https://minio.streakingman.com/solvable-sheep-game/sound-triple.mp3',
localStorage.getItem(DEFAULT_TRIPLE_SOUND_STORAGE_KEY) ||
'',
}, },
], ],
bgm: localStorage.getItem(DEFAULT_BGM_STORAGE_KEY) || '', bgm: 'https://minio.streakingman.com/solvable-sheep-game/sound-disco.mp3',
}; };
}; };

View File

@ -9,9 +9,6 @@ export const LAST_CUSTOM_THEME_ID_STORAGE_KEY = 'lastCustomThemeId';
export const LAST_UPLOAD_TIME_STORAGE_KEY = 'lastUploadTime'; export const LAST_UPLOAD_TIME_STORAGE_KEY = 'lastUploadTime';
export const CUSTOM_THEME_STORAGE_KEY = 'customTheme'; export const CUSTOM_THEME_STORAGE_KEY = 'customTheme';
export const CUSTOM_THEME_FILE_VALIDATE_STORAGE_KEY = 'customThemeFileValidate'; export const CUSTOM_THEME_FILE_VALIDATE_STORAGE_KEY = 'customThemeFileValidate';
export const DEFAULT_BGM_STORAGE_KEY = 'defaultBgm';
export const DEFAULT_TRIPLE_SOUND_STORAGE_KEY = 'defaultTripleSound';
export const DEFAULT_CLICK_SOUND_STORAGE_KEY = 'defaultClickSound';
export const USER_NAME_STORAGE_KEY = 'username'; export const USER_NAME_STORAGE_KEY = 'username';
export const USER_ID_STORAGE_KEY = 'userId'; export const USER_ID_STORAGE_KEY = 'userId';
export const PLAYING_THEME_ID_STORAGE_KEY = 'playingThemeId'; export const PLAYING_THEME_ID_STORAGE_KEY = 'playingThemeId';