Improved attachments

This commit is contained in:
2024-06-01 21:39:28 +08:00
parent a651350104
commit e96b49e3cd
11 changed files with 204 additions and 20 deletions

View File

@ -25,14 +25,25 @@ Future<double> calculateFileAspectRatio(File file) async {
}
class AttachmentProvider extends GetConnect {
static Map<String, String> mimetypeOverrides = {'mov': 'video/quicktime'};
@override
void onInit() {
httpClient.baseUrl = ServiceFinder.services['paperclip'];
}
static Map<String, String> mimetypeOverrides = {'mov': 'video/quicktime'};
final Map<int, Response> _cachedResponses = {};
Future<Response> getMetadata(int id) => get('/api/attachments/$id/meta');
Future<Response> getMetadata(int id, {noCache = false}) async {
if (!noCache && _cachedResponses.containsKey(id)) {
return _cachedResponses[id]!;
}
final resp = await get('/api/attachments/$id/meta');
_cachedResponses[id] = resp;
return resp;
}
Future<Response> createAttachment(File file, String hash, String usage,
{double? ratio}) async {
@ -122,4 +133,12 @@ class AttachmentProvider extends GetConnect {
return resp;
}
void clearCache({int? id}) {
if (id != null) {
_cachedResponses.remove(id);
} else {
_cachedResponses.clear();
}
}
}