2024-08-19 11:36:01 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:developer';
|
|
|
|
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:solian/models/link.dart';
|
|
|
|
import 'package:solian/services.dart';
|
|
|
|
|
2024-09-02 15:11:40 +00:00
|
|
|
class LinkExpandProvider extends GetxController {
|
2024-08-19 11:36:01 +00:00
|
|
|
final Map<String, LinkMeta?> _cachedResponse = {};
|
|
|
|
|
|
|
|
Future<LinkMeta?> expandLink(String url) async {
|
2024-08-26 04:13:09 +00:00
|
|
|
log('[LinkExpander] Expanding link... $url');
|
2024-08-19 11:36:01 +00:00
|
|
|
final target = utf8.fuse(base64).encode(url);
|
|
|
|
if (_cachedResponse.containsKey(target)) return _cachedResponse[target];
|
2024-09-16 03:57:16 +00:00
|
|
|
final client = await ServiceFinder.configureClient('dealer');
|
2024-08-19 11:36:01 +00:00
|
|
|
final resp = await client.get('/api/links/$target');
|
|
|
|
if (resp.statusCode != 200) {
|
|
|
|
log('Unable to expand link ($url), status: ${resp.statusCode}, response: ${resp.body}');
|
|
|
|
_cachedResponse[target] = null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
final result = LinkMeta.fromJson(resp.body);
|
|
|
|
_cachedResponse[target] = result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|