After adding the fonctionality for apk publish8
This commit is contained in:
parent
e9b8918ea2
commit
319705c597
@ -38,6 +38,18 @@ export async function checkAndroid(req: AuthRequest, res: Response): Promise<voi
|
||||
}
|
||||
}
|
||||
|
||||
/** Public metadata + download link for the website APK button (no auth). */
|
||||
export async function latestAndroid(req: AuthRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const channel = (String(req.query.channel || 'production') as 'production' | 'beta' | 'internal');
|
||||
const result = await mobileAppReleaseService.getLatestPublicAndroidApk(channel);
|
||||
res.setHeader('Cache-Control', 'no-store');
|
||||
res.json(result);
|
||||
} catch (e) {
|
||||
sendError(res, e, 'Latest APK lookup failed');
|
||||
}
|
||||
}
|
||||
|
||||
export async function downloadAndroid(req: AuthRequest, res: Response): Promise<void> {
|
||||
try {
|
||||
const id = String(req.params.id || '');
|
||||
|
||||
@ -193,6 +193,7 @@ router.get('/marketing/withdrawal-feed', marketingController.getWithdrawalFeed);
|
||||
router.get('/share-cards/verify/:token', shareCardController.verifyShareCard);
|
||||
|
||||
/** Public Android in-app update check / APK download / telemetry (no auth). */
|
||||
router.get('/app-updates/android/latest', mobileAppReleaseController.latestAndroid);
|
||||
router.get(
|
||||
'/app-updates/android',
|
||||
validateQuery(mobileUpdateCheckQuerySchema),
|
||||
|
||||
@ -77,10 +77,56 @@ export function verifyDownloadToken(token: string, releaseId: string): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
function publicDownloadPath(releaseId: string, token: string): string {
|
||||
const api = config.apiPrefix.replace(/\/$/, '');
|
||||
return `${api}/app-updates/android/download/${releaseId}?token=${encodeURIComponent(token)}`;
|
||||
}
|
||||
|
||||
function publicDownloadUrl(releaseId: string, token: string): string {
|
||||
const base = config.app.publicUrl.replace(/\/$/, '');
|
||||
const api = config.apiPrefix.replace(/\/$/, '');
|
||||
return `${base}${api}/app-updates/android/download/${releaseId}?token=${encodeURIComponent(token)}`;
|
||||
return `${base}${publicDownloadPath(releaseId, token)}`;
|
||||
}
|
||||
|
||||
/** Latest published Android APK for the public website (ignores staged rollout). */
|
||||
export async function getLatestPublicAndroidApk(channel: MobileChannel = 'production'): Promise<{
|
||||
available: boolean;
|
||||
versionName: string | null;
|
||||
versionCode: number | null;
|
||||
fileSizeBytes: number | null;
|
||||
sha256: string | null;
|
||||
/** Absolute URL using APP_PUBLIC_URL (may differ from the browser origin). */
|
||||
downloadUrl: string | null;
|
||||
/** Same-origin path — prefer this on the landing page. */
|
||||
downloadPath: string | null;
|
||||
publishedAt: string | null;
|
||||
packageName: string | null;
|
||||
}> {
|
||||
const latest = await repo.findLatestPublished('android', channel);
|
||||
if (!latest || !latest.storageKey || !latest.sha256) {
|
||||
return {
|
||||
available: false,
|
||||
versionName: null,
|
||||
versionCode: null,
|
||||
fileSizeBytes: null,
|
||||
sha256: null,
|
||||
downloadUrl: null,
|
||||
downloadPath: null,
|
||||
publishedAt: null,
|
||||
packageName: null,
|
||||
};
|
||||
}
|
||||
const { token } = createDownloadToken(latest.id);
|
||||
return {
|
||||
available: true,
|
||||
versionName: latest.versionName,
|
||||
versionCode: latest.versionCode,
|
||||
fileSizeBytes: latest.fileSizeBytes,
|
||||
sha256: latest.sha256,
|
||||
downloadUrl: publicDownloadUrl(latest.id, token),
|
||||
downloadPath: publicDownloadPath(latest.id, token),
|
||||
publishedAt: latest.publishedAt?.toISOString() ?? null,
|
||||
packageName: latest.packageName,
|
||||
};
|
||||
}
|
||||
|
||||
export async function getSettings() {
|
||||
|
||||
@ -30,7 +30,15 @@ Store the `.jks` **offline** (password manager / encrypted backup). Never commit
|
||||
|
||||
1. Copy `prediqo_mobile/android/key.properties.example` → `key.properties`
|
||||
2. Fill `storePassword`, `keyPassword`, `keyAlias`, `storeFile`
|
||||
3. Build: `flutter build apk --release`
|
||||
3. Build release APK (production API URL is the default in release mode):
|
||||
|
||||
```bash
|
||||
flutter build apk --release
|
||||
# or pin explicitly:
|
||||
flutter build apk --release --dart-define-from-file=dart_defines.prod.example.json
|
||||
```
|
||||
|
||||
The public website header exposes an Android download icon that calls `GET /api/v1/app-updates/android/latest` (only works once a release is **published**).
|
||||
|
||||
### Fingerprint for the backend
|
||||
|
||||
|
||||
@ -2,24 +2,29 @@
|
||||
|
||||
## API URL (compile-time)
|
||||
|
||||
`API_BASE_URL` is set via `--dart-define` / `--dart-define-from-file`.
|
||||
Without it, the app defaults to `http://10.0.2.2:9080` (Android emulator only).
|
||||
`API_BASE_URL` is set via `--dart-define` / `--dart-define-from-file`.
|
||||
|
||||
| Build | Default without dart-define |
|
||||
|-------|-----------------------------|
|
||||
| **Release** (`flutter build apk --release`) | `http://prediqo.redirectme.net:9080` |
|
||||
| **Debug / emulator** | `http://10.0.2.2:9080` |
|
||||
|
||||
### Local device / custom host
|
||||
|
||||
1. Copy `dart_defines.dev.example.json` → `dart_defines.dev.json`
|
||||
2. Set your API base, e.g. `http://prediqo.redirectme.net:9080`
|
||||
|
||||
### Run
|
||||
2. Set your API base, e.g. `http://prediqo.redirectme.net:9080` or `http://<PC_LAN_IP>:9080`
|
||||
|
||||
```bash
|
||||
flutter run --dart-define-from-file=dart_defines.dev.json
|
||||
```
|
||||
|
||||
### Release APK
|
||||
### Release APK (production)
|
||||
|
||||
```bash
|
||||
flutter build apk --release --dart-define-from-file=dart_defines.dev.json
|
||||
# Uses built-in production default, or pin explicitly:
|
||||
flutter build apk --release --dart-define-from-file=dart_defines.prod.example.json
|
||||
```
|
||||
|
||||
Output: `build/app/outputs/flutter-apk/app-release.apk`
|
||||
|
||||
A plain `flutter build apk --release` **will not** include your VPS URL.
|
||||
An older APK built with only the emulator default (`10.0.2.2`) **cannot** reach the VPS — rebuild and reinstall.
|
||||
|
||||
@ -96,7 +96,8 @@ Par défaut (sans dart-define) : `http://10.0.2.2:9080`.
|
||||
|
||||
### APK release
|
||||
|
||||
`flutter build apk --release` **sans** `--dart-define-from-file` compile avec `http://10.0.2.2:9080` → connexion impossible sur un vrai téléphone.
|
||||
`flutter build apk --release` utilise par défaut `http://prediqo.redirectme.net:9080`.
|
||||
Les APKs plus anciens compilés avec `10.0.2.2` ne peuvent pas joindre le VPS — il faut reconstruire.
|
||||
|
||||
```bash
|
||||
cd prediqo_mobile
|
||||
|
||||
5
prediqo_mobile/dart_defines.prod.example.json
Normal file
5
prediqo_mobile/dart_defines.prod.example.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"API_BASE_URL": "http://prediqo.redirectme.net:9080",
|
||||
"APP_ENV": "production",
|
||||
"WS_ENABLED": "true"
|
||||
}
|
||||
@ -73,19 +73,26 @@ class AppConfig {
|
||||
).toString();
|
||||
}
|
||||
|
||||
/// Production API reached by release APKs on real devices (override with dart-define).
|
||||
static const String defaultProductionApiBaseUrl =
|
||||
'http://prediqo.redirectme.net:9080';
|
||||
|
||||
/// Emulator-only loopback to the host machine's Docker nginx.
|
||||
static const String defaultEmulatorApiBaseUrl = 'http://10.0.2.2:9080';
|
||||
|
||||
static AppConfig fromEnvironment() {
|
||||
// Docker local exposes the API via nginx on 9080 (port 4000 is internal only).
|
||||
// Emulator → 10.0.2.2 ; physical device → --dart-define=API_BASE_URL=http://<PC_LAN_IP>:9080
|
||||
const apiBaseUrl = String.fromEnvironment(
|
||||
'API_BASE_URL',
|
||||
defaultValue: 'http://10.0.2.2:9080',
|
||||
);
|
||||
// Release builds without --dart-define must still hit the public VPS.
|
||||
// Debug/emulator keeps 10.0.2.2 unless API_BASE_URL is set.
|
||||
const apiBaseUrlDefine = String.fromEnvironment('API_BASE_URL', defaultValue: '');
|
||||
const wsUrl = String.fromEnvironment('WS_URL', defaultValue: '');
|
||||
// Enabled by default so local Docker (nginx /ws/) works without extra flags.
|
||||
const wsEnabled = bool.fromEnvironment('WS_ENABLED', defaultValue: true);
|
||||
const env = String.fromEnvironment('APP_ENV', defaultValue: '');
|
||||
final isProd = env == 'production' ||
|
||||
const bool.fromEnvironment('dart.vm.product', defaultValue: false);
|
||||
final apiBaseUrl = apiBaseUrlDefine.isNotEmpty
|
||||
? apiBaseUrlDefine
|
||||
: (isProd ? defaultProductionApiBaseUrl : defaultEmulatorApiBaseUrl);
|
||||
const latestAppVersion =
|
||||
String.fromEnvironment('LATEST_APP_VERSION', defaultValue: '');
|
||||
const appStoreUrl = String.fromEnvironment('APP_STORE_URL', defaultValue: '');
|
||||
|
||||
28
prediqo_web/src/features/landing/api/publicApkApi.ts
Normal file
28
prediqo_web/src/features/landing/api/publicApkApi.ts
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
* Public Android APK metadata for the landing-page download button.
|
||||
*/
|
||||
|
||||
export type LatestAndroidApk = {
|
||||
available: boolean;
|
||||
versionName: string | null;
|
||||
versionCode: number | null;
|
||||
fileSizeBytes: number | null;
|
||||
sha256: string | null;
|
||||
downloadUrl: string | null;
|
||||
downloadPath: string | null;
|
||||
publishedAt: string | null;
|
||||
packageName: string | null;
|
||||
};
|
||||
|
||||
/** Fetches the latest published production APK (no auth). */
|
||||
export async function fetchLatestAndroidApk(): Promise<LatestAndroidApk> {
|
||||
const res = await fetch('/api/v1/app-updates/android/latest', {
|
||||
method: 'GET',
|
||||
headers: { Accept: 'application/json' },
|
||||
cache: 'no-store',
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`Latest APK request failed (${res.status})`);
|
||||
}
|
||||
return (await res.json()) as LatestAndroidApk;
|
||||
}
|
||||
@ -1,11 +1,12 @@
|
||||
/**
|
||||
* Fixed public nav — brand, section anchors, language, login + signup once.
|
||||
* Fixed public nav — brand, section anchors, language, APK download, login + signup once.
|
||||
*/
|
||||
import { useState, type CSSProperties } from 'react';
|
||||
import { useCallback, useState, type CSSProperties } from 'react';
|
||||
import { Link as RouterLink } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { LanguageSwitcher } from '../../../shared/i18n/LanguageSwitcher';
|
||||
import { PLATFORM_WORDMARK } from '../../../shared/brand/platformName';
|
||||
import { fetchLatestAndroidApk } from '../api/publicApkApi';
|
||||
|
||||
type NavItem = { id: string; label: string };
|
||||
|
||||
@ -17,6 +18,33 @@ type LandingHeaderProps = {
|
||||
export function LandingHeader({ navItems, onNavigateSection }: LandingHeaderProps) {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [apkBusy, setApkBusy] = useState(false);
|
||||
const [apkHint, setApkHint] = useState<string | null>(null);
|
||||
|
||||
const onDownloadApk = useCallback(async () => {
|
||||
if (apkBusy) return;
|
||||
setApkBusy(true);
|
||||
setApkHint(null);
|
||||
try {
|
||||
const latest = await fetchLatestAndroidApk();
|
||||
if (!latest.available || (!latest.downloadPath && !latest.downloadUrl)) {
|
||||
setApkHint(t('landing.nav.apkUnavailable'));
|
||||
return;
|
||||
}
|
||||
const href = latest.downloadPath || latest.downloadUrl!;
|
||||
const a = document.createElement('a');
|
||||
a.href = href;
|
||||
a.rel = 'noopener';
|
||||
a.download = latest.versionName ? `tloto-${latest.versionName}.apk` : 'tloto.apk';
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
a.remove();
|
||||
} catch {
|
||||
setApkHint(t('landing.nav.apkError'));
|
||||
} finally {
|
||||
setApkBusy(false);
|
||||
}
|
||||
}, [apkBusy, t]);
|
||||
|
||||
return (
|
||||
<header
|
||||
@ -83,6 +111,16 @@ export function LandingHeader({ navItems, onNavigateSection }: LandingHeaderProp
|
||||
|
||||
<div style={{ marginLeft: 'auto', display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<LanguageSwitcher />
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void onDownloadApk()}
|
||||
disabled={apkBusy}
|
||||
title={t('landing.nav.downloadApk')}
|
||||
aria-label={t('landing.nav.downloadApk')}
|
||||
style={apkIconBtnStyle}
|
||||
>
|
||||
<ApkDownloadIcon busy={apkBusy} />
|
||||
</button>
|
||||
<RouterLink to="/login" style={ghostBtnStyle} className="tl-hide-xs">
|
||||
{t('landing.nav.login')}
|
||||
</RouterLink>
|
||||
@ -110,6 +148,26 @@ export function LandingHeader({ navItems, onNavigateSection }: LandingHeaderProp
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{apkHint && (
|
||||
<div
|
||||
role="status"
|
||||
style={{
|
||||
maxWidth: 1360,
|
||||
margin: '0.55rem auto 0',
|
||||
padding: '0.65rem 1rem',
|
||||
borderRadius: 12,
|
||||
border: '1px solid rgba(248,113,113,0.35)',
|
||||
background: 'rgba(127,29,29,0.55)',
|
||||
color: '#fecaca',
|
||||
fontSize: '0.85rem',
|
||||
fontWeight: 600,
|
||||
pointerEvents: 'auto',
|
||||
}}
|
||||
>
|
||||
{apkHint}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{open && (
|
||||
<div
|
||||
style={{
|
||||
@ -152,6 +210,26 @@ export function LandingHeader({ navItems, onNavigateSection }: LandingHeaderProp
|
||||
>
|
||||
{t('landing.nav.faq')}
|
||||
</RouterLink>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setOpen(false);
|
||||
void onDownloadApk();
|
||||
}}
|
||||
disabled={apkBusy}
|
||||
style={{
|
||||
...navLinkStyle,
|
||||
justifyContent: 'flex-start',
|
||||
width: '100%',
|
||||
padding: '0.85rem 1rem',
|
||||
display: 'inline-flex',
|
||||
alignItems: 'center',
|
||||
gap: 10,
|
||||
}}
|
||||
>
|
||||
<ApkDownloadIcon busy={apkBusy} />
|
||||
{t('landing.nav.downloadApk')}
|
||||
</button>
|
||||
<RouterLink
|
||||
to="/login"
|
||||
onClick={() => setOpen(false)}
|
||||
@ -177,6 +255,43 @@ export function LandingHeader({ navItems, onNavigateSection }: LandingHeaderProp
|
||||
);
|
||||
}
|
||||
|
||||
function ApkDownloadIcon({ busy }: { busy: boolean }) {
|
||||
return (
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" aria-hidden style={{ opacity: busy ? 0.55 : 1 }}>
|
||||
<path
|
||||
d="M12 3v10m0 0l3.5-3.5M12 13L8.5 9.5"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.8"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
<path
|
||||
d="M5 16.5V18a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-1.5"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.8"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
const apkIconBtnStyle: CSSProperties = {
|
||||
appearance: 'none',
|
||||
width: 40,
|
||||
height: 40,
|
||||
borderRadius: 999,
|
||||
border: '1px solid rgba(255,255,255,0.16)',
|
||||
background: 'rgba(255,255,255,0.04)',
|
||||
color: 'rgba(238,243,251,0.92)',
|
||||
display: 'inline-flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
cursor: 'pointer',
|
||||
flexShrink: 0,
|
||||
padding: 0,
|
||||
};
|
||||
|
||||
const navLinkStyle: CSSProperties = {
|
||||
appearance: 'none',
|
||||
border: 0,
|
||||
|
||||
@ -83,6 +83,9 @@ export const en = {
|
||||
live: 'Live',
|
||||
why: 'Why Tloto',
|
||||
faq: 'FAQ',
|
||||
downloadApk: 'Download Android app',
|
||||
apkUnavailable: 'No Android app is published yet. Check back soon.',
|
||||
apkError: 'Could not start the Android download. Please try again.',
|
||||
},
|
||||
hero: {
|
||||
tagline: 'Premium prediction platform',
|
||||
|
||||
@ -83,6 +83,9 @@ export const fr = {
|
||||
live: 'En direct',
|
||||
why: 'Pourquoi Tloto',
|
||||
faq: 'FAQ',
|
||||
downloadApk: 'Télécharger l’app Android',
|
||||
apkUnavailable: 'Aucune app Android n’est encore publiée. Réessayez bientôt.',
|
||||
apkError: 'Impossible de lancer le téléchargement Android. Réessayez.',
|
||||
},
|
||||
hero: {
|
||||
tagline: 'Plateforme de prédiction premium',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user