diff --git a/README.md b/README.md index e38371f..832b6e8 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Vyla Home is a native desktop app that: When you launch Vyla Home, it: -1. Starts the necessary background services (authentication proxy, streaming API, media player) +1. Starts the necessary background services (media player server) 2. Loads your saved settings and credentials (encrypted for security) 3. Checks for updates and installs them if available 4. Opens the user interface in a secure, embedded browser window diff --git a/build-pipeline.js b/build-pipeline.js index fe09a19..57e518c 100644 --- a/build-pipeline.js +++ b/build-pipeline.js @@ -5,7 +5,7 @@ const AdmZip = require('adm-zip'); const { execSync } = require('child_process'); const BUILD_DIR = path.join(__dirname, 'dist-build'); -const REPOS = ['frontend', 'player', 'auth-proxy', 'stream-api']; +const REPOS = ['frontend', 'player']; const TEMP_EXTRACT_DIR = path.join(__dirname, 'temp-validation-extract'); @@ -14,8 +14,6 @@ const GITLAB_GROUP = 'vyla-entertainment'; const REPO_CONFIG = { 'frontend': { name: 'frontend', branch: 'main' }, 'player': { name: 'player', branch: 'main' }, - 'auth-proxy': { name: 'auth-proxy', branch: 'main' }, - 'stream-api': { name: 'stream-api', branch: 'main' }, }; const clonedRepos = new Set(); @@ -174,12 +172,10 @@ function validatePayload(zipPath) { zip.extractAllTo(TEMP_EXTRACT_DIR, true); const requiredFiles = [ - 'player/index.html', - 'auth-proxy/server.js', - 'stream-api/server.js', + 'player/server.js', 'frontend/index.html' ]; - + const validationResults = { valid: true, errors: [], diff --git a/config/credentials-template.json b/config/credentials-template.json index 0fe688d..b092f3f 100644 --- a/config/credentials-template.json +++ b/config/credentials-template.json @@ -1,16 +1,5 @@ { "player": { - "TMDB_KEY": "YOUR_TMDB_KEY_HERE", - "API_KEY": "YOUR_API_KEY_HERE" - }, - "auth-proxy": { - "VITE_API_KEY": "YOUR_VITE_API_KEY_HERE", - "PROXY_VITE_API_KEY": "YOUR_PROXY_VITE_API_KEY_HERE" - }, - "stream-api": { - "TMDB_API_KEY": "YOUR_TMDB_API_KEY_HERE", - "GA_MEASUREMENT_ID": "YOUR_GA_MEASUREMENT_ID_HERE", - "GA_API_SECRET": "YOUR_GA_API_SECRET_HERE", - "TOKEN_SECRET": "YOUR_TOKEN_SECRET_HERE" + "TMDB_KEY": "YOUR_TMDB_KEY_HERE" } } \ No newline at end of file diff --git a/config/env.json b/config/env.json index 663e850..64929c0 100644 --- a/config/env.json +++ b/config/env.json @@ -1,20 +1,5 @@ { "player": { - "PORT": "3001", - "BASE_URL": "http://localhost:7860", - "BYPASS_AUTH": "true" - }, - "auth-proxy": { - "PORT": "3000", - "VITE_BASE_URL": "http://localhost:7860", - "DEV_BYPASS_AUTH": "true" - }, - "stream-api": { - "PORT": "7860", - "PROXY_URL": "https://txt.primebox.workers.dev", - "PROXY_STREAMS": "true", - "ENABLE_DEBUG_ROUTE": "true", - "BYPASS_AUTH": "true", - "TOKEN_SECRET": "vyla_default_secure_token_secret_local_dev_32chars" + "PORT": "3000" } } \ No newline at end of file diff --git a/config/replacements.json b/config/replacements.json index ceb3883..1d3ff36 100644 --- a/config/replacements.json +++ b/config/replacements.json @@ -2,40 +2,17 @@ "frontend": [ { "find": "https://player.vyla.cc", - "replace": "http://localhost:3001" + "replace": "http://localhost:3000" }, { "find": "http://player.vyla.cc", - "replace": "http://localhost:3001" - }, - { - "find": "https://api.vyla.cc", - "replace": "http://localhost:7860" - }, - { - "find": "https://auth.vyla.cc", "replace": "http://localhost:3000" } ], "player": [ - { - "find": "https://api.vyla.cc", - "replace": "http://localhost:7860" - }, - { - "find": "https://auth.vyla.cc", - "replace": "http://localhost:3000" - }, { "find": "https://player.vyla.cc", "replace": "http://localhost:4890" } - ], - "auth-proxy": [ - { - "find": "https://player.vyla.cc", - "replace": "http://localhost:3001" - } - ], - "stream-api": [] + ] } \ No newline at end of file diff --git a/github-client.js b/github-client.js index 1583a5e..47eb568 100644 --- a/github-client.js +++ b/github-client.js @@ -4,9 +4,7 @@ const path = require('path'); const REPOS = { frontend: { branch: 'main' }, - player: { branch: 'main' }, - 'stream-api': { branch: 'main' }, - 'auth-proxy': { branch: 'main' } + player: { branch: 'main' } }; const GITLAB_GROUP = 'vyla-entertainment'; diff --git a/main.js b/main.js index cf63104..375f16e 100644 --- a/main.js +++ b/main.js @@ -34,8 +34,6 @@ debugLog("--- Node.js Process Started ---"); let serviceManager; let expressApp; let expressServer; -let playerExpressApp; -let playerExpressServer; debugLog(`AppData Dir: ${APPDATA_DIR}`); @@ -217,27 +215,51 @@ async function start() { let localSha = patcher.getCurrentSha(); debugLog(`Is First Run: ${isFirstRun}, Local Version: ${localVersion}, Local SHA: ${localSha}`); - const localZipPath = path.join(__dirname, 'update-payload.zip'); - const localManifestPath = path.join(__dirname, 'manifest.json'); - let localZipManifest = null; - - if (fs.existsSync(localZipPath) && fs.existsSync(localManifestPath)) { - try { localZipManifest = JSON.parse(fs.readFileSync(localManifestPath, 'utf8')); } catch (e) { } + function findLocalZip() { + const searchRoots = [__dirname, process.cwd()]; + for (const root of searchRoots) { + let cur = root; + for (let i = 0; i < 6; i++) { + const zp = path.join(cur, 'update-payload.zip'); + if (fs.existsSync(zp)) { + const mp = path.join(cur, 'manifest.json'); + return { zipPath: zp, manifestPath: fs.existsSync(mp) ? mp : null }; + } + const parent = path.dirname(cur); + if (parent === cur) break; + cur = parent; + } + } + return null; } - if (localZipManifest && (isFirstRun || localZipManifest.sha256 !== localSha)) { - debugLog("New local payload detected! Applying local build..."); + const localFound = findLocalZip(); + let localZipPath = localFound ? localFound.zipPath : null; + let localManifestPath = localFound ? localFound.manifestPath : null; + let localZipManifest = null; + + if (localManifestPath) { + try { + localZipManifest = JSON.parse(fs.readFileSync(localManifestPath, 'utf8')); + } catch (e) { } + } + + if (localZipPath && (isFirstRun || (localZipManifest && localZipManifest.sha256 !== localSha))) { + debugLog(`Applying local development payload from: ${localZipPath}`); sendToTauri('status', { message: 'Extracting local development payload...' }); patcher.purgeOldCode(); patcher.extractZipPayload(localZipPath); patcher.applyPatches(getReplacementsConfig()); patcher.bridgeCredentials(serviceManager.credentialManager); - patcher.saveCurrentVersion(localZipManifest.version, localZipManifest.sha256); + + const ver = localZipManifest ? localZipManifest.version : '1.1.32'; + const sha = localZipManifest ? localZipManifest.sha256 : null; + patcher.saveCurrentVersion(ver, sha); serviceManager.envConfig = getEnvConfig(); isFirstRun = false; - localVersion = localZipManifest.version; - localSha = localZipManifest.sha256; + localVersion = ver; + localSha = sha; debugLog("Local payload applied successfully."); } @@ -247,18 +269,43 @@ async function start() { debugLog("Fetching updates from updateClient..."); release = await updateClient.checkForUpdates(); debugLog(`Update check finished. Found: ${release ? release.version : 'None'}`); + + let appPkgVer = '0.0.0'; + try { + appPkgVer = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8')).version || '0.0.0'; + } catch (e) { } + + if (release && release.version) { + const rVer = release.version.replace('v', '').split('.').map(Number); + const aVer = appPkgVer.split('.').map(Number); + let isOlder = false; + for (let i = 0; i < 3; i++) { + if ((rVer[i] || 0) < (aVer[i] || 0)) { isOlder = true; break; } + if ((rVer[i] || 0) > (aVer[i] || 0)) { break; } + } + if (isOlder) { + debugLog(`Remote version ${release.version} is older than local package ${appPkgVer}. Ignoring remote release.`); + release = null; + } + } } catch (e) { debugLog(`Update check failed (offline?): ${e.message}`); sendToTauri('status', { message: `Update server check skipped (${e.message})` }); } + const normalizeVer = (v) => (v || '').toString().replace(/^v/, '').trim(); + if (release) { - const hasUpdate = release.version !== localVersion || (release.sha256 && release.sha256 !== localSha); + const isNewerSha = release.sha256 && localSha && release.sha256 !== localSha; + const isDifferentVer = normalizeVer(release.version) !== normalizeVer(localVersion); + const hasUpdate = (isDifferentVer || isNewerSha) && !localZipPath; + if (isFirstRun) { - debugLog("First run. Installing remote build..."); + debugLog("First run with no local payload. Installing remote build..."); sendToTauri('status', { message: 'First run detected. Preparing initial installation...' }); await installBuild(release); } else if (hasUpdate) { + debugLog("Update available. Prompting user..."); sendToTauri('status', { message: `New update available (${release.version}). Awaiting confirmation...` }); @@ -327,51 +374,21 @@ async function start() { sendToTauri('status', { message: 'Validating critical components...' }); if (!patcher.verifyExtraction()) { - throw new Error('No application files found. Check your internet connection and try again.'); + throw new Error('No application files found. Ensure you run "npm run build:payload" to generate the local development payload.'); } sendToTauri('status', { message: 'Loading encrypted credentials...' }); serviceManager.credentialManager.loadCredentials(); - sendToTauri('status', { message: 'Starting background services (auth-proxy, stream-api)...' }); + sendToTauri('status', { message: 'Starting background services (player)...' }); await serviceManager.startServices([ - { name: 'auth-proxy', relativeDir: 'auth-proxy' }, - { name: 'stream-api', relativeDir: 'stream-api' }, + { name: 'player', relativeDir: 'player', startScript: 'server.js' } ]); debugLog("Backend services spawn requested."); - sendToTauri('status', { message: 'Binding player web server on port 3001...' }); - const playerDir = path.join(APPDATA_DIR, 'player'); - playerExpressApp = express(); - playerExpressApp.use((req, res, next) => { - res.header('Access-Control-Allow-Origin', '*'); - res.header('Access-Control-Allow-Methods', 'GET,POST,OPTIONS'); - res.header('Access-Control-Allow-Headers', '*'); - if (req.method === 'OPTIONS') return res.sendStatus(200); - next(); - }); - playerExpressApp.get('/__tauri_cmd/:cmd', (req, res) => { - debugLog(`[PLAYER-SERVER:3001] Command received: ${req.params.cmd} (window: ${req.query.window || 'main'})`); - sendToTauri('tauri-cmd', { cmd: req.params.cmd, url: req.query.url, window: req.query.window }); - res.sendStatus(200); - }); - playerExpressApp.use(sameTabNavMiddleware(playerDir)); - playerExpressApp.use(express.static(playerDir, { - etag: false, - setHeaders: (res) => { - res.set('Cache-Control', 'no-store, no-cache, must-revalidate, private'); - } - })); - playerExpressApp.get('*', (req, res) => { - res.set('Cache-Control', 'no-store, no-cache, must-revalidate, private'); - res.sendFile(path.join(playerDir, 'index.html')); - }); - playerExpressServer = playerExpressApp.listen(3001, '127.0.0.1'); - debugLog("Player Express running on 3001"); - - sendToTauri('status', { message: 'Waiting for microservices to bind ports (3000, 3001, 7860)...' }); - await serviceManager.waitForPorts([3000, 3001, 7860]); - debugLog("Ports 3000, 3001, 7860 are ready."); + sendToTauri('status', { message: 'Waiting for microservices to bind port 3000...' }); + await serviceManager.waitForPorts([3000]); + debugLog("Port 3000 is ready."); sendToTauri('status', { message: 'Binding UI server on port 4890...' }); const frontendDir = path.join(APPDATA_DIR, 'frontend'); @@ -409,9 +426,6 @@ async function start() { const FRONTEND_PORT = 4890; expressApp.use('/build', express.static(path.join(__dirname, 'build'))); - if (playerExpressApp) { - playerExpressApp.use('/build', express.static(path.join(__dirname, 'build'))); - } expressServer = expressApp.listen(FRONTEND_PORT, () => { sendToTauri('status', { message: 'All backend services running and healthy.' }); diff --git a/package.json b/package.json index 6a4f0b2..dc31773 100644 --- a/package.json +++ b/package.json @@ -54,4 +54,4 @@ "installerHeaderIcon": "build/icon.ico" } } -} +} \ No newline at end of file diff --git a/patcher.js b/patcher.js index 586dc13..96a7d40 100644 --- a/patcher.js +++ b/patcher.js @@ -99,9 +99,7 @@ class Patcher { verifyExtraction() { const requiredFiles = [ - 'player/index.html', - 'auth-proxy/server.js', - 'stream-api/server.js', + 'player/server.js', 'frontend/index.html' ]; @@ -155,7 +153,7 @@ class Patcher { } applyPatches(replacements) { - const targetDirs = ['frontend', 'player', 'auth-proxy', 'stream-api']; + const targetDirs = ['frontend', 'player']; for (const dirName of targetDirs) { const dirPath = path.join(this.appDataPath, dirName); if (!fs.existsSync(dirPath)) continue; diff --git a/service-manager.js b/service-manager.js index 2501c56..99650b1 100644 --- a/service-manager.js +++ b/service-manager.js @@ -40,18 +40,16 @@ class ServiceManager { } let tokenSecret = process.env.TOKEN_SECRET || - process.env.STREAM_API_TOKEN_SECRET || - this.credentialManager.getCredential('stream-api', 'TOKEN_SECRET'); + this.credentialManager.getCredential('player', 'TOKEN_SECRET'); if (!tokenSecret || tokenSecret.length < 32) { tokenSecret = require('crypto').randomBytes(32).toString('hex'); - this.credentialManager.setCredential('stream-api', 'TOKEN_SECRET', tokenSecret); + this.credentialManager.setCredential('player', 'TOKEN_SECRET', tokenSecret); } const env = { ...process.env, TOKEN_SECRET: tokenSecret, - STREAM_API_TOKEN_SECRET: tokenSecret, ...(this.envConfig[name] || {}), ...(this.credentialManager.getServiceCredentials(name) || {}) }; diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 7359897..9535654 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -45,4 +45,4 @@ "../node_modules/**/*" ] } -} +} \ No newline at end of file