Respond to CR.

// FREEBIE
pull/1/head
Matthew Chen 8 years ago
parent 270a10a62a
commit e05b687438

@ -16,119 +16,165 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
@implementation MIMETypeUtil @implementation MIMETypeUtil
+ (NSDictionary *)supportedVideoMIMETypesToExtensionTypes { + (NSDictionary *)supportedVideoMIMETypesToExtensionTypes {
return @{ static NSDictionary *result = nil;
@"video/3gpp" : @"3gp", static dispatch_once_t onceToken;
@"video/3gpp2" : @"3g2", dispatch_once(&onceToken, ^{
@"video/mp4" : @"mp4", result = @{
@"video/quicktime" : @"mov", @"video/3gpp" : @"3gp",
@"video/x-m4v" : @"m4v" @"video/3gpp2" : @"3g2",
}; @"video/mp4" : @"mp4",
@"video/quicktime" : @"mov",
@"video/x-m4v" : @"m4v"
};
});
return result;
} }
+ (NSDictionary *)supportedAudioMIMETypesToExtensionTypes { + (NSDictionary *)supportedAudioMIMETypesToExtensionTypes {
return @{ static NSDictionary *result = nil;
@"audio/aac" : @"m4a", static dispatch_once_t onceToken;
@"audio/x-m4p" : @"m4p", dispatch_once(&onceToken, ^{
@"audio/x-m4b" : @"m4b", result = @{
@"audio/x-m4a" : @"m4a", @"audio/aac" : @"m4a",
@"audio/wav" : @"wav", @"audio/x-m4p" : @"m4p",
@"audio/x-wav" : @"wav", @"audio/x-m4b" : @"m4b",
@"audio/x-mpeg" : @"mp3", @"audio/x-m4a" : @"m4a",
@"audio/mpeg" : @"mp3", @"audio/wav" : @"wav",
@"audio/mp4" : @"mp4", @"audio/x-wav" : @"wav",
@"audio/mp3" : @"mp3", @"audio/x-mpeg" : @"mp3",
@"audio/mpeg3" : @"mp3", @"audio/mpeg" : @"mp3",
@"audio/x-mp3" : @"mp3", @"audio/mp4" : @"mp4",
@"audio/x-mpeg3" : @"mp3", @"audio/mp3" : @"mp3",
@"audio/amr" : @"amr", @"audio/mpeg3" : @"mp3",
@"audio/aiff" : @"aiff", @"audio/x-mp3" : @"mp3",
@"audio/x-aiff" : @"aiff", @"audio/x-mpeg3" : @"mp3",
@"audio/3gpp2" : @"3g2", @"audio/amr" : @"amr",
@"audio/3gpp" : @"3gp" @"audio/aiff" : @"aiff",
}; @"audio/x-aiff" : @"aiff",
@"audio/3gpp2" : @"3g2",
@"audio/3gpp" : @"3gp"
};
});
return result;
} }
+ (NSDictionary *)supportedImageMIMETypesToExtensionTypes { + (NSDictionary *)supportedImageMIMETypesToExtensionTypes {
return @{ static NSDictionary *result = nil;
@"image/jpeg" : @"jpeg", static dispatch_once_t onceToken;
@"image/pjpeg" : @"jpeg", dispatch_once(&onceToken, ^{
OWSMimeTypeImagePng : @"png", result = @{
@"image/tiff" : @"tif", @"image/jpeg" : @"jpeg",
@"image/x-tiff" : @"tif", @"image/pjpeg" : @"jpeg",
@"image/bmp" : @"bmp", OWSMimeTypeImagePng : @"png",
@"image/x-windows-bmp" : @"bmp" @"image/tiff" : @"tif",
}; @"image/x-tiff" : @"tif",
@"image/bmp" : @"bmp",
@"image/x-windows-bmp" : @"bmp"
};
});
return result;
} }
+ (NSDictionary *)supportedAnimatedMIMETypesToExtensionTypes { + (NSDictionary *)supportedAnimatedMIMETypesToExtensionTypes {
return @{ static NSDictionary *result = nil;
@"image/gif" : @"gif", static dispatch_once_t onceToken;
}; dispatch_once(&onceToken, ^{
result = @{
@"image/gif" : @"gif",
};
});
return result;
} }
+ (NSDictionary *)supportedBinaryDataMIMETypesToExtensionTypes + (NSDictionary *)supportedBinaryDataMIMETypesToExtensionTypes
{ {
return @{ static NSDictionary *result = nil;
OWSMimeTypeApplicationOctetStream : @"dat", static dispatch_once_t onceToken;
}; dispatch_once(&onceToken, ^{
result = @{
OWSMimeTypeApplicationOctetStream : @"dat",
};
});
return result;
} }
+ (NSDictionary *)supportedVideoExtensionTypesToMIMETypes { + (NSDictionary *)supportedVideoExtensionTypesToMIMETypes {
return @{ static NSDictionary *result = nil;
@"3gp" : @"video/3gpp", static dispatch_once_t onceToken;
@"3gpp" : @"video/3gpp", dispatch_once(&onceToken, ^{
@"3gp2" : @"video/3gpp2", result = @{
@"3gpp2" : @"video/3gpp2", @"3gp" : @"video/3gpp",
@"mp4" : @"video/mp4", @"3gpp" : @"video/3gpp",
@"mov" : @"video/quicktime", @"3gp2" : @"video/3gpp2",
@"mqv" : @"video/quicktime", @"3gpp2" : @"video/3gpp2",
@"m4v" : @"video/x-m4v" @"mp4" : @"video/mp4",
}; @"mov" : @"video/quicktime",
@"mqv" : @"video/quicktime",
@"m4v" : @"video/x-m4v"
};
});
return result;
} }
+ (NSDictionary *)supportedAudioExtensionTypesToMIMETypes { + (NSDictionary *)supportedAudioExtensionTypesToMIMETypes {
return @{ static NSDictionary *result = nil;
@"3gp" : @"audio/3gpp", static dispatch_once_t onceToken;
@"3gpp" : @"@audio/3gpp", dispatch_once(&onceToken, ^{
@"3g2" : @"audio/3gpp2", result = @{
@"3gp2" : @"audio/3gpp2", @"3gp" : @"audio/3gpp",
@"aiff" : @"audio/aiff", @"3gpp" : @"@audio/3gpp",
@"aif" : @"audio/aiff", @"3g2" : @"audio/3gpp2",
@"aifc" : @"audio/aiff", @"3gp2" : @"audio/3gpp2",
@"cdda" : @"audio/aiff", @"aiff" : @"audio/aiff",
@"amr" : @"audio/amr", @"aif" : @"audio/aiff",
@"mp3" : @"audio/mp3", @"aifc" : @"audio/aiff",
@"swa" : @"audio/mp3", @"cdda" : @"audio/aiff",
@"mp4" : @"audio/mp4", @"amr" : @"audio/amr",
@"mpeg" : @"audio/mpeg", @"mp3" : @"audio/mp3",
@"mpg" : @"audio/mpeg", @"swa" : @"audio/mp3",
@"wav" : @"audio/wav", @"mp4" : @"audio/mp4",
@"bwf" : @"audio/wav", @"mpeg" : @"audio/mpeg",
@"m4a" : @"audio/x-m4a", @"mpg" : @"audio/mpeg",
@"m4b" : @"audio/x-m4b", @"wav" : @"audio/wav",
@"m4p" : @"audio/x-m4p" @"bwf" : @"audio/wav",
}; @"m4a" : @"audio/x-m4a",
@"m4b" : @"audio/x-m4b",
@"m4p" : @"audio/x-m4p"
};
});
return result;
} }
+ (NSDictionary *)supportedImageExtensionTypesToMIMETypes { + (NSDictionary *)supportedImageExtensionTypesToMIMETypes {
return @{ static NSDictionary *result = nil;
@"png" : OWSMimeTypeImagePng, static dispatch_once_t onceToken;
@"x-png" : OWSMimeTypeImagePng, dispatch_once(&onceToken, ^{
@"jfif" : @"image/jpeg", result = @{
@"jfif" : @"image/pjpeg", @"png" : OWSMimeTypeImagePng,
@"jfif-tbnl" : @"image/jpeg", @"x-png" : OWSMimeTypeImagePng,
@"jpe" : @"image/jpeg", @"jfif" : @"image/jpeg",
@"jpe" : @"image/pjpeg", @"jfif" : @"image/pjpeg",
@"jpeg" : @"image/jpeg", @"jfif-tbnl" : @"image/jpeg",
@"jpg" : @"image/jpeg", @"jpe" : @"image/jpeg",
@"tif" : @"image/tiff", @"jpe" : @"image/pjpeg",
@"tiff" : @"image/tiff" @"jpeg" : @"image/jpeg",
}; @"jpg" : @"image/jpeg",
@"tif" : @"image/tiff",
@"tiff" : @"image/tiff"
};
});
return result;
} }
+ (NSDictionary *)supportedAnimatedExtensionTypesToMIMETypes { + (NSDictionary *)supportedAnimatedExtensionTypesToMIMETypes {
return @{ static NSDictionary *result = nil;
@"gif" : @"image/gif", static dispatch_once_t onceToken;
}; dispatch_once(&onceToken, ^{
result = @{
@"gif" : @"image/gif",
};
});
return result;
} }
+ (BOOL)isSupportedVideoMIMEType:(NSString *)contentType { + (BOOL)isSupportedVideoMIMEType:(NSString *)contentType {
@ -328,22 +374,46 @@ NSString *const OWSMimeTypeImagePng = @"image/png";
+ (NSSet<NSString *> *)supportedVideoUTITypes + (NSSet<NSString *> *)supportedVideoUTITypes
{ {
return [self utiTypesForMIMETypes:[self supportedVideoMIMETypesToExtensionTypes].allKeys]; OWSAssert([NSThread isMainThread]);
static NSSet<NSString *> *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = [self utiTypesForMIMETypes:[self supportedVideoMIMETypesToExtensionTypes].allKeys];
});
return result;
} }
+ (NSSet<NSString *> *)supportedAudioUTITypes + (NSSet<NSString *> *)supportedAudioUTITypes
{ {
return [self utiTypesForMIMETypes:[self supportedAudioMIMETypesToExtensionTypes].allKeys]; OWSAssert([NSThread isMainThread]);
static NSSet<NSString *> *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = [self utiTypesForMIMETypes:[self supportedAudioMIMETypesToExtensionTypes].allKeys];
});
return result;
} }
+ (NSSet<NSString *> *)supportedImageUTITypes + (NSSet<NSString *> *)supportedImageUTITypes
{ {
return [self utiTypesForMIMETypes:[self supportedImageMIMETypesToExtensionTypes].allKeys]; OWSAssert([NSThread isMainThread]);
static NSSet<NSString *> *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = [self utiTypesForMIMETypes:[self supportedImageMIMETypesToExtensionTypes].allKeys];
});
return result;
} }
+ (NSSet<NSString *> *)supportedAnimatedImageUTITypes + (NSSet<NSString *> *)supportedAnimatedImageUTITypes
{ {
return [self utiTypesForMIMETypes:[self supportedAnimatedMIMETypesToExtensionTypes].allKeys]; OWSAssert([NSThread isMainThread]);
static NSSet<NSString *> *result = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
result = [self utiTypesForMIMETypes:[self supportedAnimatedMIMETypesToExtensionTypes].allKeys];
});
return result;
} }
@end @end

Loading…
Cancel
Save