✨ Link expand
This commit is contained in:
25
lib/providers/link_expander.dart
Normal file
25
lib/providers/link_expander.dart
Normal file
@ -0,0 +1,25 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:get/get.dart';
|
||||
import 'package:solian/models/link.dart';
|
||||
import 'package:solian/services.dart';
|
||||
|
||||
class LinkExpandController extends GetxController {
|
||||
final Map<String, LinkMeta?> _cachedResponse = {};
|
||||
|
||||
Future<LinkMeta?> expandLink(String url) async {
|
||||
final target = utf8.fuse(base64).encode(url);
|
||||
if (_cachedResponse.containsKey(target)) return _cachedResponse[target];
|
||||
final client = ServiceFinder.configureClient('dealer');
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user