apstanisic / directus-dart

Directus SDK for Dart and Flutter
MIT License
37 stars 24 forks source link

Improve `DirectusFile.downloadUrl` method #49

Open reev-create opened 2 years ago

reev-create commented 2 years ago

https://github.com/apstanisic/directus-dart/blob/ec87f59f5260470a06f9672dddc1baf962a8b85d/lib/src/modules/files/directus_file.dart#L18

File download URL should return the whole download URL along with concatenated auth token of the current user

reev-create commented 2 years ago

Something like this

String? downloadUrl(String baseUrl) {
  if (id == null) return null;
  // Remove trailing / if exists.
  if (baseUrl.endsWith('/')) {
    baseUrl = baseUrl.substring(0, baseUrl.length - 1);
  }

  return '$baseUrl/assets/$id?access_token=${sdk.auth.tokens?.accessToken}';
}
apstanisic commented 2 years ago

That's a cool idea. But we don't have access to SDK in DirectusFile. User would either have to pass sdk or access token as a named param. Something like: downloadUrl(String baseUrl, {String? accessToken}), or downloadUrl(String baseUrl, {Directus? sdk}).