mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2026-02-18 21:13:04 -05:00
fix: Create _content folder only when there is an attachment (#297)
This commit is contained in:
@ -38,14 +38,6 @@ SerializationResult ChatSerializer::saveToFile(const ChatModel *model, const QSt
|
|||||||
return {false, "Failed to create directory structure"};
|
return {false, "Failed to create directory structure"};
|
||||||
}
|
}
|
||||||
|
|
||||||
QString contentFolder = getChatContentFolder(filePath);
|
|
||||||
QDir dir;
|
|
||||||
if (!dir.exists(contentFolder)) {
|
|
||||||
if (!dir.mkpath(contentFolder)) {
|
|
||||||
LOG_MESSAGE(QString("Warning: Failed to create content folder: %1").arg(contentFolder));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile file(filePath);
|
QFile file(filePath);
|
||||||
if (!file.open(QIODevice::WriteOnly)) {
|
if (!file.open(QIODevice::WriteOnly)) {
|
||||||
return {false, QString("Failed to open file for writing: %1").arg(filePath)};
|
return {false, QString("Failed to open file for writing: %1").arg(filePath)};
|
||||||
@ -88,7 +80,8 @@ SerializationResult ChatSerializer::loadFromFile(ChatModel *model, const QString
|
|||||||
return {true, QString()};
|
return {true, QString()};
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonObject ChatSerializer::serializeMessage(const ChatModel::Message &message, const QString &chatFilePath)
|
QJsonObject ChatSerializer::serializeMessage(
|
||||||
|
const ChatModel::Message &message, const QString &chatFilePath)
|
||||||
{
|
{
|
||||||
QJsonObject messageObj;
|
QJsonObject messageObj;
|
||||||
messageObj["role"] = static_cast<int>(message.role);
|
messageObj["role"] = static_cast<int>(message.role);
|
||||||
@ -129,7 +122,8 @@ QJsonObject ChatSerializer::serializeMessage(const ChatModel::Message &message,
|
|||||||
return messageObj;
|
return messageObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatModel::Message ChatSerializer::deserializeMessage(const QJsonObject &json, const QString &chatFilePath)
|
ChatModel::Message ChatSerializer::deserializeMessage(
|
||||||
|
const QJsonObject &json, const QString &chatFilePath)
|
||||||
{
|
{
|
||||||
ChatModel::Message message;
|
ChatModel::Message message;
|
||||||
message.role = static_cast<ChatModel::ChatRole>(json["role"].toInt());
|
message.role = static_cast<ChatModel::ChatRole>(json["role"].toInt());
|
||||||
@ -178,7 +172,8 @@ QJsonObject ChatSerializer::serializeChat(const ChatModel *model, const QString
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatSerializer::deserializeChat(ChatModel *model, const QJsonObject &json, const QString &chatFilePath)
|
bool ChatSerializer::deserializeChat(
|
||||||
|
ChatModel *model, const QJsonObject &json, const QString &chatFilePath)
|
||||||
{
|
{
|
||||||
QJsonArray messagesArray = json["messages"].toArray();
|
QJsonArray messagesArray = json["messages"].toArray();
|
||||||
QVector<ChatModel::Message> messages;
|
QVector<ChatModel::Message> messages;
|
||||||
@ -193,7 +188,14 @@ bool ChatSerializer::deserializeChat(ChatModel *model, const QJsonObject &json,
|
|||||||
model->setLoadingFromHistory(true);
|
model->setLoadingFromHistory(true);
|
||||||
|
|
||||||
for (const auto &message : messages) {
|
for (const auto &message : messages) {
|
||||||
model->addMessage(message.content, message.role, message.id, message.attachments, message.images, message.isRedacted, message.signature);
|
model->addMessage(
|
||||||
|
message.content,
|
||||||
|
message.role,
|
||||||
|
message.id,
|
||||||
|
message.attachments,
|
||||||
|
message.images,
|
||||||
|
message.isRedacted,
|
||||||
|
message.signature);
|
||||||
LOG_MESSAGE(QString("Loaded message with %1 image(s), isRedacted=%2, signature length=%3")
|
LOG_MESSAGE(QString("Loaded message with %1 image(s), isRedacted=%2, signature length=%3")
|
||||||
.arg(message.images.size())
|
.arg(message.images.size())
|
||||||
.arg(message.isRedacted)
|
.arg(message.isRedacted)
|
||||||
@ -219,7 +221,9 @@ bool ChatSerializer::validateVersion(const QString &version)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (version == "0.1") {
|
if (version == "0.1") {
|
||||||
LOG_MESSAGE("Loading chat from old format 0.1 - images folder structure has changed from _images to _content");
|
LOG_MESSAGE(
|
||||||
|
"Loading chat from old format 0.1 - images folder structure has changed from _images "
|
||||||
|
"to _content");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,10 +238,11 @@ QString ChatSerializer::getChatContentFolder(const QString &chatFilePath)
|
|||||||
return QDir(dirPath).filePath(baseName + "_content");
|
return QDir(dirPath).filePath(baseName + "_content");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ChatSerializer::saveContentToStorage(const QString &chatFilePath,
|
bool ChatSerializer::saveContentToStorage(
|
||||||
const QString &fileName,
|
const QString &chatFilePath,
|
||||||
const QString &base64Data,
|
const QString &fileName,
|
||||||
QString &storedPath)
|
const QString &base64Data,
|
||||||
|
QString &storedPath)
|
||||||
{
|
{
|
||||||
QString contentFolder = getChatContentFolder(chatFilePath);
|
QString contentFolder = getChatContentFolder(chatFilePath);
|
||||||
QDir dir;
|
QDir dir;
|
||||||
@ -252,9 +257,9 @@ bool ChatSerializer::saveContentToStorage(const QString &chatFilePath,
|
|||||||
QString extension = originalFileInfo.suffix();
|
QString extension = originalFileInfo.suffix();
|
||||||
QString baseName = originalFileInfo.completeBaseName();
|
QString baseName = originalFileInfo.completeBaseName();
|
||||||
QString uniqueName = QString("%1_%2.%3")
|
QString uniqueName = QString("%1_%2.%3")
|
||||||
.arg(baseName)
|
.arg(baseName)
|
||||||
.arg(QUuid::createUuid().toString(QUuid::WithoutBraces).left(8))
|
.arg(QUuid::createUuid().toString(QUuid::WithoutBraces).left(8))
|
||||||
.arg(extension);
|
.arg(extension);
|
||||||
|
|
||||||
QString fullPath = QDir(contentFolder).filePath(uniqueName);
|
QString fullPath = QDir(contentFolder).filePath(uniqueName);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user