Files
reader/android/scripts/verify-web-apk.ps1
hectorqin 73f9eb6e20 feat(media): add isolated media libraries and playback
Support local and OpenList libraries, metadata, independent media navigation, themes, and audio/video playback. Preserve approved v2 prototypes and current documentation; archive superseded review artifacts and keep generated validation output outside version control.
2026-09-27 18:22:51 +08:00

34 lines
1.7 KiB
PowerShell

param(
[string]$ApkPath,
[string]$WebDist
)
$ErrorActionPreference = 'Stop'
$repoRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '../..'))
if (-not $ApkPath) { $ApkPath = Join-Path $repoRoot 'android/app/build/outputs/apk/debug/app-debug.apk' }
if (-not $WebDist) { $WebDist = Join-Path $repoRoot 'web/dist' }
$resolvedApk = (Resolve-Path -LiteralPath $ApkPath).Path
$resolvedDist = (Resolve-Path -LiteralPath $WebDist).Path
if (-not (Test-Path -LiteralPath (Join-Path $resolvedDist 'index.html'))) { throw 'Build web/dist before checking the APK.' }
Add-Type -AssemblyName System.IO.Compression.FileSystem
$archive = [IO.Compression.ZipFile]::OpenRead($resolvedApk)
try {
if (@($archive.Entries | Where-Object { $_.FullName.StartsWith('assets/web-assets/') }).Count) {
throw 'APK contains a duplicate web-assets subtree.'
}
$checked = 0
foreach ($file in Get-ChildItem -LiteralPath $resolvedDist -File -Recurse) {
$relative = $file.FullName.Substring($resolvedDist.Length).TrimStart('\', '/').Replace('\', '/')
$entry = $archive.GetEntry('assets/' + $relative)
if (-not $entry) { throw "APK is missing $relative" }
$stream = $entry.Open()
$sha = [Security.Cryptography.SHA256]::Create()
try {
$actual = [BitConverter]::ToString($sha.ComputeHash($stream)).Replace('-', '')
$expected = (Get-FileHash -LiteralPath $file.FullName -Algorithm SHA256).Hash
if ($actual -ne $expected) { throw "APK has a stale or modified asset: $relative" }
} finally { $stream.Dispose(); $sha.Dispose() }
$checked++
}
[pscustomobject]@{ apk = $resolvedApk; matchedWebFiles = $checked; duplicateBundle = $false } | ConvertTo-Json
} finally { $archive.Dispose() }