-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
76 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
namespace GitHub { | ||
interface Release { | ||
url: string; | ||
assets_url: string; | ||
upload_url: string; | ||
html_url: string; | ||
id: number; | ||
author: { | ||
login: string; | ||
id: number; | ||
node_id: string; | ||
avatar_url: string; | ||
gravatar_id: string; | ||
url: string; | ||
html_url: string; | ||
followers_url: string; | ||
following_url: string; | ||
gists_url: string; | ||
starred_url: string; | ||
subscriptions_url: string; | ||
organizations_url: string; | ||
repos_url: string; | ||
events_url: string; | ||
received_events_url: string; | ||
type: string; | ||
site_admin: boolean | ||
}; | ||
node_id: string; | ||
tag_name: string; | ||
target_commitish: string; | ||
name: string; | ||
draft: boolean; | ||
prerelease: boolean; | ||
created_at: string; | ||
published_at: string; | ||
assets: any[]; | ||
tarball_url: string; | ||
zipball_url: string; | ||
body: string; | ||
mentions_count: number | ||
} | ||
} |
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 |
---|---|---|
@@ -1,36 +1,40 @@ | ||
import fs from 'fs/promises'; | ||
import fetch from 'node-fetch'; | ||
import { exec } from 'child_process'; | ||
import os from 'os'; | ||
import { exec } from "child_process"; | ||
import fetch from "node-fetch"; | ||
import os from "os"; | ||
import { version as localVersion } from "../../package.json"; | ||
|
||
async function getAppVersionGithub() { | ||
const githubJson = await fetch('https://api.github.com/repos/aymene69/stremio-jackett/releases/latest'); | ||
const githubJsonContent = await githubJson.json(); | ||
// @ts-ignore | ||
const appVersion = githubJsonContent.tag_name; | ||
return appVersion.replace('v', ''); | ||
/** @type {GitHub.Release} */ | ||
// @ts-ignore | ||
const latestRelease = await ( | ||
await fetch("https://api.github.com/repos/aymene69/stremio-jackett/releases/latest") | ||
).json(); | ||
|
||
const appVersion = latestRelease.tag_name; | ||
|
||
return appVersion.replace("v", ""); | ||
} | ||
|
||
export async function updateApp() { | ||
const appVersionLocal = localVersion | ||
const appVersionGithub = await getAppVersionGithub(); | ||
if (appVersionLocal !== appVersionGithub) { | ||
console.log('A new update is available!'); | ||
console.log('Local version:', appVersionLocal, 'Github version:', appVersionGithub); | ||
console.log('Updating app...'); | ||
if (os.platform() === 'win32') { | ||
const updateCmd = "git clone https://github.com/aymene69/stremio-jackett temp & xcopy temp\\* .\\ /E /I /Q & rmdir /S /Q temp & npm install"; | ||
await exec(updateCmd); | ||
} | ||
else { | ||
const updateCmd = "git clone https://github.com/aymene69/stremio-jackett temp && sudo rsync -a temp/ ./ && sudo rm -r temp && npm install"; | ||
await exec(updateCmd); | ||
} | ||
console.log('App updated.'); | ||
} | ||
else { | ||
console.log('App is up to date.'); | ||
console.log('Local version:', appVersionLocal, 'Github version:', appVersionGithub) | ||
} | ||
} | ||
const latestVersion = await getAppVersionGithub(); | ||
|
||
if (localVersion === latestVersion) { | ||
return; | ||
} | ||
|
||
console.log("A new update is available!"); | ||
console.log("Local version:", localVersion, "GitHub version:", latestVersion); | ||
console.log("Updating app..."); | ||
|
||
let updateCmd = "git clone https://github.com/aymene69/stremio-jackett temp"; | ||
if (os.platform() === "win32") { | ||
updateCmd += " & xcopy temp\\* .\\ /E /I /Q & rmdir /S /Q temp & "; | ||
} else { | ||
updateCmd += " && sudo rsync -a temp/ ./ && sudo rm -r temp && "; | ||
} | ||
updateCmd += "npm install"; | ||
|
||
exec(updateCmd); | ||
|
||
console.log("App updated."); | ||
} |