实现获取Markdown文件内容的方法

main
wuyize 2023-07-06 21:16:03 +08:00
parent 604203047c
commit 8bd68cb3ec
5 changed files with 101 additions and 27 deletions

View File

@ -103,6 +103,8 @@ AppFluWindow {
function (result, data) { function (result, data) {
console.log(result) console.log(result)
console.log(data) console.log(data)
UserData.username = param.username
FluApp.navigate("/") FluApp.navigate("/")
window.close() window.close()
}, function (p1, p2) { }, function (p1, p2) {

View File

@ -18,6 +18,7 @@ FluWindow {
CustomAppBar { CustomAppBar {
id: title_bar id: title_bar
title: window.title title: window.title
username: UserData.username
anchors { anchors {
left: parent.left left: parent.left
@ -62,37 +63,67 @@ FluWindow {
Layout.topMargin: 45 Layout.topMargin: 45
Layout.bottomMargin: 4 Layout.bottomMargin: 4
Layout.rightMargin: 4 Layout.rightMargin: 4
replaceEnter: null pushEnter: Transition {
replaceExit: null PropertyAnimation {
property: "opacity"
from: 0
to: 1
duration: 200
}
}
pushExit: Transition {
PropertyAnimation {
property: "opacity"
from: 1
to: 0
duration: 200
}
}
popEnter: Transition {
PropertyAnimation {
property: "opacity"
from: 0
to: 1
duration: 200
}
}
popExit: Transition {
PropertyAnimation {
property: "opacity"
from: 1
to: 0
duration: 200
}
}
initialItem: create_note_view initialItem: create_note_view
} }
Connections { Connections {
target: SignalFileOperation target: SignalFileOperation
function onOpen(file) { function onOpen(file) {
stack_view.push(file_view, {knowledgeFileId: file}) stack_view.push(file_view, {
"knowledgeFileId": file
})
} }
function onOpenNote(note) { function onOpenNote(note) {
stack_view.push(note_view, {noteFileId: note}) stack_view.push(note_view, {
"noteFileId": note
})
} }
function onBack() { function onBack() {
if(stack_view.depth > 0) if (stack_view.depth > 0)
stack_view.pop() stack_view.pop()
} }
} }
Component { Component {
id: file_view id: file_view
ContentPage { ContentPage {}
}
} }
Component { Component {
id: note_view id: note_view
NotePage { NotePage {}
}
} }
Component { Component {
@ -103,14 +134,14 @@ FluWindow {
} }
// ContentPage { // ContentPage {
// Layout.fillHeight: true // Layout.fillHeight: true
// Layout.fillWidth: true // Layout.fillWidth: true
// Layout.topMargin: 45 // Layout.topMargin: 45
// Layout.bottomMargin: 4 // Layout.bottomMargin: 4
// Layout.rightMargin: 4 // Layout.rightMargin: 4
// type: "md" // type: "md"
// } // }
/* /*

View File

@ -147,7 +147,7 @@ FluArea {
FluText { FluText {
id: text_title id: text_title
padding: 10 padding: 10
text: content_page.title text: content_page.title.split(".")[0]
font { font {
pointSize: 15 pointSize: 15
bold: true bold: true
@ -225,9 +225,16 @@ FluArea {
} }
onClicked: { onClicked: {
emit: content_area.download(content_area.knowledgeFileId) emit: content_area.download(content_area.knowledgeFileId)
//FileTransferManager.getMarkdown(content_page.fileId)
FileTransferManager.download(content_page.fileId, FileTransferManager.download(content_page.fileId,
content_page.title) content_page.title)
} }
// Connections {
// target: FileTransferManager
// onMarkdownData: data => {
// console.log(data)
// }
// }
} }
} }

View File

@ -397,3 +397,30 @@ QString FileTransferManager::getFileName(const QUrl &fileUrl)
return fileUrl.fileName(); return fileUrl.fileName();
} }
void FileTransferManager::getMarkdown(const QString &fileId)
{
QtConcurrent::run([fileId, this] {
qDebug() << "Start Get";
std::string resData;
if (CURLE_OK != httpGet("File/" + fileId.toStdString() + "/status", resData))
return;
qDebug() << resData.c_str();
auto resJson = QJsonDocument::fromJson(resData.c_str());
if (!resJson["isCompleted"].toBool()) {
qDebug() << "File Not Completed";
return;
}
auto size = resJson["size"].toInteger();
auto fileUrl = std::format("File/{}?rangeStart={}&rangeEnd={}", fileId.toStdString(), 0, size);
std::string fileData;
auto res = httpGet(fileUrl, fileData);
//qDebug() << fileData.c_str();
emit markdownData(QString::fromStdString(fileData));
//qDebug() << "End Get" << res;
});
}

View File

@ -12,21 +12,28 @@
#include "FileTransferListModel.h" #include "FileTransferListModel.h"
class FileTransferManager : public QObject class FileTransferManager : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit FileTransferManager(QObject *parent = nullptr); explicit FileTransferManager(QObject *parent = nullptr);
Q_INVOKABLE QString getFileName(const QUrl& fileUrl); Q_INVOKABLE QString getFileName(const QUrl &fileUrl);
Q_INVOKABLE int64_t getFileSize(const QUrl& fileUrl);
Q_INVOKABLE QString getFileMd5(const QUrl& fileUrl);
Q_INVOKABLE void upload(const QUrl& fileUrl, const QString& fileId, const QString& ticket, const QString &fileName);
Q_INVOKABLE void download(const QString& fileId, const QString& fileName, bool resume = false); Q_INVOKABLE int64_t getFileSize(const QUrl &fileUrl);
Q_INVOKABLE void pause(const QString& fileId);
Q_INVOKABLE QString getFileMd5(const QUrl &fileUrl);
Q_INVOKABLE void upload(const QUrl &fileUrl, const QString &fileId, const QString &ticket, const QString &fileName);
Q_INVOKABLE void download(const QString &fileId, const QString &fileName, bool resume = false);
Q_INVOKABLE void pause(const QString &fileId);
Q_INVOKABLE void getMarkdown(const QString &fileId);
signals:
void markdownData(QString data);
private: private:
}; };