forked from Shinonome/dots-hyprland
BooruImage: refractor image downloader proc
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
import QtQuick
|
||||||
|
import Quickshell
|
||||||
|
import Quickshell.Io
|
||||||
|
import qs.modules.common
|
||||||
|
import qs.modules.common.functions
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
signal done(string path, int width, int height);
|
||||||
|
required property string filePath;
|
||||||
|
required property string sourceUrl;
|
||||||
|
property string downloadUserAgent: Config.options?.networking.userAgent ?? ""
|
||||||
|
|
||||||
|
function processFilePath() {
|
||||||
|
return StringUtils.shellSingleQuoteEscape(FileUtils.trimFileProtocol(filePath));
|
||||||
|
}
|
||||||
|
|
||||||
|
running: true
|
||||||
|
command: ["bash", "-c",
|
||||||
|
`mkdir -p $(dirname '${processFilePath(filePath)}'); [ -f '${processFilePath(filePath)}' ] || curl -sSL '${sourceUrl}' -o '${processFilePath(filePath)}' && magick identify -format '%w %h' '${processFilePath(filePath)}'[0]`
|
||||||
|
]
|
||||||
|
stdout: StdioCollector {
|
||||||
|
id: imageSizeOutputCollector
|
||||||
|
onStreamFinished: {
|
||||||
|
const output = imageSizeOutputCollector.text.trim();
|
||||||
|
const [width, height] = output.split(" ").map(Number);
|
||||||
|
root.done(root.filePath, width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
import qs.services
|
import qs.services
|
||||||
import qs.modules.common
|
import qs.modules.common
|
||||||
import qs.modules.common.widgets
|
|
||||||
import qs.modules.common.functions
|
import qs.modules.common.functions
|
||||||
|
import qs.modules.common.utils
|
||||||
|
import qs.modules.common.widgets
|
||||||
import QtQml
|
import QtQml
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
@@ -25,18 +26,19 @@ Button {
|
|||||||
property real imageRadius: Appearance.rounding.small
|
property real imageRadius: Appearance.rounding.small
|
||||||
|
|
||||||
property bool showActions: false
|
property bool showActions: false
|
||||||
Process {
|
ImageDownloaderProcess {
|
||||||
id: downloadProcess
|
id: imageDownloader
|
||||||
running: false
|
running: root.manualDownload
|
||||||
command: ["bash", "-c", `mkdir -p '${root.previewDownloadPath}' && [ -f ${root.filePath} ] || curl -sSL '${root.imageData.preview_url ?? root.imageData.sample_url}' -o '${root.filePath}'`]
|
filePath: root.filePath
|
||||||
onExited: (exitCode, exitStatus) => {
|
sourceUrl: root.imageData.preview_url ?? root.imageData.sample_url
|
||||||
imageObject.source = `${previewDownloadPath}/${root.fileName}`
|
onDone: (path, width, height) => {
|
||||||
}
|
imageObject.source = ""
|
||||||
}
|
imageObject.source = path
|
||||||
|
if (!modelData.width || !modelData.height) {
|
||||||
Component.onCompleted: {
|
modelData.width = width
|
||||||
if (root.manualDownload) {
|
modelData.height = height
|
||||||
downloadProcess.running = true
|
modelData.aspect_ratio = width / height
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user