Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F140343
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/kazv-io-manager.cpp b/src/kazv-io-manager.cpp
index ea8a74f..68f1651 100644
--- a/src/kazv-io-manager.cpp
+++ b/src/kazv-io-manager.cpp
@@ -1,110 +1,110 @@
/*
* This file is part of kazv.
* SPDX-FileCopyrightText: 2022 nannanko <nannanko@kazv.moe>
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include "kazv-io-manager.hpp"
#include "kazv-io-job.hpp"
#include "matrix-room.hpp"
#include "upload-job-model.hpp"
#include <api/csapi/content-repo.hpp>
#include <file-desc.hpp>
#include <QObject>
#include <QIODevice>
#include <QFile>
#include <QSaveFile>
#include <QPointer>
#include <QSharedPointer>
#include <QUrl>
#include <QMap>
#include <QMultiMap>
#include <string>
struct KazvIOManagerPrivate
{
QMap<QString, QPointer<KazvIODownloadJob>> downloadJobs;
QMap<QString, QPointer<UploadJobModel>> uploadJobs;
};
KazvIOManager::KazvIOManager(QObject *parent)
: QObject(parent)
, m_d(new KazvIOManagerPrivate)
{
}
KazvIOManager::~KazvIOManager() = default;
KazvIOBaseJob *KazvIOManager::startNewDownloadJob(const QUrl &serverUrl, const QUrl &localFileUrl, const QString &jobId)
{
auto downloadJob = QPointer<KazvIODownloadJob>(new KazvIODownloadJob());
+ downloadJob->setFile(new QSaveFile(localFileUrl.path()));
downloadJob->setJob(KIO::get(serverUrl));
- downloadJob->setFile(new QSaveFile(localFileUrl.path(), downloadJob.data()));
m_d->downloadJobs[jobId] = downloadJob;
return downloadJob.data();
}
KazvIOBaseJob *KazvIOManager::startNewUploadJob(const QUrl &serverUrl, const QUrl &localFileUrl, const QString &token, const QString &roomId, MatrixRoomList *roomList)
{
auto uploadJob = QPointer<KazvIOUploadJob>(new KazvIOUploadJob());
- uploadJob->setFile(new QFile(localFileUrl.path(), uploadJob.data()));
+ uploadJob->setFile(new QFile(localFileUrl.path()));
auto kazvUploadJob = Kazv::Api::UploadContentJob(serverUrl.toString().toStdString(), token.toStdString(), Kazv::FileDesc(std::string()));
uploadJob->setJob(KIO::http_post(QString(kazvUploadJob.url().data()), uploadJob->file().data()));
uploadJob->job()->addMetaData(QString("content-type") , QMimeDatabase().mimeTypeForFile(localFileUrl.path()).name());
uploadJob->job()->addMetaData("customHTTPHeader", QStringLiteral("Authorization: ").append(kazvUploadJob.requestHeader()->at("Authorization").data()));
uploadJob->job()->addMetaData("PropagateHttpHeader", "true");
uploadJob->setRoom(roomList->room(roomId));
uploadJob->setLocalFileUrl(localFileUrl);
connect(uploadJob.data(), &KazvIOBaseJob::result, this, [this, roomId, uploadJob](KazvIOBaseJob::ErrorCode ec) {
if (!ec) {
m_d->uploadJobs[roomId]->removeJob(uploadJob);
}
});
if (!m_d->uploadJobs.contains(roomId) || m_d->uploadJobs[roomId].isNull()) {
m_d->uploadJobs[roomId] = new UploadJobModel(this);
}
m_d->uploadJobs[roomId]->addJob(uploadJob);
return uploadJob.data();
}
KazvIOBaseJob *KazvIOManager::getDownloadJob(const QString &jobId)
{
auto targetJob = m_d->downloadJobs.find(jobId);
if (targetJob == m_d->downloadJobs.end()) {
return nullptr;
}
return targetJob.value().data();
}
void KazvIOManager::deleteDownloadJob(const QString &jobId)
{
m_d->downloadJobs[jobId]->deleteLater();
m_d->downloadJobs.remove(jobId);
}
UploadJobModel *KazvIOManager::getUploadJobs(const QString &roomId)
{
if (!m_d->uploadJobs.contains(roomId) || m_d->uploadJobs[roomId].isNull()) {
m_d->uploadJobs[roomId] = new UploadJobModel(this);
}
return m_d->uploadJobs[roomId].data();
}
void KazvIOManager::deleteUploadJob(const QString &roomId, KazvIOBaseJob *job)
{
m_d->uploadJobs[roomId]->removeJob(QPointer<KazvIOUploadJob>(qobject_cast<KazvIOUploadJob*>(job)));
}
void KazvIOManager::deleteModelIfEmpty(const QString &roomId)
{
if (!m_d->uploadJobs.contains(roomId)) {
return;
} else if (m_d->uploadJobs[roomId]->rowCount() == 0) {
auto job = m_d->uploadJobs[roomId];
m_d->uploadJobs.remove(roomId);
job->deleteLater();
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 6:36 PM (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55378
Default Alt Text
(4 KB)
Attached To
Mode
rK kazv
Attached
Detach File
Event Timeline
Log In to Comment