mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-30 22:25:12 +00:00
Enforce video/audio extension by mime type.
This commit is contained in:
@@ -484,13 +484,13 @@ void DocumentData::setattributes(
|
||||
|| type == AnimatedDocument
|
||||
|| type == RoundVideoDocument
|
||||
|| isAnimation()) {
|
||||
if (_nameType != Type::Video) {
|
||||
if (!enforceNameType(Type::Video)) {
|
||||
type = FileDocument;
|
||||
_additional = nullptr;
|
||||
}
|
||||
}
|
||||
if (type == SongDocument || type == VoiceDocument || isAudioFile()) {
|
||||
if (_nameType != Type::Audio) {
|
||||
if (!enforceNameType(Type::Audio)) {
|
||||
type = FileDocument;
|
||||
_additional = nullptr;
|
||||
}
|
||||
@@ -951,6 +951,24 @@ void DocumentData::setFileName(const QString &remoteFileName) {
|
||||
_nameType = Core::DetectNameType(_filename);
|
||||
}
|
||||
|
||||
bool DocumentData::enforceNameType(Core::NameType nameType) {
|
||||
if (_nameType == nameType) {
|
||||
return true;
|
||||
}
|
||||
const auto base = _filename.isEmpty() ? u"file"_q : _filename;
|
||||
const auto mime = Core::MimeTypeForName(mimeString());
|
||||
const auto patterns = mime.globPatterns();
|
||||
for (const auto &pattern : mime.globPatterns()) {
|
||||
const auto now = base + QString(pattern).replace('*', QString());
|
||||
if (Core::DetectNameType(now) == nameType) {
|
||||
_filename = now;
|
||||
_nameType = nameType;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void DocumentData::setLoadedInMediaCacheLocation() {
|
||||
_location = Core::FileLocation();
|
||||
_flags |= Flag::LoadedInMediaCache;
|
||||
|
Reference in New Issue
Block a user