初始化提交
This commit is contained in:
22
frontend/src/utils/audio.js
Normal file
22
frontend/src/utils/audio.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Get the proper play URL based on source
|
||||
* @param {string} source - The source platform (e.g., 'bilibili', 'netease')
|
||||
* @param {string} url - The original audio URL
|
||||
* @param {string} referer - The referer URL
|
||||
* @returns {string} The processed play URL
|
||||
*/
|
||||
export function getProperPlayUrl(source, url, referer) {
|
||||
console.log("--------getProperPlayUrl----------------");
|
||||
console.log(source);
|
||||
console.log(url);
|
||||
console.log(referer);
|
||||
if (source === "bilibili") {
|
||||
const params = new URLSearchParams({
|
||||
url: url,
|
||||
source: 'bilibili',
|
||||
referer: referer
|
||||
});
|
||||
return `${import.meta.env.VITE_APP_API_URL}/proxy/audio?${params}`;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
46
frontend/src/utils/index.js
Normal file
46
frontend/src/utils/index.js
Normal file
@@ -0,0 +1,46 @@
|
||||
export function secondDurationToDisplayDuration(secondDuration, allowZero = false) {
|
||||
if (!secondDuration) {
|
||||
return allowZero ? "00:00" : " - ";
|
||||
}
|
||||
secondDuration = parseInt(secondDuration);
|
||||
let duration = secondDuration;
|
||||
let minute = Math.floor(duration / 60);
|
||||
let second = duration % 60;
|
||||
if (minute < 10) {
|
||||
minute = "0" + minute;
|
||||
}
|
||||
if (second < 10) {
|
||||
second = "0" + second;
|
||||
}
|
||||
return minute + ":" + second;
|
||||
}
|
||||
|
||||
export function sourceCodeToName(source) {
|
||||
return {
|
||||
"qq": "QQ音乐",
|
||||
"xiami": "虾米音乐",
|
||||
"netease": "网易云音乐",
|
||||
"kugou": "酷狗音乐",
|
||||
"kuwo": "酷我音乐",
|
||||
"migu": "咪咕音乐",
|
||||
"bilibili": "Bilibili",
|
||||
"douyin": "抖音",
|
||||
"youtube": "YouTube",
|
||||
}[source] || "未知";
|
||||
}
|
||||
|
||||
export function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
export function ellipsis(value, maxLength) {
|
||||
if (!value) {
|
||||
return "";
|
||||
}
|
||||
value = value.trim();
|
||||
if (!value) return "";
|
||||
if (value.length > maxLength) {
|
||||
return value.slice(0, maxLength) + "...";
|
||||
}
|
||||
return value;
|
||||
}
|
||||
24
frontend/src/utils/pwa.js
Normal file
24
frontend/src/utils/pwa.js
Normal file
@@ -0,0 +1,24 @@
|
||||
let request;
|
||||
|
||||
let isInstallable = false;
|
||||
|
||||
// The file is not useful now.
|
||||
window.addEventListener('beforeinstallprompt', (r) => {
|
||||
console.log('beforeinstallprompt')
|
||||
// Prevent Chrome 67 and earlier from automatically showing the prompt
|
||||
r.preventDefault()
|
||||
request = r
|
||||
isInstallable = true;
|
||||
});
|
||||
|
||||
export async function installPWA() {
|
||||
if (request) {
|
||||
console.log('start install')
|
||||
let installResponse = await request.prompt();
|
||||
console.info({installResponse});
|
||||
return installResponse.outcome === 'accepted';
|
||||
} else {
|
||||
console.log('The request is not available');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
20
frontend/src/utils/storage.js
Normal file
20
frontend/src/utils/storage.js
Normal file
@@ -0,0 +1,20 @@
|
||||
export default {
|
||||
set (key, val) {
|
||||
if (typeof val === 'object') {
|
||||
val = JSON.stringify(val)
|
||||
}
|
||||
window.localStorage.setItem(key, val)
|
||||
},
|
||||
get (key) {
|
||||
let data = window.localStorage.getItem(key)
|
||||
try {
|
||||
data = JSON.parse(data);
|
||||
return data;
|
||||
} catch {
|
||||
return data;
|
||||
}
|
||||
},
|
||||
del (key) {
|
||||
window.localStorage.removeItem(key)
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user