add macOS support for ad loading and improve timestamp handling
Some checks failed
Build Android App / build (push) Failing after 49s

This commit is contained in:
ImBenji
2026-01-02 18:46:12 +00:00
parent 016f7911f3
commit 7d8e19d1f5
13 changed files with 369 additions and 75 deletions

View File

@@ -159,9 +159,36 @@ class QuoteSession {
}
class QuoteSnapshot {
final String token;
final String url;
final String sessionId;
final int createdAt;
final int expiresAt;
QuoteSnapshot({
required this.token,
required this.url,
required this.sessionId,
required this.createdAt,
required this.expiresAt,
});
factory QuoteSnapshot.fromJson(Map<String, dynamic> json) {
return QuoteSnapshot(
token: json["token"],
url: json["url"],
sessionId: json["sessionId"],
createdAt: json["createdAt"],
expiresAt: json["expiresAt"],
);
}
}
class QuoteGeneratorApiV2 {
static const String _baseUrl = "https://quotes.imbenji.net";
// static const String _baseUrl = "http://localhost:3000";
// static const String _baseUrl = "https://quotes.imbenji.net";
static const String _baseUrl = "http://localhost:3000";
// create new session
@@ -259,6 +286,40 @@ class QuoteGeneratorApiV2 {
}
// create persistant snapshot link
static Future<QuoteSnapshot> createSnapshotLink(String sessionId) async {
final url = Uri.parse("$_baseUrl/v2/quote/$sessionId/snapshot-link");
final response = await http.post(
url,
headers: {"User-Agent": "QuoteGen-Flutter/1.0"},
);
if (response.statusCode == 201) {
final data = jsonDecode(response.body);
return QuoteSnapshot.fromJson(data);
} else {
throw Exception("Failed to create snapshot link: ${response.statusCode}");
}
}
// get snapshot image by token
static Future<Uint8List> getSnapshot(String token) async {
final url = Uri.parse("$_baseUrl/v2/snapshot/$token");
final response = await http.get(
url,
headers: {"User-Agent": "QuoteGen-Flutter/1.0"},
);
if (response.statusCode == 200) {
return response.bodyBytes;
} else {
throw Exception("Failed to get snapshot: ${response.statusCode}");
}
}
// helper to get current timestamp in seconds
static int getCurrentTimestamp() {
return DateTime.now().millisecondsSinceEpoch ~/ 1000;