MCPcopy Create free account
hub / github.com/Palm1r/QodeAssist / saveContentToStorage

Method saveContentToStorage

ChatView/ChatSerializer.cpp:261–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

259}
260
261bool ChatSerializer::saveContentToStorage(
262 const QString &chatFilePath,
263 const QString &fileName,
264 const QString &base64Data,
265 QString &storedPath)
266{
267 QString contentFolder = getChatContentFolder(chatFilePath);
268 QDir dir;
269 if (!dir.exists(contentFolder)) {
270 if (!dir.mkpath(contentFolder)) {
271 LOG_MESSAGE(QString("Failed to create content folder: %1").arg(contentFolder));
272 return false;
273 }
274 }
275
276 QFileInfo originalFileInfo(fileName);
277 QString extension = originalFileInfo.suffix();
278 QString baseName = originalFileInfo.completeBaseName();
279 QString uniqueName = QString("%1_%2.%3")
280 .arg(baseName)
281 .arg(QUuid::createUuid().toString(QUuid::WithoutBraces).left(8))
282 .arg(extension);
283
284 QString fullPath = QDir(contentFolder).filePath(uniqueName);
285
286 QByteArray contentData = QByteArray::fromBase64(base64Data.toUtf8());
287 QFile file(fullPath);
288 if (!file.open(QIODevice::WriteOnly)) {
289 LOG_MESSAGE(QString("Failed to open file for writing: %1").arg(fullPath));
290 return false;
291 }
292
293 if (file.write(contentData) == -1) {
294 LOG_MESSAGE(QString("Failed to write content data: %1").arg(file.errorString()));
295 return false;
296 }
297
298 file.close();
299
300 storedPath = uniqueName;
301 LOG_MESSAGE(QString("Saved content: %1 to %2").arg(fileName, fullPath));
302
303 return true;
304}
305
306QString ChatSerializer::loadContentFromStorage(const QString &chatFilePath, const QString &storedPath)
307{

Callers

nothing calls this directly

Calls 3

toUtf8Method · 0.80
toStringMethod · 0.45
filePathMethod · 0.45

Tested by

no test coverage detected