main
karlis 2023-07-06 21:50:55 +08:00
commit 83c05d97c5
13 changed files with 385 additions and 154 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

@ -4,6 +4,7 @@ import QtQuick.Window
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Controls.Basic import QtQuick.Controls.Basic
import FluentUI import FluentUI
import SignalFileOperation 1.0
import org.wangwenx190.FramelessHelper import org.wangwenx190.FramelessHelper
import "qrc:///AicsKnowledgeBase/qml/global" import "qrc:///AicsKnowledgeBase/qml/global"
import "qrc:///AicsKnowledgeBase/qml/page" import "qrc:///AicsKnowledgeBase/qml/page"
@ -17,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
@ -54,16 +56,92 @@ FluWindow {
} }
} }
StackView {
ContentPage { id: stack_view
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" pushEnter: Transition {
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
} }
Connections {
target: SignalFileOperation
function onOpen(file) {
stack_view.clear()
stack_view.push(file_view, {knowledgeFileId: file})
}
function onOpenNote(note) {
stack_view.push(note_view, {
"noteFileId": note
})
}
function onBack() {
if (stack_view.depth > 0)
stack_view.pop()
}
}
Component {
id: file_view
ContentPage {}
}
Component {
id: note_view
NotePage {}
}
Component {
id: create_note_view
CreateNotePage {
}
}
// ContentPage {
// Layout.fillHeight: true
// Layout.fillWidth: true
// Layout.topMargin: 45
// Layout.bottomMargin: 4
// Layout.rightMargin: 4
// type: "md"
// }
/* /*
FluArea { FluArea {

View File

@ -34,12 +34,12 @@ FluButton {
implicitWidth: Window.window == null ? 400 : Math.min( implicitWidth: Window.window == null ? 400 : Math.min(
Window.window.width, 400) Window.window.width, 400)
implicitHeight: text_title.height + text_message.height + layout_actions.height implicitHeight: text_title.height + content.height + layout_actions.height
color: 'transparent' color: 'transparent'
radius: 5 radius: 5
FluText { FluText {
id: text_title id: text_title
font: FluTextStyle.TitleLarge font: FluTextStyle.Title
text: "上传知识文件" text: "上传知识文件"
topPadding: 20 topPadding: 20
leftPadding: 20 leftPadding: 20
@ -51,11 +51,9 @@ FluButton {
right: parent.right right: parent.right
} }
} }
FluText {
id: text_message Row {
font: FluTextStyle.Body id: content
wrapMode: Text.WrapAnywhere
text: "content"
topPadding: 14 topPadding: 14
leftPadding: 20 leftPadding: 20
rightPadding: 20 rightPadding: 20
@ -65,7 +63,13 @@ FluButton {
left: parent.left left: parent.left
right: parent.right right: parent.right
} }
FluMultilineTextBox {
id: brief_textbox
width: parent.width - parent.leftPadding - parent.rightPadding
placeholderText: "请输入简介"
}
} }
Rectangle { Rectangle {
id: layout_actions id: layout_actions
height: 68 height: 68
@ -76,7 +80,7 @@ FluButton {
243 / 255, 243 / 255, 243 / 255, 243 / 255, 243 / 255, 243 / 255,
blurBackground ? blurOpacity - 0.4 : 1) blurBackground ? blurOpacity - 0.4 : 1)
anchors { anchors {
top: text_message.bottom top: content.bottom
left: parent.left left: parent.left
right: parent.right right: parent.right
} }
@ -113,7 +117,7 @@ FluButton {
return return
var body = { var body = {
"name": name, "name": name,
"brief": "brief", "brief": brief_textbox.text,
"size": size, "size": size,
"md5": md5, "md5": md5,
"tags": [], "tags": [],

View File

@ -5,4 +5,5 @@ import QtQuick
QtObject { QtObject {
signal open(string file) signal open(string file)
signal openNote(string note) signal openNote(string note)
signal back()
} }

View File

@ -0,0 +1,8 @@
pragma Singleton
import QtQuick
QtObject {
property string username
property string userId
}

View File

@ -1,3 +1,4 @@
singleton NavItems 1.0 NavItems.qml singleton NavItems 1.0 NavItems.qml
singleton FooterItems 1.0 FooterItems.qml singleton FooterItems 1.0 FooterItems.qml
singleton Request 1.0 Request.qml singleton Request 1.0 Request.qml
singleton UserData 1.0 UserData.qml

View File

@ -29,7 +29,7 @@ FluArea {
NoteList { NoteList {
id: noteList id: noteList
onOpen: function handle(noteId) { onOpen: function handle(noteId) {
console.log("open note: " + noteId) emit: SignalFileOperation.openNote(noteId)
} }
onCreateNote: function handle() { onCreateNote: function handle() {
console.log("create note") console.log("create note")
@ -40,26 +40,20 @@ FluArea {
id: content_area id: content_area
paddings: 0 paddings: 0
backgroundColor: "#f9f9f9" backgroundColor: "#f9f9f9"
visible: false // visible: false
property string type: "" property string type: ""
property string knowledgeFileId property string knowledgeFileId
signal back
signal download(string knowledgeFileId) signal download(string knowledgeFileId)
signal clickTags(string tagName) signal clickTags(string tagName)
// paddings: { // paddings: {
// top: 10 // top: 10
// right: 0 // right: 0
// bottom: 10 // bottom: 10
// left: 10 // left: 10
// } // }
Connections {
target: SignalFileOperation
function onOpen(file) {
content_area.visible = true
content_page.loadFile(file)
}
}
FluScrollablePage { FluScrollablePage {
id: content_page id: content_page
anchors.fill: parent anchors.fill: parent
@ -69,6 +63,7 @@ FluArea {
bottomPadding: 0 bottomPadding: 0
property string fileId property string fileId
property int noteCount: 0
property int favoriteCount: 0 property int favoriteCount: 0
property int shareCount: 0 property int shareCount: 0
property int browsCount: 555 property int browsCount: 555
@ -77,50 +72,77 @@ FluArea {
property double fileSize: 455 property double fileSize: 455
property string title: "文章标题" property string title: "文章标题"
property list<string> tags: ["tag 1", "tag 2", "tag 3"] property list<string> tags: ["tag 1", "tag 2", "tag 3"]
property string publishTime: "2020-01-01" property var publishTime
property string brief: "这是一个简介" property string brief: "这是一个简介"
function getType(suffix) { function getType(suffix) {
if(suffix === "md") if (suffix === "md")
return "MD" return "MD"
else if(suffix === "mp4" || suffix === "avi" else if (suffix === "mp4" || suffix === "avi" || suffix === "rmvb"
|| suffix === "rmvb" || suffix === "rm" || suffix === "rm" || suffix === "wmv" || suffix === "mkv")
|| suffix === "wmv" || suffix === "mkv")
return "VIDEO" return "VIDEO"
else return "OTHER" else
return "OTHER"
} }
function loadFile(knowledgeFileId) { function loadFile(knowledgeFileId) {
content_area.knowledgeFileId = knowledgeFileId content_area.knowledgeFileId = knowledgeFileId
console.log(knowledgeFileId) console.log(knowledgeFileId)
Request.get("knowledge/" + knowledgeFileId, function (response, data) { Request.get("knowledge/" + knowledgeFileId,
content_page.publishTime = data.createTime function (response, data) {
content_page.title = data.name content_page.publishTime = data.createTime
content_page.fileId = data.knowledgeFileAttribute.id content_page.title = data.name
content_page.fileId = data.knowledgeFileAttribute.id
content_area.type = data.knowledgeFileAttribute.suffix content_area.type = data.knowledgeFileAttribute.suffix
var tagString = "" var tagString = ""
for (var j = 0; j < data.knowledgeFileAttribute.tags.length; j++) { for (var j = 0; j < data.knowledgeFileAttribute.tags.length; j++) {
if (j != 0) if (j != 0)
tagString = tagString + "," tagString = tagString + ","
tagString = tagString + data.knowledgeFileAttribute.tags[j].name tagString = tagString + data.knowledgeFileAttribute.tags[j].name
} }
content_page.tags = tagString.split(",") content_page.tags = tagString.split(",")
content_page.brief = data.knowledgeFileAttribute.brief content_page.brief = data.knowledgeFileAttribute.brief
content_page.browsCount = data.knowledgeFileAttribute.pageView content_page.browsCount = data.knowledgeFileAttribute.pageView
var starers = data.knowledgeFileAttribute.starers // var starers = data.knowledgeFileAttribute.starers
for(var i=0; i<starers.length; i++) { // for (var i = 0; i < starers.length; i++) {
} // }
content_page.favoriteCount = starers.length // content_page.favoriteCount = starers.length
}) if (content_area.type === "MD") {
FileTransferManager.getMarkdown(content_page.fileId)
} else if (content_area.type === "VIDEO") {
} else {
Request.get("knowledge/" + knowledgeFileId + "/preview/external",
function (res) {
content_view.push(other_view, {
"url": res
})
})
}
})
} }
Component.onCompleted: { Connections {
target: FileTransferManager
onMarkdownData: data => {
content_view.push(text_view, {contentMd: data})
}
}
Component.onCompleted: {
loadFile(knowledgeFileId)
console.log(content_area.type)
}
FluText {
font.pointSize: 12
Layout.margins: -5
} }
Item { Item {
@ -130,7 +152,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
@ -148,7 +170,7 @@ FluArea {
} }
} }
FluText { FluText {
text: "" text: content_page.noteCount
font.pointSize: 8 font.pointSize: 8
Layout.alignment: button_note.Center Layout.alignment: button_note.Center
Layout.topMargin: -5 Layout.topMargin: -5
@ -208,8 +230,11 @@ FluArea {
} }
onClicked: { onClicked: {
emit: content_area.download(content_area.knowledgeFileId) emit: content_area.download(content_area.knowledgeFileId)
FileTransferManager.download(content_area.knowledgeFileId) //FileTransferManager.getMarkdown(content_page.fileId)
FileTransferManager.download(content_page.fileId,
content_page.title)
} }
} }
} }
@ -260,16 +285,24 @@ FluArea {
} }
} }
Loader { // WebEngineView {
// Layout.fillWidth: true
// backgroundColor: "transparent"
// implicitHeight: 200
// settings.javascriptEnabled: true
// settings.pluginsEnabled: true
// url: "https://www.baidu.com"
// }
StackView {
id: content_view id: content_view
Layout.fillWidth: true Layout.fillWidth: true
sourceComponent: video_view height: width*10/16
} }
Component { Component {
id: video_view id: video_view
FluMediaPlayer { FluMediaPlayer {
Layout.fillWidth: true width: parent.width
implicitHeight: width * 9 / 16. implicitHeight: width * 9 / 16.
} }
} }
@ -277,15 +310,14 @@ FluArea {
id: text_view id: text_view
NoteEditPage { NoteEditPage {
noteId: "255454" noteId: "255454"
Layout.fillWidth: true width: parent.width
implicitHeight: 400 height: width*9/16
} }
} }
Component { Component {
id: other_view id: other_view
WebEngineView { WebEngineView {
Layout.fillWidth: true width: parent.width
id: sitemonitory_view
backgroundColor: "transparent" backgroundColor: "transparent"
implicitHeight: 200 implicitHeight: 200
settings.javascriptEnabled: true settings.javascriptEnabled: true

View File

@ -0,0 +1,102 @@
import QtQuick
import QtQuick.Layouts
import QtQuick.Window
import QtQuick.Controls
import QtQuick.Controls.Basic
import QtWebEngine 1.2
import FluentUI
import AicsKB.FileTransferManager
import SignalFileOperation 1.0
import "qrc:///AicsKnowledgeBase/qml/page"
import "qrc:///AicsKnowledgeBase/qml/component"
import "qrc:///AicsKnowledgeBase/qml/global"
FluArea {
id: edit_area
paddings: 0
backgroundColor: "#f9f9f9"
property string noteTitle
property string noteContent
Component.onCompleted: {
noteTitle = Qt.binding(function() {
return input_title.text
})
noteContent = Qt.binding(function() {
return input_md.contentMd
})
}
FluScrollablePage {
id: edit_page
anchors.fill: parent
leftPadding: 5
topPadding: 5
rightPadding: 5
bottomPadding: 0
RowLayout {
FluIconButton {
iconSize: 12
iconSource: FluentIcons.Back
onClicked: {
emit: SignalFileOperation.back()
}
Layout.margins: -5
}
}
Item {
Layout.fillWidth: true
implicitHeight: 50
RowLayout {
Layout.fillWidth: true
FluText {
padding: 10
text: "标题"
font {
pointSize: 15
bold: true
}
}
FluTextBox {
id: input_title
padding: 10
placeholderText:"单行输入框"
implicitWidth: parent.width
}
}
}
FluText {
padding: 10
text: "内容"
font {
pointSize: 15
bold: true
}
}
NoteEditPage {
id: input_md
noteId: "255454"
width: parent.width
height: width*9/16
isEditable: true
}
RowLayout {
Layout.alignment: Qt.AlignCenter
Layout.topMargin: 10
FluFilledButton {
text: "上传"
onClicked: {
console.log(noteTitle)
console.log(noteContent)
}
}
FluButton {
text: "取消"
}
}
}
}

View File

@ -11,6 +11,10 @@ FluArea {
paddings: 0 paddings: 0
backgroundColor: "#f9f9f9" backgroundColor: "#f9f9f9"
property string noteId: "234" property string noteId: "234"
property string contentMd: ""
property bool isEditing: false
property bool isEditable: false
Layout.fillWidth: true
FluScrollablePage { FluScrollablePage {
id: edit_page id: edit_page
@ -20,21 +24,16 @@ FluArea {
rightPadding: 5 rightPadding: 5
bottomPadding: 0 bottomPadding: 0
property string contentMd: "**ssijfdijgo**\ndfdgfdggggggggggggggggggggggggggggggggggggggggggggggggggg"
property bool isEditing: false
property bool isEditable: false
Component.onCompleted: { Component.onCompleted: {
edit_page.isEditable = true
textArea_edit.text = edit_page.contentMd textArea_edit.text = edit_area.contentMd
edit_page.contentMd = Qt.binding( edit_area.contentMd = Qt.binding(
function() { function() {
return textArea_edit.text return textArea_edit.text
}) })
textArea_preview.text = Qt.binding( textArea_preview.text = Qt.binding(
function() { function() {
return edit_page.contentMd return edit_area.contentMd
}) })
} }
@ -46,7 +45,7 @@ FluArea {
id: button_edit id: button_edit
iconSource: FluentIcons.Edit iconSource: FluentIcons.Edit
iconSize: 12 iconSize: 12
visible: edit_page.isEditable visible: edit_area.isEditable
anchors { anchors {
right: parent.right right: parent.right
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
@ -72,7 +71,7 @@ FluArea {
verticalCenter: parent.verticalCenter verticalCenter: parent.verticalCenter
} }
onClicked: { onClicked: {
button_edit.visible = edit_page.isEditable button_edit.visible = edit_area.isEditable
button_save.visible = false button_save.visible = false
button_preview.visible = false button_preview.visible = false
button_subfield.visible = false button_subfield.visible = false
@ -153,7 +152,7 @@ FluArea {
property bool isPreviewShowing: true property bool isPreviewShowing: true
Layout.fillWidth: true Layout.fillWidth: true
implicitHeight: 300 implicitHeight: width * 8/16
ScrollView { ScrollView {
id: edit_show_view id: edit_show_view

View File

@ -8,16 +8,16 @@ import FluentUI
import AicsKB.FileTransferManager import AicsKB.FileTransferManager
import SignalFileOperation 1.0 import SignalFileOperation 1.0
import "qrc:///AicsKnowledgeBase/qml/page" import "qrc:///AicsKnowledgeBase/qml/page"
import "qrc:///AicsKnowledgeBase/qml/component"
import "qrc:///AicsKnowledgeBase/qml/global"
FluArea { FluArea {
id: note_area id: note_area
paddings: 0 paddings: 0
backgroundColor: "#f9f9f9" backgroundColor: "#f9f9f9"
visible: false // visible: false
property string type: "" property string type: ""
property string noteId property string noteFileId
property string isFile: false
property string knowledgeUrl : "aics/main/knowledge/"
signal clickTags(string tagName) signal clickTags(string tagName)
// paddings: { // paddings: {
@ -26,12 +26,6 @@ FluArea {
// bottom: 10 // bottom: 10
// left: 10 // left: 10
// } // }
Connections {
target: SignalFileOperation
function onOpen(file) {
}
}
FluScrollablePage { FluScrollablePage {
id: note_page id: note_page
@ -41,44 +35,45 @@ FluArea {
rightPadding: 10 rightPadding: 10
bottomPadding: 0 bottomPadding: 0
property string fileId
property int likeCount: 0 property int likeCount: 0
property int favoriteCount: 0 property int favoriteCount: 0
property int shareCount: 0 property int shareCount: 0
property int browsCount: 555 property int browsCount: 555
property bool isLike: false property bool isLike: false
property bool isFavorite: false property bool isFavorite: false
property bool isDownload: false
property double fileSize: 455 property double fileSize: 455
property list<string> tags: ["tag1", "tag2", "tag3"] property string title: "文章标题"
property string publishTime: "2002-01-01" property list<string> tags: ["tag 1", "tag 2", "tag 3"]
property string publishTime: "2020-01-01"
property string brief: "这是一个简介" property string brief: "这是一个简介"
function getType(suffix) { function getType(suffix) {
if(suffix === "md") if(suffix === "md")
return "md" return "MD"
else if(suffix === "mp4" || suffix === "avi" || suffix === "rmvb" || suffix === "mkv") else if(suffix === "mp4" || suffix === "avi"
return "video" || suffix === "rmvb" || suffix === "rm"
else return "other" || suffix === "wmv" || suffix === "mkv")
return "VIDEO"
else return "OTHER"
} }
function loadFile(noteId) { function loadNote(noteFileId) {
var fileUrl = knowledgeUrl+noteId note_area.noteFileId = noteFileId
Request.get(fileUrl, function (response) {
var data = JSON.parse(response) }
console.log(data.knowledgeFileAttribute)
publishTime = data.createTime Component.onCompleted: {
type = getType(data.knowledgeFileAttribute.suffix)
brief = data.knowledgeFileAttribute.brief }
fileSize = data.knowledgeFileAttribute.size
browsCount = data.knowledgeFileAttribute.pageView FluIconButton {
var tagString = "" iconSize: 12
for (var j = 0; j < file.knowledgeFileAttribute.tags.length; j++) { iconSource: FluentIcons.Back
if (j != 0) onClicked: {
tagString = tagString + "," emit: SignalFileOperation.back()
tagString = tagString + file.knowledgeFileAttribute.tags[j].name }
} Layout.margins: -5
tags = tagString.split(",")
})
} }
Item { Item {
@ -88,7 +83,7 @@ FluArea {
FluText { FluText {
id: text_title id: text_title
padding: 10 padding: 10
text: "文章标题" text: note_page.title
font { font {
pointSize: 15 pointSize: 15
bold: true bold: true
@ -100,7 +95,7 @@ FluArea {
id: button_share id: button_share
iconSize: 15 iconSize: 15
iconSource: FluentIcons.Share iconSource: FluentIcons.Share
text: content_page.shareCount.toString() text: note_page.shareCount.toString()
} }
FluText { FluText {
id: text_share id: text_share
@ -118,12 +113,8 @@ FluArea {
id: layout_favorite id: layout_favorite
FluIconButton { FluIconButton {
id: button_favorite id: button_favorite
iconSize: 15 iconSize: 15
iconSource: note_page.isFavorite ? FluentIcons.FavoriteStarFill : FluentIcons.FavoriteStar iconSource: note_page.isFavorite ? FluentIcons.FavoriteStarFill : FluentIcons.FavoriteStar
onClicked: {
Request.put()
}
} }
FluText { FluText {
id: text_favorite id: text_favorite
@ -146,7 +137,7 @@ FluArea {
} }
FluText { FluText {
id: text_like id: text_like
text: note_page.favoriteCount text: note_page.likeCount
font.pointSize: 8 font.pointSize: 8
Layout.alignment: button_like.Center Layout.alignment: button_like.Center
Layout.topMargin: -5 Layout.topMargin: -5
@ -156,20 +147,6 @@ FluArea {
right: layout_favorite.left right: layout_favorite.left
} }
} }
FluIconButton {
id: button_download
iconSize: 25
iconSource: note_page.isDownload ? FluentIcons.OEM : FluentIcons.Download
anchors {
verticalCenter: text_title.verticalCenter
right: layout_like.left
rightMargin: 20
}
onClicked: {
emit: content_area.download(content_area.knowledgeFileId)
FileTransferManager.download(content_area.knowledgeFileId)
}
}
} }
FluArea { FluArea {
@ -177,32 +154,33 @@ FluArea {
implicitHeight: 100 implicitHeight: 100
ColumnLayout { ColumnLayout {
RowLayout { RowLayout {
width: parent.width
FluText { FluText {
padding: 10 padding: 10
text: content_page.publishTime text: note_page.publishTime
} }
FluText { FluText {
padding: 10 padding: 10
text: content_page.fileSize.toString() + "MB" text: note_page.fileSize.toString() + "MB"
} }
FluText { FluText {
padding: 10 padding: 10
text: content_page.browsCount.toString() + "浏览量" text: note_page.browsCount.toString() + "浏览量"
} }
} }
FluText { FluText {
Layout.topMargin: -2 Layout.topMargin: -2
Layout.leftMargin: 10 Layout.leftMargin: 10
text: content_page.brief text: note_page.brief
} }
RowLayout { RowLayout {
Layout.topMargin: 2 Layout.topMargin: 2
Layout.leftMargin: 5 Layout.leftMargin: 5
Repeater { Repeater {
model: content_page.tags model: note_page.tags
delegate: Button { delegate: Button {
Layout.margins: 2 Layout.margins: 2
text: "#" + content_page.tags[index] text: "#" + note_page.tags[index]
background: Rectangle { background: Rectangle {
implicitHeight: 10 implicitHeight: 10
implicitWidth: 10 implicitWidth: 10
@ -210,20 +188,18 @@ FluArea {
radius: 10 radius: 10
} }
onClicked: { onClicked: {
emit: content_area.clickTags(text) emit: note_area.clickTags(text)
} }
} }
} }
} }
} }
} }
NoteEditPage { NoteEditPage {
id: md_edit_page id: text_view
noteId: "255454" noteId: "255454"
Layout.fillWidth: true width: parent.width
implicitHeight: 400 implicitHeight: 400
} }
} }
} }

View File

@ -305,7 +305,6 @@ bool httpDownload(const std::string &url, const std::string &savePath, const Fil
return false; return false;
obj.totalSize = item.totalSize;//原始文件大小 obj.totalSize = item.totalSize;//原始文件大小
obj.file = std::ofstream(savePath, std::ios::binary | std::ios::app); obj.file = std::ofstream(savePath, std::ios::binary | std::ios::app);
if (!obj.file.is_open()) { if (!obj.file.is_open()) {
qDebug() << "Open File Failed"; qDebug() << "Open File Failed";
curl_easy_cleanup(obj.curlHandle); curl_easy_cleanup(obj.curlHandle);
@ -348,8 +347,9 @@ void FileTransferManager::download(const QString &fileId, const QString &fileNam
} }
auto size = resJson["size"].toInteger(); auto size = resJson["size"].toInteger();
std::string savePath = "D:\\Downloads\\" + fileName.toStdString(); std::string savePath = "D:\\Downloads\\" + fileName.toLocal8Bit().toStdString();
QFileInfo fileInfo(savePath.c_str()); qDebug() << savePath.c_str();
QFileInfo fileInfo(QString::fromLocal8Bit(savePath.c_str()));
int64_t completedSize = fileInfo.exists() ? fileInfo.size() : 0; int64_t completedSize = fileInfo.exists() ? fileInfo.size() : 0;
FileItem item{true, fileId, fileName, completedSize, size}; FileItem item{true, fileId, fileName, completedSize, size};
if (!resume) if (!resume)
@ -359,14 +359,8 @@ void FileTransferManager::download(const QString &fileId, const QString &fileNam
auto fileUrl = std::format("File/{}?rangeStart={}&rangeEnd={}", fileId.toStdString(), completedSize, size); auto fileUrl = std::format("File/{}?rangeStart={}&rangeEnd={}", fileId.toStdString(), completedSize, size);
auto res = httpDownload(fileUrl, savePath, item); auto res = httpDownload(fileUrl, savePath, item);
/*auto fileUrl = std::format("File/{}?rangeStart={}&rangeEnd={}", fileId.toStdString(), 0, size / 2);
auto res = httpDownload(fileUrl, savePath, item);
fileUrl = std::format("File/{}?rangeStart={}&rangeEnd={}", fileId.toStdString(), size / 2, size);
res = httpDownload(fileUrl, savePath, item);*/
qDebug() << "End Get" << res; qDebug() << "End Get" << res;
}); });
} }
void FileTransferManager::pause(const QString &fileId) void FileTransferManager::pause(const QString &fileId)
@ -403,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:
}; };

View File

@ -62,7 +62,7 @@ int main(int argc, char *argv[])
&app, [url](QObject *obj, const QUrl &objUrl) { &app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl) if (!obj && url == objUrl)
QCoreApplication::exit(-1); QCoreApplication::exit(-1);
}, Qt::QueuedConnection); }, Qt::QueuedConnection);
engine.load(url); engine.load(url);
auto result = QGuiApplication::exec(); auto result = QGuiApplication::exec();
httpClient->deleteLater(); httpClient->deleteLater();