mirror of https://github.com/FreeTubeApp/FreeTube
Simplify static file loading (#4971)
This commit is contained in:
parent
e633eaf1dd
commit
27eecb9e0b
|
@ -111,13 +111,14 @@ function startRenderer(callback) {
|
||||||
|
|
||||||
const server = new WebpackDevServer({
|
const server = new WebpackDevServer({
|
||||||
static: {
|
static: {
|
||||||
directory: path.join(process.cwd(), 'static'),
|
directory: path.resolve(__dirname, '..', 'static'),
|
||||||
watch: {
|
watch: {
|
||||||
ignored: [
|
ignored: [
|
||||||
/(dashFiles|storyboards)\/*/,
|
/(dashFiles|storyboards)\/*/,
|
||||||
'/**/.DS_Store',
|
'/**/.DS_Store',
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
publicPath: '/static'
|
||||||
},
|
},
|
||||||
port
|
port
|
||||||
}, compiler)
|
}, compiler)
|
||||||
|
|
|
@ -111,8 +111,8 @@ const config = {
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
node: {
|
node: {
|
||||||
__dirname: isDevMode,
|
__dirname: false,
|
||||||
__filename: isDevMode
|
__filename: false
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
processLocalesPlugin,
|
processLocalesPlugin,
|
||||||
|
|
|
@ -108,8 +108,8 @@ const config = {
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
node: {
|
node: {
|
||||||
__dirname: true,
|
__dirname: false,
|
||||||
__filename: isDevMode,
|
__filename: false
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
|
|
|
@ -276,10 +276,7 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
|
|
||||||
checkExternalPlayer: async function () {
|
checkExternalPlayer: async function () {
|
||||||
const payload = {
|
this.getExternalPlayerCmdArgumentsData()
|
||||||
externalPlayer: this.externalPlayer
|
|
||||||
}
|
|
||||||
this.getExternalPlayerCmdArgumentsData(payload)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
handleUpdateBannerClick: function (response) {
|
handleUpdateBannerClick: function (response) {
|
||||||
|
|
|
@ -36,14 +36,14 @@ export async function loadLocale(locale) {
|
||||||
|
|
||||||
// locales are only compressed in our production Electron builds
|
// locales are only compressed in our production Electron builds
|
||||||
if (process.env.IS_ELECTRON && process.env.NODE_ENV !== 'development') {
|
if (process.env.IS_ELECTRON && process.env.NODE_ENV !== 'development') {
|
||||||
const { readFile } = require('fs/promises')
|
|
||||||
const { promisify } = require('util')
|
const { promisify } = require('util')
|
||||||
const { brotliDecompress } = require('zlib')
|
const { brotliDecompress } = require('zlib')
|
||||||
const brotliDecompressAsync = promisify(brotliDecompress)
|
const brotliDecompressAsync = promisify(brotliDecompress)
|
||||||
try {
|
try {
|
||||||
// decompress brotli compressed json file and then load it
|
// decompress brotli compressed json file and then load it
|
||||||
// eslint-disable-next-line n/no-path-concat
|
const url = createWebURL(`/static/locales/${locale}.json.br`)
|
||||||
const compressed = await readFile(`${__dirname}/static/locales/${locale}.json.br`)
|
const compressed = await (await fetch(url)).arrayBuffer()
|
||||||
|
|
||||||
const decompressed = await brotliDecompressAsync(compressed)
|
const decompressed = await brotliDecompressAsync(compressed)
|
||||||
const data = JSON.parse(decompressed.toString())
|
const data = JSON.parse(decompressed.toString())
|
||||||
i18n.setLocaleMessage(locale, data)
|
i18n.setLocaleMessage(locale, data)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import fs from 'fs/promises'
|
|
||||||
import { createWebURL, fetchWithTimeout } from '../../helpers/utils'
|
import { createWebURL, fetchWithTimeout } from '../../helpers/utils'
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
|
@ -42,14 +41,11 @@ const actions = {
|
||||||
|
|
||||||
// If the invidious instance fetch isn't returning anything interpretable
|
// If the invidious instance fetch isn't returning anything interpretable
|
||||||
if (instances.length === 0) {
|
if (instances.length === 0) {
|
||||||
// Fallback: read from static file
|
|
||||||
const fileName = 'invidious-instances.json'
|
|
||||||
/* eslint-disable-next-line n/no-path-concat */
|
|
||||||
const fileLocation = process.env.NODE_ENV === 'development' ? './static/' : `${__dirname}/static/`
|
|
||||||
const filePath = `${fileLocation}${fileName}`
|
|
||||||
console.warn('reading static file for invidious instances')
|
console.warn('reading static file for invidious instances')
|
||||||
const fileData = process.env.IS_ELECTRON ? await fs.readFile(filePath, 'utf8') : await (await fetch(createWebURL(filePath))).text()
|
const url = createWebURL('/static/invidious-instances.json')
|
||||||
instances = JSON.parse(fileData).filter(e => {
|
|
||||||
|
const fileData = await (await fetch(url)).json()
|
||||||
|
instances = fileData.filter(e => {
|
||||||
return process.env.SUPPORTS_LOCAL_API || e.cors
|
return process.env.SUPPORTS_LOCAL_API || e.cors
|
||||||
}).map(e => {
|
}).map(e => {
|
||||||
return e.url
|
return e.url
|
||||||
|
|
|
@ -384,11 +384,10 @@ const actions = {
|
||||||
|
|
||||||
async getRegionData ({ commit }, { locale }) {
|
async getRegionData ({ commit }, { locale }) {
|
||||||
const localePathExists = process.env.GEOLOCATION_NAMES.includes(locale)
|
const localePathExists = process.env.GEOLOCATION_NAMES.includes(locale)
|
||||||
// Exclude __dirname from path if not in electron
|
|
||||||
const fileLocation = `${process.env.IS_ELECTRON ? process.env.NODE_ENV === 'development' ? '.' : __dirname : ''}/static/geolocations/`
|
|
||||||
|
|
||||||
const pathName = `${fileLocation}${localePathExists ? locale : 'en-US'}.json`
|
const url = createWebURL(`/static/geolocations/${localePathExists ? locale : 'en-US'}.json`)
|
||||||
const countries = process.env.IS_ELECTRON ? JSON.parse(await fs.readFile(pathName)) : await (await fetch(createWebURL(pathName))).json()
|
|
||||||
|
const countries = await (await fetch(url)).json()
|
||||||
|
|
||||||
const regionNames = countries.map((entry) => { return entry.name })
|
const regionNames = countries.map((entry) => { return entry.name })
|
||||||
const regionValues = countries.map((entry) => { return entry.code })
|
const regionValues = countries.map((entry) => { return entry.code })
|
||||||
|
@ -620,16 +619,9 @@ const actions = {
|
||||||
commit('setSessionSearchHistory', [])
|
commit('setSessionSearchHistory', [])
|
||||||
},
|
},
|
||||||
|
|
||||||
async getExternalPlayerCmdArgumentsData ({ commit }, payload) {
|
async getExternalPlayerCmdArgumentsData ({ commit }) {
|
||||||
const fileName = 'external-player-map.json'
|
const url = createWebURL('/static/external-player-map.json')
|
||||||
/* eslint-disable-next-line n/no-path-concat */
|
const externalPlayerMap = await (await fetch(url)).json()
|
||||||
const fileLocation = process.env.NODE_ENV === 'development' ? './static/' : `${__dirname}/static/`
|
|
||||||
|
|
||||||
const fileData = await fs.readFile(`${fileLocation}${fileName}`)
|
|
||||||
|
|
||||||
const externalPlayerMap = JSON.parse(fileData).map((entry) => {
|
|
||||||
return { name: entry.name, value: entry.value, cmdArguments: entry.cmdArguments }
|
|
||||||
})
|
|
||||||
// Sort external players alphabetically & case-insensitive, keep default entry at the top
|
// Sort external players alphabetically & case-insensitive, keep default entry at the top
|
||||||
const playerNone = externalPlayerMap.shift()
|
const playerNone = externalPlayerMap.shift()
|
||||||
externalPlayerMap.sort((a, b) => a.name.localeCompare(b.name, undefined, { sensitivity: 'base' }))
|
externalPlayerMap.sort((a, b) => a.name.localeCompare(b.name, undefined, { sensitivity: 'base' }))
|
||||||
|
|
Loading…
Reference in New Issue