mirror of
https://github.com/SpotX-Official/SpotX.git
synced 2026-06-19 13:50:04 +10:00
fix(patches): skip version-mismatched patch targets
- check patch versions before opening target files - add the home-v2 empty response check patch #862
This commit is contained in:
@@ -2583,6 +2583,14 @@
|
|||||||
},
|
},
|
||||||
"match": "(typeName\\])",
|
"match": "(typeName\\])",
|
||||||
"replace": "$1 || []"
|
"replace": "$1 || []"
|
||||||
|
},
|
||||||
|
"fixHomeV2EmptyResponseCheck": {
|
||||||
|
"version": {
|
||||||
|
"fr": "1.1.92",
|
||||||
|
"to": "1.2.45"
|
||||||
|
},
|
||||||
|
"match": "(\"HomeResponsePayload\"[\\s\\S]{0,500}?)0\\s*===\\s*([A-Za-z_$][\\w$]*)\\.sectionContainer\\.sections\\.totalCount\\s*\\|\\|\\s*0\\s*===\\s*\\2\\.sectionContainer\\.sections\\.items\\.length",
|
||||||
|
"replace": "$1!Array.isArray(null==$2||null==$2.sectionContainer||null==$2.sectionContainer.sections?void 0:$2.sectionContainer.sections.items)||0===$2.sectionContainer.sections.items.length"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"VariousJs": {
|
"VariousJs": {
|
||||||
|
|||||||
@@ -1853,8 +1853,45 @@ if ($webjson -eq $null) {
|
|||||||
Stop-Script
|
Stop-Script
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Get-JsonValue {
|
||||||
|
param (
|
||||||
|
[AllowNull()]
|
||||||
|
[object]$Object,
|
||||||
|
|
||||||
function Helper($paramname) {
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string]$Name
|
||||||
|
)
|
||||||
|
|
||||||
|
if ($null -eq $Object) { return $null }
|
||||||
|
$property = $Object.PSObject.Properties[$Name]
|
||||||
|
if ($null -eq $property) { return $null }
|
||||||
|
return $property.Value
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-PatchVersionMatch {
|
||||||
|
param (
|
||||||
|
[AllowNull()]
|
||||||
|
[object]$Patch,
|
||||||
|
|
||||||
|
[switch]$Translate
|
||||||
|
)
|
||||||
|
|
||||||
|
if ($null -eq $Patch) { return $false }
|
||||||
|
if ((Get-JsonValue -Object $Patch -Name 'disable') -eq $true) { return $false }
|
||||||
|
if ($Translate) { return $true }
|
||||||
|
|
||||||
|
$version = Get-JsonValue -Object $Patch -Name 'version'
|
||||||
|
$versionTo = Get-JsonValue -Object $version -Name 'to'
|
||||||
|
$versionFr = Get-JsonValue -Object $version -Name 'fr'
|
||||||
|
$offline_patch = $offline -replace '(\d+\.\d+\.\d+)(.\d+)', '$1'
|
||||||
|
|
||||||
|
if ($versionTo) { $to = [version]$versionTo -ge [version]$offline_patch } else { $to = $true }
|
||||||
|
if ($versionFr) { $fr = [version]$versionFr -le [version]$offline_patch } else { $fr = $false }
|
||||||
|
|
||||||
|
return $fr -and $to
|
||||||
|
}
|
||||||
|
|
||||||
|
function Helper($paramname, [switch]$CheckOnly) {
|
||||||
|
|
||||||
|
|
||||||
function Remove-Json {
|
function Remove-Json {
|
||||||
@@ -1892,21 +1929,6 @@ function Helper($paramname) {
|
|||||||
Remove-Json -j $to -p $propertyName
|
Remove-Json -j $to -p $propertyName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function Get-JsonValue {
|
|
||||||
param (
|
|
||||||
[AllowNull()]
|
|
||||||
[object]$Object,
|
|
||||||
|
|
||||||
[Parameter(Mandatory = $true)]
|
|
||||||
[string]$Name
|
|
||||||
)
|
|
||||||
|
|
||||||
if ($null -eq $Object) { return $null }
|
|
||||||
$property = $Object.PSObject.Properties[$Name]
|
|
||||||
if ($null -eq $property) { return $null }
|
|
||||||
return $property.Value
|
|
||||||
}
|
|
||||||
|
|
||||||
switch ( $paramname ) {
|
switch ( $paramname ) {
|
||||||
"HtmlLicMin" {
|
"HtmlLicMin" {
|
||||||
# licenses.html minification
|
# licenses.html minification
|
||||||
@@ -1936,6 +1958,7 @@ function Helper($paramname) {
|
|||||||
# Remove indent for old theme xpui.css
|
# Remove indent for old theme xpui.css
|
||||||
$name = "patches.json.others."
|
$name = "patches.json.others."
|
||||||
$n = "xpui.css"
|
$n = "xpui.css"
|
||||||
|
$contents = "fix-old-theme"
|
||||||
$json = $webjson.others
|
$json = $webjson.others
|
||||||
}
|
}
|
||||||
"Fixjs" {
|
"Fixjs" {
|
||||||
@@ -1959,14 +1982,16 @@ function Helper($paramname) {
|
|||||||
"Discriptions" {
|
"Discriptions" {
|
||||||
# Add discriptions (xpui-desktop-modals.js)
|
# Add discriptions (xpui-desktop-modals.js)
|
||||||
|
|
||||||
$svg_tg = $webjson.others.discriptions.svgtg
|
if (!$CheckOnly) {
|
||||||
$svg_git = $webjson.others.discriptions.svggit
|
$svg_tg = $webjson.others.discriptions.svgtg
|
||||||
$svg_faq = $webjson.others.discriptions.svgfaq
|
$svg_git = $webjson.others.discriptions.svggit
|
||||||
$replace = $webjson.others.discriptions.replace
|
$svg_faq = $webjson.others.discriptions.svgfaq
|
||||||
|
$replace = $webjson.others.discriptions.replace
|
||||||
|
|
||||||
$replacedText = $replace -f $svg_git, $svg_tg, $svg_faq
|
$replacedText = $replace -f $svg_git, $svg_tg, $svg_faq
|
||||||
|
|
||||||
$webjson.others.discriptions.replace = '$1"' + $replacedText + '"})'
|
$webjson.others.discriptions.replace = '$1"' + $replacedText + '"})'
|
||||||
|
}
|
||||||
|
|
||||||
$name = "patches.json.others."
|
$name = "patches.json.others."
|
||||||
$n = "xpui-desktop-modals.js"
|
$n = "xpui-desktop-modals.js"
|
||||||
@@ -1982,6 +2007,14 @@ function Helper($paramname) {
|
|||||||
}
|
}
|
||||||
"ForcedExp" {
|
"ForcedExp" {
|
||||||
# Forced disable some exp (xpui.js)
|
# Forced disable some exp (xpui.js)
|
||||||
|
if ($CheckOnly) {
|
||||||
|
$name = "patches.json.others."
|
||||||
|
$n = "xpui.js"
|
||||||
|
$contents = "ForcedExp"
|
||||||
|
$json = $webjson.others
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
$offline_patch = $offline -replace '(\d+\.\d+\.\d+)(.\d+)', '$1'
|
$offline_patch = $offline -replace '(\d+\.\d+\.\d+)(.\d+)', '$1'
|
||||||
$Enable = $webjson.others.EnableExp
|
$Enable = $webjson.others.EnableExp
|
||||||
$Disable = $webjson.others.DisableExp
|
$Disable = $webjson.others.DisableExp
|
||||||
@@ -2152,6 +2185,13 @@ function Helper($paramname) {
|
|||||||
$json = $webjsonru
|
$json = $webjsonru
|
||||||
}
|
}
|
||||||
"Binary" {
|
"Binary" {
|
||||||
|
if ($CheckOnly) {
|
||||||
|
$name = "patches.json.others.binary."
|
||||||
|
$n = "Spotify.exe"
|
||||||
|
$contents = $webjson.others.binary.psobject.properties.name
|
||||||
|
$json = $webjson.others.binary
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
$binary = $webjson.others.binary
|
$binary = $webjson.others.binary
|
||||||
|
|
||||||
@@ -2179,7 +2219,21 @@ function Helper($paramname) {
|
|||||||
$json = $webjson.others
|
$json = $webjson.others
|
||||||
|
|
||||||
}
|
}
|
||||||
|
"HomeV2-js" {
|
||||||
|
|
||||||
|
$name = "patches.json.others."
|
||||||
|
$n = "home-v2.js"
|
||||||
|
$contents = "fixHomeV2EmptyResponseCheck"
|
||||||
|
$json = $webjson.others
|
||||||
|
}
|
||||||
"VariousofXpui-js" {
|
"VariousofXpui-js" {
|
||||||
|
if ($CheckOnly) {
|
||||||
|
$name = "patches.json.VariousJs."
|
||||||
|
$n = "xpui.js"
|
||||||
|
$contents = $webjson.VariousJs.psobject.properties.name
|
||||||
|
$json = $webjson.VariousJs
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
$VarJs = $webjson.VariousJs
|
$VarJs = $webjson.VariousJs
|
||||||
|
|
||||||
@@ -2254,35 +2308,31 @@ function Helper($paramname) {
|
|||||||
}
|
}
|
||||||
$paramdata = $xpui
|
$paramdata = $xpui
|
||||||
$novariable = "Didn't find variable "
|
$novariable = "Didn't find variable "
|
||||||
$offline_patch = $offline -replace '(\d+\.\d+\.\d+)(.\d+)', '$1'
|
|
||||||
|
|
||||||
$contents | foreach {
|
foreach ($contentName in @($contents)) {
|
||||||
|
if ([string]::IsNullOrEmpty($contentName)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
$contentName = $PSItem
|
|
||||||
$contentPatch = Get-JsonValue -Object $json -Name $contentName
|
$contentPatch = Get-JsonValue -Object $json -Name $contentName
|
||||||
if ($null -eq $contentPatch) {
|
if ($null -eq $contentPatch) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((Get-JsonValue -Object $contentPatch -Name 'disable') -eq $true) {
|
if ((Get-JsonValue -Object $contentPatch -Name 'disable') -eq $true) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
$version = Get-JsonValue -Object $contentPatch -Name 'version'
|
$translate = $paramname -eq "RuTranslate"
|
||||||
$versionTo = Get-JsonValue -Object $version -Name 'to'
|
$checkVer = Test-PatchVersionMatch -Patch $contentPatch -Translate:$translate
|
||||||
$versionFr = Get-JsonValue -Object $version -Name 'fr'
|
|
||||||
|
|
||||||
if ($versionTo) { $to = [version]$versionTo -ge [version]$offline_patch } else { $to = $true }
|
if ($checkVer) {
|
||||||
if ($versionFr) { $fr = [version]$versionFr -le [version]$offline_patch } else { $fr = $false }
|
if ($CheckOnly) { return $true }
|
||||||
|
|
||||||
$checkVer = $fr -and $to; $translate = $paramname -eq "RuTranslate"
|
|
||||||
|
|
||||||
if ($checkVer -or $translate) {
|
|
||||||
|
|
||||||
$matchValue = Get-JsonValue -Object $contentPatch -Name 'match'
|
$matchValue = Get-JsonValue -Object $contentPatch -Name 'match'
|
||||||
$replaceValue = Get-JsonValue -Object $contentPatch -Name 'replace'
|
$replaceValue = Get-JsonValue -Object $contentPatch -Name 'replace'
|
||||||
if ($null -eq $matchValue -or $null -eq $replaceValue) {
|
if ($null -eq $matchValue -or $null -eq $replaceValue) {
|
||||||
return
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
$matchPatterns = @($matchValue)
|
$matchPatterns = @($matchValue)
|
||||||
@@ -2322,6 +2372,7 @@ function Helper($paramname) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($CheckOnly) { return $false }
|
||||||
$paramdata
|
$paramdata
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2330,6 +2381,8 @@ function extract ($counts, $method, $name, $helper, $add, $patch) {
|
|||||||
$reader = $null
|
$reader = $null
|
||||||
$writer = $null
|
$writer = $null
|
||||||
|
|
||||||
|
if ($helper -and $null -eq $add -and !(Helper -paramname $helper -CheckOnly)) { return }
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch ( $counts ) {
|
switch ( $counts ) {
|
||||||
"one" {
|
"one" {
|
||||||
@@ -3209,6 +3262,7 @@ if ($test_spa) {
|
|||||||
injection -p $xpui_spa_patch -f "spotx-helper/lyrics-color" -n @("rules.css", "colors.css") -c @($rulesContent, $colorsContent) -i "rules.css"
|
injection -p $xpui_spa_patch -f "spotx-helper/lyrics-color" -n @("rules.css", "colors.css") -c @($rulesContent, $colorsContent) -i "rules.css"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
extract -counts 'one' -method 'zip' -name 'home-v2.js' -helper 'HomeV2-js'
|
||||||
extract -counts 'one' -method 'zip' -name 'xpui.js' -helper 'VariousofXpui-js'
|
extract -counts 'one' -method 'zip' -name 'xpui.js' -helper 'VariousofXpui-js'
|
||||||
|
|
||||||
if ([version]$offline -ge [version]"1.1.85.884" -and [version]$offline -le [version]"1.2.57.463") {
|
if ([version]$offline -ge [version]"1.1.85.884" -and [version]$offline -le [version]"1.2.57.463") {
|
||||||
@@ -3270,7 +3324,6 @@ if ($test_spa) {
|
|||||||
if ($null -ne $css ) { extract -counts 'one' -method 'zip' -name 'xpui.css' -add $css }
|
if ($null -ne $css ) { extract -counts 'one' -method 'zip' -name 'xpui.css' -add $css }
|
||||||
|
|
||||||
# Old UI fix
|
# Old UI fix
|
||||||
$contents = "fix-old-theme"
|
|
||||||
extract -counts 'one' -method 'zip' -name 'xpui.css' -helper "FixCss"
|
extract -counts 'one' -method 'zip' -name 'xpui.css' -helper "FixCss"
|
||||||
|
|
||||||
# Remove RTL and minification of all *.css
|
# Remove RTL and minification of all *.css
|
||||||
|
|||||||
Reference in New Issue
Block a user