fix polyfills

This commit is contained in:
2024-08-16 16:15:45 +02:00
parent 4ae05bd060
commit bd2e4cdac4
4 changed files with 1348 additions and 116 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -12,7 +12,6 @@
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore" "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
}, },
"dependencies": { "dependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@esbuild-plugins/node-modules-polyfill": "^0.2.2", "@esbuild-plugins/node-modules-polyfill": "^0.2.2",
"@jridgewell/sourcemap-codec": "^1.4.15", "@jridgewell/sourcemap-codec": "^1.4.15",
"@melloware/coloris": "^0.24.0", "@melloware/coloris": "^0.24.0",
@@ -23,6 +22,7 @@
"musickit-typescript": "^1.2.4", "musickit-typescript": "^1.2.4",
"pinia": "^2.1.7", "pinia": "^2.1.7",
"socket.io-client": "^4.7.5", "socket.io-client": "^4.7.5",
"vite-plugin-node-polyfills": "^0.22.0",
"vue": "^3.4.15", "vue": "^3.4.15",
"vue-router": "^4.2.5" "vue-router": "^4.2.5"
}, },
@@ -38,6 +38,6 @@
"npm-run-all2": "^6.1.1", "npm-run-all2": "^6.1.1",
"typescript": "~5.3.0", "typescript": "~5.3.0",
"vite": "^5.0.11", "vite": "^5.0.11",
"vue-tsc": "^1.8.27" "vue-tsc": "^2.0.29"
} }
} }

View File

@@ -315,30 +315,53 @@
if ( res.status === 200 ) { if ( res.status === 200 ) {
res.blob().then( blob => { res.blob().then( blob => {
parseBlob( blob ).then( data => { parseBlob( blob ).then( data => {
player.findSongOnAppleMusic( data.common.title ?? songDetails.filename.split( '.' )[ 0 ] ).then( d => { try {
let url = d.data.results.songs.data[ 0 ].attributes.artwork.url; player.findSongOnAppleMusic( data.common.title ?? songDetails.filename.split( '.' )[ 0 ] ).then( d => {
url = url.replace( '{w}', String( d.data.results.songs.data[ 0 ].attributes.artwork.width ) ); let url = d.data.results.songs.data[ 0 ].attributes.artwork.url;
url = url.replace( '{h}', String( d.data.results.songs.data[ 0 ].attributes.artwork.height ) ); url = url.replace( '{w}', String( d.data.results.songs.data[ 0 ].attributes.artwork.width ) );
const song: Song = { url = url.replace( '{h}', String( d.data.results.songs.data[ 0 ].attributes.artwork.height ) );
artist: data.common.artist ?? d.data.results.songs.data[ 0 ].attributes.artistName, const song: Song = {
title: data.common.title ?? d.data.results.songs.data[ 0 ].attributes.name, artist: data.common.artist ?? d.data.results.songs.data[ 0 ].attributes.artistName,
duration: data.format.duration ?? ( d.data.results.songs.data[ 0 ].attributes.durationInMillis / 1000 ), title: data.common.title ?? d.data.results.songs.data[ 0 ].attributes.name,
id: songDetails.url, duration: data.format.duration ?? ( d.data.results.songs.data[ 0 ].attributes.durationInMillis / 1000 ),
origin: 'disk', id: songDetails.url,
cover: url origin: 'disk',
} cover: url
resolve( song ); }
} ).catch( e => { resolve( song );
reject( e ); } ).catch( e => {
} ); console.error( e );
const song: Song = {
artist: data.common.artist ?? 'Unknown artist',
title: data.common.title ?? 'Unknown song title',
duration: data.format.duration ?? 1000,
id: songDetails.url,
origin: 'disk',
cover: ''
}
resolve( song );
} );
} catch ( err ) {
console.error( err );
alert( 'One of your songs was not loadable. (finalization-error)' )
}
} ).catch( e => { } ).catch( e => {
console.error( e );
alert( 'One of your songs was not loadable. (parser-error)' );
reject( e ); reject( e );
} ); } );
} ).catch( e => { } ).catch( e => {
console.error( e );
alert( 'One of your songs was not loadable. (converter-error)' );
reject( e ); reject( e );
} ); } );
} else {
console.error( res.status );
alert( 'One of your songs was not loadable. (invalid-response-code)' );
} }
} ).catch( e => { } ).catch( e => {
console.error( e );
alert( 'One of your songs was not loadable. (could-not-connect)' );
reject( e ); reject( e );
} ); } );
} ); } );

View File

@@ -2,30 +2,19 @@ import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite' import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill' import { nodePolyfills } from 'vite-plugin-node-polyfills'
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [ plugins: [
vue(), vue(),
nodePolyfills(),
], ],
resolve: { resolve: {
alias: { alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)) '@': fileURLToPath(new URL('./src', import.meta.url))
} }
}, },
optimizeDeps: {
esbuildOptions: {
define: {
global: 'globalThis',
},
plugins: [
NodeGlobalsPolyfillPlugin({
buffer: true,
}),
],
},
},
server: { server: {
port: 8081 port: 8081
} }