70 lines
1.9 KiB
TypeScript
70 lines
1.9 KiB
TypeScript
import fs from "node:fs";
|
|
import { Router } from "express";
|
|
import path from "path";
|
|
import { fileURLToPath } from "url";
|
|
|
|
const router = Router();
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
const downloadDir = path.resolve(__dirname, "../../downloads/mobile");
|
|
const projectRoot = path.resolve("./lstMobile"); // adjust as needed
|
|
const appJsonPath = path.join(projectRoot, "app.json");
|
|
|
|
const raw = fs.readFileSync(appJsonPath, "utf-8");
|
|
const config = JSON.parse(raw);
|
|
|
|
const exp = config.expo;
|
|
|
|
const currentApk = {
|
|
packageName: exp.android?.package,
|
|
versionName: exp.version,
|
|
versionCode: exp.android?.versionCode,
|
|
minSupportedVersionCode: 1, // keep this custom if needed
|
|
fileName: "lst-mobile.apk",
|
|
};
|
|
|
|
router.get("/version", async (req, res) => {
|
|
const baseUrl = `${req.protocol}://${req.get("host")}`;
|
|
|
|
res.json({
|
|
packageName: currentApk.packageName,
|
|
versionName: currentApk.versionName,
|
|
versionCode: currentApk.versionCode,
|
|
minSupportedVersionCode: currentApk.minSupportedVersionCode,
|
|
downloadUrl: `${baseUrl}/lst/api/mobile/apk/latest`,
|
|
});
|
|
});
|
|
|
|
router.get("/apk/latest", (_, res) => {
|
|
const apkPath = path.join(downloadDir, currentApk.fileName);
|
|
|
|
if (!fs.existsSync(apkPath)) {
|
|
return res.status(404).json({ success: false, message: "APK not found" });
|
|
}
|
|
|
|
res.setHeader("Content-Type", "application/vnd.android.package-archive");
|
|
res.setHeader(
|
|
"Content-Disposition",
|
|
`attachment; filename="${currentApk.fileName}"`,
|
|
);
|
|
|
|
return res.sendFile(apkPath);
|
|
});
|
|
|
|
router.get("/apk/ehs", (_, res) => {
|
|
const apkPath = path.join(downloadDir, "EHS.apk");
|
|
|
|
if (!fs.existsSync(apkPath)) {
|
|
return res.status(404).json({ success: false, message: "APK not found" });
|
|
}
|
|
|
|
res.setHeader("Content-Type", "application/vnd.android.package-archive");
|
|
res.setHeader("Content-Disposition", `attachment; filename="EHS.apk}"`);
|
|
|
|
return res.sendFile(apkPath);
|
|
});
|
|
|
|
export default router;
|