diff --git a/dots/.config/quickshell/ii/modules/common/utils/ImageDownloaderProcess.qml b/dots/.config/quickshell/ii/modules/common/utils/ImageDownloaderProcess.qml index 3a86b2fe1..37276378e 100644 --- a/dots/.config/quickshell/ii/modules/common/utils/ImageDownloaderProcess.qml +++ b/dots/.config/quickshell/ii/modules/common/utils/ImageDownloaderProcess.qml @@ -16,9 +16,20 @@ Process { return StringUtils.shellSingleQuoteEscape(FileUtils.trimFileProtocol(filePath)); } + function processSourceUrl() { + return StringUtils.shellSingleQuoteEscape(sourceUrl); + } + + function curlUserAgentArg() { + if (!downloadUserAgent) { + return ""; + } + return ` -H 'User-Agent: ${StringUtils.shellSingleQuoteEscape(downloadUserAgent)}'`; + } + running: true command: ["bash", "-c", - `mkdir -p $(dirname '${processFilePath()}'); [ -f '${processFilePath()}' ] || curl -sSL '${sourceUrl}' -o '${processFilePath()}' && file '${processFilePath()}'` + `mkdir -p $(dirname '${processFilePath()}'); [ -f '${processFilePath()}' ] || curl -sSL '${processSourceUrl()}'${curlUserAgentArg()} -o '${processFilePath()}' && file '${processFilePath()}'` ] stdout: StdioCollector { id: imageSizeOutputCollector diff --git a/dots/.config/quickshell/ii/modules/ii/sidebarLeft/anime/BooruImage.qml b/dots/.config/quickshell/ii/modules/ii/sidebarLeft/anime/BooruImage.qml index 9447abf88..033cf60c3 100644 --- a/dots/.config/quickshell/ii/modules/ii/sidebarLeft/anime/BooruImage.qml +++ b/dots/.config/quickshell/ii/modules/ii/sidebarLeft/anime/BooruImage.qml @@ -172,8 +172,10 @@ Button { onClicked: { root.showActions = false; const targetPath = root.imageData.is_nsfw ? root.nsfwPath : root.downloadPath; + const userAgent = Config.options?.networking?.userAgent ?? "" + const userAgentHeader = userAgent ? ` -H 'User-Agent: ${StringUtils.shellSingleQuoteEscape(userAgent)}'` : "" Quickshell.execDetached(["bash", "-c", - `mkdir -p '${targetPath}' && curl '${root.imageData.file_url}' -o '${targetPath}/${root.fileName}' && notify-send '${Translation.tr("Download complete")}' '${root.downloadPath}/${root.fileName}' -a 'Shell'` + `mkdir -p '${targetPath}' && curl '${StringUtils.shellSingleQuoteEscape(root.imageData.file_url)}'${userAgentHeader} -o '${targetPath}/${root.fileName}' && notify-send '${Translation.tr("Download complete")}' '${root.downloadPath}/${root.fileName}' -a 'Shell'` ]) } } diff --git a/dots/.config/quickshell/ii/modules/ii/sidebarLeft/anime/BooruResponse.qml b/dots/.config/quickshell/ii/modules/ii/sidebarLeft/anime/BooruResponse.qml index f67db79b5..57e42472d 100644 --- a/dots/.config/quickshell/ii/modules/ii/sidebarLeft/anime/BooruResponse.qml +++ b/dots/.config/quickshell/ii/modules/ii/sidebarLeft/anime/BooruResponse.qml @@ -230,7 +230,7 @@ Rectangle { rowHeight: imageRow.rowHeight imageRadius: imageRow.modelData.images.length == 1 ? 50 : Appearance.rounding.normal // Download manually to reduce redundant requests or make sure downloading works - manualDownload: ["danbooru", "waifu.im", "t.alcy.cc"].includes(root.responseData.provider) + manualDownload: ["danbooru", "waifu.im", "t.alcy.cc", "konachan"].includes(root.responseData.provider) previewDownloadPath: root.previewDownloadPath downloadPath: root.downloadPath nsfwPath: root.nsfwPath diff --git a/dots/.config/quickshell/ii/scripts/colors/random/random_konachan_wall.sh b/dots/.config/quickshell/ii/scripts/colors/random/random_konachan_wall.sh index a1f922121..5e92a5bf3 100755 --- a/dots/.config/quickshell/ii/scripts/colors/random/random_konachan_wall.sh +++ b/dots/.config/quickshell/ii/scripts/colors/random/random_konachan_wall.sh @@ -29,14 +29,15 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" mkdir -p "$PICTURES_DIR/Wallpapers" page=$((1 + RANDOM % 1000)); -response=$(curl "https://konachan.net/post.json?tags=rating%3Asafe&limit=1&page=$page") +illogicalImpulseConfigPath="$HOME/.config/illogical-impulse/config.json" +userAgent=$(jq -r '.networking.userAgent // empty' "$illogicalImpulseConfigPath" 2>/dev/null) +response=$(curl -A "$userAgent" "https://konachan.net/post.json?tags=rating%3Asafe&limit=1&page=$page") link=$(echo "$response" | jq '.[0].file_url' -r); ext=$(echo "$link" | awk -F. '{print $NF}') downloadPath="$PICTURES_DIR/Wallpapers/random_wallpaper.$ext" -illogicalImpulseConfigPath="$HOME/.config/illogical-impulse/config.json" -currentWallpaperPath=$(jq -r '.background.wallpaperPath' $illogicalImpulseConfigPath) +currentWallpaperPath=$(jq -r '.background.wallpaperPath' "$illogicalImpulseConfigPath") if [ "$downloadPath" == "$currentWallpaperPath" ]; then downloadPath="$PICTURES_DIR/Wallpapers/random_wallpaper-1.$ext" fi -curl "$link" -o "$downloadPath" +curl -A "$userAgent" "$link" -o "$downloadPath" "$SCRIPT_DIR/../switchwall.sh" --image "$downloadPath" diff --git a/dots/.config/quickshell/ii/services/Booru.qml b/dots/.config/quickshell/ii/services/Booru.qml index 4cba189df..7cc30cc9a 100644 --- a/dots/.config/quickshell/ii/services/Booru.qml +++ b/dots/.config/quickshell/ii/services/Booru.qml @@ -405,8 +405,8 @@ Singleton { } try { - // Required for danbooru - if (currentProvider == "danbooru") { + // Required for danbooru and konachan + if (["danbooru", "konachan"].includes(currentProvider)) { xhr.setRequestHeader("User-Agent", defaultUserAgent) } else if (currentProvider == "zerochan") { @@ -457,8 +457,8 @@ Singleton { } try { - // Required for danbooru - if (currentProvider == "danbooru") { + // Required for danbooru and konachan + if (["danbooru", "konachan"].includes(currentProvider)) { xhr.setRequestHeader("User-Agent", defaultUserAgent) } xhr.send()