mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-30 09:30:47 +03:00
Fix media deletion of animated files
This commit is contained in:
parent
80a39cca17
commit
4f6c840ed1
4 changed files with 42 additions and 16 deletions
|
@ -32,16 +32,17 @@ MxcImageProvider::MxcImageProvider()
|
||||||
timer->setInterval(std::chrono::hours(1));
|
timer->setInterval(std::chrono::hours(1));
|
||||||
connect(timer, &QTimer::timeout, this, [] {
|
connect(timer, &QTimer::timeout, this, [] {
|
||||||
QThreadPool::globalInstance()->start([] {
|
QThreadPool::globalInstance()->start([] {
|
||||||
|
nhlog::net()->debug("Running media purge");
|
||||||
QDir dir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) +
|
QDir dir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) +
|
||||||
"/media_cache",
|
"/media_cache",
|
||||||
"",
|
"",
|
||||||
QDir::SortFlags(QDir::Name | QDir::IgnoreCase),
|
QDir::SortFlags(QDir::Name | QDir::IgnoreCase),
|
||||||
QDir::Filter::Writable | QDir::Filter::NoDotAndDotDot | QDir::Filter::Files);
|
QDir::Filter::Writable | QDir::Filter::NoDotAndDotDot | QDir::Filter::Files |
|
||||||
|
QDir::Filter::Dirs);
|
||||||
|
|
||||||
auto files = dir.entryInfoList();
|
auto handleFile = [](const QFileInfo &fileInfo) {
|
||||||
for (const auto &fileInfo : std::as_const(files)) {
|
|
||||||
if (fileInfo.fileTime(QFile::FileTime::FileAccessTime)
|
if (fileInfo.fileTime(QFile::FileTime::FileAccessTime)
|
||||||
.daysTo(QDateTime::currentDateTime()) > 30) {
|
.daysTo(QDateTime::currentDateTime()) > 14) {
|
||||||
if (QFile::remove(fileInfo.absoluteFilePath()))
|
if (QFile::remove(fileInfo.absoluteFilePath()))
|
||||||
nhlog::net()->debug("Deleted stale media '{}'",
|
nhlog::net()->debug("Deleted stale media '{}'",
|
||||||
fileInfo.absoluteFilePath().toStdString());
|
fileInfo.absoluteFilePath().toStdString());
|
||||||
|
@ -49,6 +50,25 @@ MxcImageProvider::MxcImageProvider()
|
||||||
nhlog::net()->warn("Failed to delete stale media '{}'",
|
nhlog::net()->warn("Failed to delete stale media '{}'",
|
||||||
fileInfo.absoluteFilePath().toStdString());
|
fileInfo.absoluteFilePath().toStdString());
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
auto files = dir.entryInfoList();
|
||||||
|
for (const auto &fileInfo : std::as_const(files)) {
|
||||||
|
if (fileInfo.isDir()) {
|
||||||
|
// handle one level of legacy directories
|
||||||
|
auto nestedDir = QDir(fileInfo.absoluteFilePath(),
|
||||||
|
"",
|
||||||
|
QDir::SortFlags(QDir::Name | QDir::IgnoreCase),
|
||||||
|
QDir::Filter::Writable | QDir::Filter::NoDotAndDotDot |
|
||||||
|
QDir::Filter::Files
|
||||||
|
)
|
||||||
|
.entryInfoList();
|
||||||
|
for (const auto &nestedFile : std::as_const(nestedDir)) {
|
||||||
|
handleFile(nestedFile);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
handleFile(fileInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -2073,10 +2073,12 @@ TimelineModel::cacheMedia(const QString &eventId,
|
||||||
|
|
||||||
const auto url = mxcUrl.toStdString();
|
const auto url = mxcUrl.toStdString();
|
||||||
const auto name = QString(mxcUrl).remove(QStringLiteral("mxc://"));
|
const auto name = QString(mxcUrl).remove(QStringLiteral("mxc://"));
|
||||||
QFileInfo filename(
|
QFileInfo filename(QStringLiteral("%1/media_cache/%2.%3")
|
||||||
QStringLiteral("%1/media_cache/%2.%3")
|
.arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation),
|
||||||
.arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation), name, suffix));
|
QString::fromUtf8(name.toUtf8().toBase64(
|
||||||
if (QDir::cleanPath(name) != name) {
|
QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals)),
|
||||||
|
suffix));
|
||||||
|
if (QDir::cleanPath(filename.filePath()) != filename.filePath()) {
|
||||||
nhlog::net()->warn("mxcUrl '{}' is not safe, not downloading file", url);
|
nhlog::net()->warn("mxcUrl '{}' is not safe, not downloading file", url);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,10 +53,12 @@ MxcAnimatedImage::startDownload()
|
||||||
|
|
||||||
const auto url = mxcUrl.toStdString();
|
const auto url = mxcUrl.toStdString();
|
||||||
const auto name = QString(mxcUrl).remove(QStringLiteral("mxc://"));
|
const auto name = QString(mxcUrl).remove(QStringLiteral("mxc://"));
|
||||||
QFileInfo filename(
|
QFileInfo filename(QStringLiteral("%1/media_cache/media/%2.%3")
|
||||||
QStringLiteral("%1/media_cache/media/%2.%3")
|
.arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation),
|
||||||
.arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation), name, suffix));
|
QString::fromUtf8(name.toUtf8().toBase64(
|
||||||
if (QDir::cleanPath(name) != name) {
|
QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals)),
|
||||||
|
suffix));
|
||||||
|
if (QDir::cleanPath(filename.filePath()) != filename.filePath()) {
|
||||||
nhlog::net()->warn("mxcUrl '{}' is not safe, not downloading file", url);
|
nhlog::net()->warn("mxcUrl '{}' is not safe, not downloading file", url);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,10 +96,12 @@ MxcMediaProxy::startDownload(bool onlyCached)
|
||||||
|
|
||||||
const auto url = mxcUrl.toStdString();
|
const auto url = mxcUrl.toStdString();
|
||||||
const auto name = QString(mxcUrl).remove(QStringLiteral("mxc://"));
|
const auto name = QString(mxcUrl).remove(QStringLiteral("mxc://"));
|
||||||
QFileInfo filename(
|
QFileInfo filename(QStringLiteral("%1/media_cache/media/%2.%3")
|
||||||
QStringLiteral("%1/media_cache/media/%2.%3")
|
.arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation),
|
||||||
.arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation), name, suffix));
|
QString::fromUtf8(name.toUtf8().toBase64(
|
||||||
if (QDir::cleanPath(name) != name) {
|
QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals)),
|
||||||
|
suffix));
|
||||||
|
if (QDir::cleanPath(filename.filePath()) != filename.filePath()) {
|
||||||
nhlog::net()->warn("mxcUrl '{}' is not safe, not downloading file", url);
|
nhlog::net()->warn("mxcUrl '{}' is not safe, not downloading file", url);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue