2023-05-01 13:13:40 -04:00
|
|
|
import 'package:contacts_plus_plus/config.dart';
|
2023-04-30 03:01:59 -04:00
|
|
|
import 'package:path/path.dart' as p;
|
|
|
|
|
|
|
|
enum NeosDBEndpoint
|
|
|
|
{
|
|
|
|
def,
|
|
|
|
blob,
|
|
|
|
cdn,
|
|
|
|
videoCDN,
|
|
|
|
}
|
|
|
|
|
|
|
|
extension NeosStringExtensions on Uri {
|
|
|
|
static String dbSignature(Uri neosdb) => neosdb.pathSegments.length < 2 ? "" : p.basenameWithoutExtension(neosdb.pathSegments[1]);
|
|
|
|
static String? neosDBQuery(Uri neosdb) => neosdb.query.trim().isEmpty ? null : neosdb.query.substring(1);
|
|
|
|
static bool isLegacyNeosDB(Uri uri) => !(uri.scheme != "neosdb") && uri.pathSegments.length >= 2 && p.basenameWithoutExtension(uri.pathSegments[1]).length < 30;
|
|
|
|
|
|
|
|
Uri neosDBToHTTP(NeosDBEndpoint endpoint) {
|
|
|
|
var signature = dbSignature(this);
|
|
|
|
var query = neosDBQuery(this);
|
|
|
|
if (query != null) {
|
|
|
|
signature = "$signature/$query";
|
|
|
|
}
|
|
|
|
if (isLegacyNeosDB(this)) {
|
|
|
|
return Uri.parse(Config.legacyCloudUrl + signature);
|
|
|
|
}
|
|
|
|
String base;
|
|
|
|
switch (endpoint) {
|
|
|
|
case NeosDBEndpoint.blob:
|
|
|
|
base = Config.blobStorageUrl;
|
|
|
|
break;
|
|
|
|
case NeosDBEndpoint.cdn:
|
|
|
|
base = Config.neosCdnUrl;
|
|
|
|
break;
|
|
|
|
case NeosDBEndpoint.videoCDN:
|
|
|
|
base = Config.videoStorageUrl;
|
|
|
|
break;
|
|
|
|
case NeosDBEndpoint.def:
|
|
|
|
base = Config.neosAssetsUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Uri.parse(base + signature);
|
|
|
|
}
|
2023-04-30 17:14:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class Aux {
|
|
|
|
static String neosDbToHttp(String neosdb) {
|
|
|
|
final fullUri = neosdb.replaceFirst("neosdb:///", Config.neosCdnUrl);
|
|
|
|
final lastPeriodIndex = fullUri.lastIndexOf(".");
|
|
|
|
if (lastPeriodIndex != -1 && fullUri.length - lastPeriodIndex < 8) {
|
|
|
|
// I feel like 8 is a good maximum for file extension length? Can neosdb Uris even come without file extensions?
|
|
|
|
return fullUri.substring(0, lastPeriodIndex);
|
|
|
|
}
|
|
|
|
return fullUri;
|
|
|
|
}
|
2023-05-01 12:50:54 -04:00
|
|
|
}
|