added autoupdate endpoints

This commit is contained in:
SrGooglo 2023-06-13 23:31:59 +00:00
parent 3f1010e5e4
commit 35a4f42766
3 changed files with 50 additions and 2 deletions

View File

@ -6,7 +6,7 @@
"webDir": "dist",
"plugins": {
"CapacitorUpdater": {
"updateUrl": "https://relic.ragestudio.net/comty/update_check"
"updateUrl": "https://api.comty.app/auto-update/mobile"
}
}
}

View File

@ -0,0 +1,46 @@
import { Controller } from "linebridge/dist/server"
import { Octokit } from "@octokit/rest"
const octokit = new Octokit({})
const endpoints = {
post: {
"/mobile": {
fn: async (req, res) => {
if (!process.env.GITHUB_REPO) {
return res.status(400).json({
error: "GITHUB_REPO env variable not set"
})
}
const lastRelease = await octokit.repos.getLatestRelease({
owner: process.env.GITHUB_REPO.split("/")[0],
repo: process.env.GITHUB_REPO.split("/")[1]
})
const bundle = lastRelease.data.assets.find((asset) => asset.name === "mobile_dist.zip")
const version = lastRelease.data.tag_name
if (!bundle) {
return res.status(400).json({
error: "mobile asset not available",
version: version,
})
}
return res.json({
url: bundle.browser_download_url,
version: version,
})
}
}
}
}
export default class AutoUpdate extends Controller {
static refName = "AutoUpdate"
static useRoute = "/auto-update"
httpEndpoints = endpoints
}

View File

@ -24,4 +24,6 @@ export { default as ModerationController } from "./ModerationController"
export { default as AdminController } from "./AdminController"
export { default as SyncController } from "./SyncController"
export { default as SyncController } from "./SyncController"
export { default as AutoUpdateController } from "./AutoUpdate"