-
Notifications
You must be signed in to change notification settings - Fork 4
Add hosted Defuddle URL conversion to the app #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| from pathlib import Path, PureWindowsPath | ||
| from urllib.parse import unquote, urlparse | ||
|
|
||
| WEB_URL_SCHEMES = {"http", "https"} | ||
| UNSAFE_FILENAME_CHARS = re.compile(r"[^A-Za-z0-9._-]+") | ||
|
|
||
|
|
||
| def is_web_url(value: str) -> bool: | ||
| candidate = value.strip() | ||
| if not candidate: | ||
| return False | ||
| if any(ch.isspace() or ord(ch) < 32 for ch in candidate): | ||
| return False | ||
|
|
||
| parsed = urlparse(candidate) | ||
| return parsed.scheme.lower() in WEB_URL_SCHEMES and bool(parsed.netloc) | ||
|
|
||
|
|
||
| def _source_path(source: str) -> Path | PureWindowsPath: | ||
| candidate = source.strip() | ||
| if "\\" in candidate: | ||
| return PureWindowsPath(candidate) | ||
| return Path(candidate) | ||
|
|
||
|
|
||
| def source_display_name(source: str) -> str: | ||
| return source.strip() if is_web_url(source) else _source_path(source).name or source | ||
|
|
||
|
|
||
| def source_output_stem(source: str) -> str: | ||
| if not is_web_url(source): | ||
| return _source_path(source).stem or "converted" | ||
|
|
||
| parsed = urlparse(source.strip()) | ||
| path_parts = [part for part in parsed.path.split("/") if part] | ||
| slug = unquote(path_parts[-1]) if path_parts else "" | ||
| query = parsed.query.split("&", 1)[0] if parsed.query else "" | ||
|
|
||
| segments = [parsed.netloc] | ||
| if slug: | ||
| segments.append(slug) | ||
| elif query: | ||
| segments.append(query) | ||
|
|
||
| candidate = "-".join(segments) | ||
| sanitized = UNSAFE_FILENAME_CHARS.sub("-", candidate).strip("._-") | ||
| return sanitized or "website" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from PySide6.QtCore import Signal | ||
| from PySide6.QtWidgets import QHBoxLayout, QWidget | ||
| from qfluentwidgets import LineEdit, PushButton | ||
|
|
||
|
|
||
| class UrlInputBar(QWidget): | ||
| url_submitted = Signal(str) | ||
|
|
||
| def __init__(self, translate, parent=None): | ||
| super().__init__(parent=parent) | ||
| self.translate = translate | ||
|
|
||
| layout = QHBoxLayout(self) | ||
| layout.setContentsMargins(0, 0, 0, 0) | ||
| layout.setSpacing(8) | ||
|
|
||
| self.url_edit = LineEdit(self) | ||
| self.url_edit.returnPressed.connect(self.submit_url) | ||
|
|
||
| self.submit_button = PushButton(self) | ||
| self.submit_button.clicked.connect(self.submit_url) | ||
|
|
||
| layout.addWidget(self.url_edit, 1) | ||
| layout.addWidget(self.submit_button) | ||
|
|
||
| self.retranslate_ui(translate) | ||
|
|
||
| def submit_url(self) -> None: | ||
| value = self.url_edit.text().strip() | ||
| if value: | ||
| self.url_submitted.emit(value) | ||
|
|
||
| def clear(self) -> None: | ||
| self.url_edit.clear() | ||
|
|
||
| def retranslate_ui(self, translate) -> None: | ||
| self.translate = translate | ||
| self.url_edit.setPlaceholderText(self.translate("home_url_placeholder")) | ||
| self.submit_button.setText(self.translate("home_add_url_button")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_web_url() is used as the primary validation gate for URL input, but it currently returns True for strings that contain whitespace in the URL path (e.g., "https://example.com/hello world"). Those inputs will later fail during HTTP request construction. Consider tightening validation (reject any whitespace / control chars) or normalizing to a properly encoded URL before enqueueing so the UI’s "Invalid URL" path catches these cases.