forked from LizardByte/Sunshine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ui): ensure pre-releases are properly checked (LizardByte#2564)
- Loading branch information
1 parent
f01dbaf
commit c5d318c
Showing
4 changed files
with
89 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
class SunshineVersion { | ||
constructor(release = null, version = null) { | ||
if (release) { | ||
this.release = release; | ||
this.version = release.tag_name; | ||
this.versionName = release.name; | ||
this.versionTag = release.tag_tag; | ||
} else if (version) { | ||
this.release = null; | ||
this.version = version; | ||
this.versionName = null; | ||
this.versionTag = null; | ||
} else { | ||
throw new Error('Either release or version must be provided'); | ||
} | ||
this.versionParts = this.parseVersion(this.version); | ||
this.versionMajor = this.versionParts ? this.versionParts[0] : null; | ||
this.versionMinor = this.versionParts ? this.versionParts[1] : null; | ||
this.versionPatch = this.versionParts ? this.versionParts[2] : null; | ||
} | ||
|
||
parseVersion(version) { | ||
if (!version) { | ||
return null; | ||
} | ||
let v = version; | ||
if (v.indexOf("v") === 0) { | ||
v = v.substring(1); | ||
} | ||
return v.split('.').map(Number); | ||
} | ||
|
||
isGreater(otherVersion) { | ||
let otherVersionParts; | ||
if (otherVersion instanceof SunshineVersion) { | ||
otherVersionParts = otherVersion.versionParts; | ||
} else if (typeof otherVersion === 'string') { | ||
otherVersionParts = this.parseVersion(otherVersion); | ||
} else { | ||
throw new Error('Invalid argument: otherVersion must be a SunshineVersion object or a version string'); | ||
} | ||
|
||
if (!this.versionParts || !otherVersionParts) { | ||
return false; | ||
} | ||
for (let i = 0; i < Math.min(3, this.versionParts.length, otherVersionParts.length); i++) { | ||
if (this.versionParts[i] > otherVersionParts[i]) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
export default SunshineVersion; |