mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 19:34:23 +02:00
Split MIMETypeLibrary file type detection into three separate functions
This commit is contained in:
parent
660d8c4e92
commit
19459c15a5
3 changed files with 21 additions and 4 deletions
libraries
|
@ -50,7 +50,14 @@ std::shared_ptr<Serializer> FormatRegistry::getSerializerForMIMEType(const hifi:
|
|||
{
|
||||
// TODO: shared_lock in C++14
|
||||
std::lock_guard<std::mutex> lock(*const_cast<std::mutex*>(&_libraryLock));
|
||||
id = _mimeTypeLibrary.findMatchingMIMEType(data, url, webMediaType);
|
||||
|
||||
id = _mimeTypeLibrary.findMIMETypeForData(data);
|
||||
if (id == INVALID_MIME_TYPE_ID) {
|
||||
id = _mimeTypeLibrary.findMIMETypeForURL(url);
|
||||
}
|
||||
if (id == INVALID_MIME_TYPE_ID) {
|
||||
id = _mimeTypeLibrary.findMIMETypeForMediaType(webMediaType);
|
||||
}
|
||||
}
|
||||
return getSerializerForMIMETypeID(id);
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ MIMEType MIMETypeLibrary::getMIMEType(const MIMETypeLibrary::ID& id) const {
|
|||
return MIMEType::NONE;
|
||||
}
|
||||
|
||||
MIMETypeLibrary::ID MIMETypeLibrary::findMatchingMIMEType(const hifi::ByteArray& data, const hifi::URL& url, const std::string& webMediaType) const {
|
||||
MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForData(const hifi::ByteArray& data) const {
|
||||
// Check file contents
|
||||
for (auto& mimeType : _mimeTypes) {
|
||||
for (auto& fileSignature : mimeType.mimeType.fileSignatures) {
|
||||
|
@ -46,6 +46,10 @@ MIMETypeLibrary::ID MIMETypeLibrary::findMatchingMIMEType(const hifi::ByteArray&
|
|||
}
|
||||
}
|
||||
|
||||
return INVALID_ID;
|
||||
}
|
||||
|
||||
MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForURL(const hifi::URL& url) const {
|
||||
// Check file extension
|
||||
std::string urlString = url.path().toStdString();
|
||||
std::size_t extensionSeparator = urlString.rfind('.');
|
||||
|
@ -60,6 +64,10 @@ MIMETypeLibrary::ID MIMETypeLibrary::findMatchingMIMEType(const hifi::ByteArray&
|
|||
}
|
||||
}
|
||||
|
||||
return INVALID_ID;
|
||||
}
|
||||
|
||||
MIMETypeLibrary::ID MIMETypeLibrary::findMIMETypeForMediaType(const std::string& webMediaType) const {
|
||||
// Check web media type
|
||||
if (webMediaType != "") {
|
||||
for (auto& supportedFormat : _mimeTypes) {
|
||||
|
@ -71,6 +79,5 @@ MIMETypeLibrary::ID MIMETypeLibrary::findMatchingMIMEType(const hifi::ByteArray&
|
|||
}
|
||||
}
|
||||
|
||||
// Supported file type not found.
|
||||
return INVALID_ID;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,10 @@ public:
|
|||
void unregisterMIMEType(const ID& id);
|
||||
|
||||
MIMEType getMIMEType(const ID& id) const;
|
||||
ID findMatchingMIMEType(const hifi::ByteArray& data, const hifi::URL& url, const std::string& webMediaType) const;
|
||||
|
||||
ID findMIMETypeForData(const hifi::ByteArray& data) const;
|
||||
ID findMIMETypeForURL(const hifi::URL& url) const;
|
||||
ID findMIMETypeForMediaType(const std::string& webMediaType) const;
|
||||
|
||||
protected:
|
||||
ID nextID { 1 };
|
||||
|
|
Loading…
Reference in a new issue