Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
0e2ec7a
feat: refactor data fetching for commit documentation and add custom …
sumitjain236 Mar 7, 2025
5e03cbb
feat: remove unused DocsLandingPage, DocsList, HeroSection, and Shoot…
sumitjain236 Mar 7, 2025
f9fa7f2
feat: enhance commit documentation retrieval and update routing for docs
sumitjain236 Mar 7, 2025
c0eb9c3
feat: Docs tab and list of docs
sumitjain236 Mar 7, 2025
f911f3b
feat: add CommitDocsList component for displaying commit documentation
sumitjain236 Mar 7, 2025
82b0a71
feat: Docs dashboard Sidebar
sumitjain236 Mar 7, 2025
9f89e1c
feat: replace anchor tags with Link component for internal navigation…
sumitjain236 Mar 9, 2025
a2770da
feat: update website route rules for commit documentation paths
sumitjain236 Mar 9, 2025
0145911
feat: add description and preview image fields to CommitDocs interfac…
sumitjain236 Mar 11, 2025
1922b32
feat: add convert_to_webp function for image format conversion and ha…
sumitjain236 Mar 11, 2025
f1a2120
feat: add screenshot capture and saving functionality for document pr…
sumitjain236 Mar 11, 2025
15349be
feat: add pyppeteer dependency for browser automation support
sumitjain236 Mar 11, 2025
de81643
feat: add preview image field and functionality to save screenshot in…
sumitjain236 Mar 11, 2025
e0bcf45
feat: add functionality to save preview screenshot before saving Comm…
sumitjain236 Mar 11, 2025
9673dfc
feat: Add Commit Docs Modal
sumitjain236 Mar 11, 2025
5579dc2
feat: update Overview component to dynamically adjust tab grid count …
sumitjain236 Mar 15, 2025
ed70f08
feat: add DocsMainPage component for displaying commit documentation …
sumitjain236 Mar 15, 2025
b47d547
feat: enhance Sidebar component with animated transitions and improve…
sumitjain236 Mar 15, 2025
3fc271f
feat: update routing in App component to include DocsMainPage and Pag…
sumitjain236 Mar 23, 2025
2345cb3
feat: enhance DocsMainPage and PageContent components for improved us…
sumitjain236 Mar 23, 2025
d3805a5
feat: implement Commit Docs Page list retrieval and enhance PageTable…
sumitjain236 Mar 23, 2025
6c5ff44
feat: simplify DocsPageForm layout by removing expandable fields and …
sumitjain236 Mar 23, 2025
e377fb7
feat: add CreateCommitDocsPage component for creating new documentati…
sumitjain236 Mar 23, 2025
98d4380
feat: fix badge rendering in Sidebar component for consistent display
sumitjain236 Mar 28, 2025
15e65aa
feat: add AsyncDropdownWithoutForm component for without form
sumitjain236 Mar 29, 2025
27d3115
feat: remove OnThisPage component
sumitjain236 Mar 29, 2025
8eec364
feat: add mutate function to useGetCommitDocsDetails for enhanced dat…
sumitjain236 Mar 29, 2025
d7eab1f
feat: add Sidebar component
sumitjain236 Mar 29, 2025
fc2b59b
feat: add animation to ViewDocs component for improved user experience
sumitjain236 Mar 29, 2025
203bd7d
feat: integrate dnd-kit for drag-and-drop functionality in Sidebar co…
sumitjain236 Mar 29, 2025
96f5271
feat: add manage_sidebar function to modify sidebar items in Commit Docs
sumitjain236 Mar 29, 2025
15ec41f
fix: update image handling in convert_to_webp to use io.BytesIO for b…
sumitjain236 Mar 29, 2025
e4a1fdb
feat: add column title editing functionality in BoardColumn and Kanba…
sumitjain236 Mar 30, 2025
475d051
feat: add Discord URL field to Commit Docs for enhanced communication…
sumitjain236 Mar 30, 2025
9728047
refactor: remove Renderer component and associated logic for document…
sumitjain236 Mar 30, 2025
a37a4eb
feat: enhance ImageUploader with edit and delete buttons using icons
sumitjain236 Mar 30, 2025
3eb1dfc
feat: add DocsSettings component for managing documentation settings
sumitjain236 Mar 30, 2025
f53e3c3
feat: implement Sidebar component for enhanced documentation navigation
sumitjain236 Mar 30, 2025
e8a77f0
refactor: replace KanbanBoard with SidebarBoard in DashboardSidebar c…
sumitjain236 Mar 30, 2025
f88e1d8
feat: add DashboardNavbar component and integrate it into the routing…
sumitjain236 Mar 30, 2025
521b111
feat: enhance NavbarColumn and NavbarTaskCard components with additio…
sumitjain236 Mar 30, 2025
2650d0d
feat: add hide_on_navbar and hide_on_sidebar properties to Navbar and…
sumitjain236 Mar 31, 2025
87fc088
chore: remove MDX plugin and dependencies from Vite configuration and…
sumitjain236 Mar 31, 2025
ea9cc4a
feat: add MarkdownRenderer and MarkdownRendererSuspense components fo…
sumitjain236 Mar 31, 2025
f6e5d53
feat: add DashboardFooter component and integrate it into the App rou…
sumitjain236 Mar 31, 2025
ecbbf8d
feat: add FooterTaskCard component for enhanced task management in th…
sumitjain236 Mar 31, 2025
ea889c2
feat: add manage_footer function to modify footer items in commit docs
sumitjain236 Mar 31, 2025
d7a9793
feat: enhance NavbarColumn layout and improve input field accessibility
sumitjain236 Mar 31, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions commit/api/convert_to_webp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import frappe
from frappe.core.doctype.file.utils import delete_file
from urllib.parse import unquote
import requests
from PIL import Image
from frappe.core.doctype.file.file import get_local_image
from frappe.model.document import Document
import os

@frappe.whitelist()
def convert_to_webp(image_url: str | None = None, file_doc: Document | None = None) -> str:
"""BETA: Convert image to webp format"""

CONVERTIBLE_IMAGE_EXTENSIONS = ["png", "jpeg", "jpg"]

def can_convert_image(extn):
return extn.lower() in CONVERTIBLE_IMAGE_EXTENSIONS

def get_extension(filename):
return filename.split(".")[-1].lower()

def convert_and_save_image(image, path):
image.save(path, "WEBP")
return path

def update_file_doc_with_webp(file_doc, image, extn):
webp_path = file_doc.get_full_path().replace(extn, "webp")
convert_and_save_image(image, webp_path)
delete_file(file_doc.get_full_path())
file_doc.file_url = f"{file_doc.file_url.replace(extn, 'webp')}"
file_doc.save()
return file_doc.file_url

def create_new_webp_file_doc(file_url, image, extn):
files = frappe.get_all("File", filters={"file_url": file_url}, fields=["name"], limit=1)
if files:
_file = frappe.get_doc("File", files[0].name)
webp_path = _file.get_full_path().replace(extn, "webp")
convert_and_save_image(image, webp_path)
new_file = frappe.copy_doc(_file)
new_file.file_name = f"{_file.file_name.replace(extn, 'webp')}"
new_file.file_url = f"{_file.file_url.replace(extn, 'webp')}"
new_file.save()
return new_file.file_url
return file_url

def handle_image_from_url(image_url):
image_url = unquote(image_url)
response = requests.get(image_url)
image = Image.open(io.BytesIO(response.content))
filename = image_url.split("/")[-1]
extn = get_extension(filename)
if can_convert_image(extn):
_file = frappe.get_doc(
{
"doctype": "File",
"file_name": f"{filename.replace(extn, 'webp')}",
"file_url": f"/files/{filename.replace(extn, 'webp')}",
}
)
webp_path = _file.get_full_path()
convert_and_save_image(image, webp_path)
_file.save()
return _file.file_url
return image_url

if not image_url and not file_doc:
return ""

if file_doc:
if file_doc.file_url.startswith("/files"):
image, filename, extn = get_local_image(file_doc.file_url)
if can_convert_image(extn):
return update_file_doc_with_webp(file_doc, image, extn)
if file_doc.file_url.startswith("/private"):
image, filename, extn = get_local_image(file_doc.file_url)
if can_convert_image(extn):
return update_file_doc_with_webp(file_doc, image, extn)

return file_doc.file_url

if image_url.startswith("/files"):
image, filename, extn = get_local_image(image_url)
if can_convert_image(extn):
return create_new_webp_file_doc(image_url, image, extn)
return image_url
if image_url.startswith("/private"):
image, filename, extn = get_local_image(image_url)
if can_convert_image(extn):
return create_new_webp_file_doc(image_url, image, extn)
return image_url
if image_url.startswith("http"):
return handle_image_from_url(image_url)

return image_url

def save_webp_image(doctype:str,docname:str,image_field:str):
file_url = frappe.db.get_value(doctype,docname,image_field)
if file_url:
webp_url = convert_to_webp(file_url)
frappe.db.set_value(doctype,docname,image_field,webp_url)
59 changes: 59 additions & 0 deletions commit/api/preview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import asyncio
import io
from pyppeteer import launch
import frappe
from frappe.utils.file_manager import save_file
from commit.api.convert_to_webp import convert_to_webp

async def capture_screenshot(url, width=1366, height=800, delay=3):
browser = await launch(
headless=True,
handleSIGINT=False,
handleSIGTERM=False,
handleSIGHUP=False
)
page = await browser.newPage()

await page.setViewport({"width": width, "height": height})
await page.goto(url, {"waitUntil": "load"})
await asyncio.sleep(delay) # Ensure page loads fully

# ✅ Explicitly return bytes and ensure no file is saved
screenshot_bytes = await page.screenshot({"fullPage": False, "encoding": "binary"})

await browser.close()

return screenshot_bytes # Return raw image data

def save_preview_screenshot(url, doctype, docname, field):
try:
loop = asyncio.get_running_loop()
except RuntimeError:
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
screenshot_bytes = loop.run_until_complete(capture_screenshot(url))
else:
screenshot_bytes = loop.run_until_complete(capture_screenshot(url))

# ✅ Correct way: Wrap bytes in BytesIO
screenshot_io = io.BytesIO(screenshot_bytes)

file_doc = frappe.get_doc({
"doctype": "File",
"file_name": docname + "_" + "preview.png",
"attached_to_doctype": doctype,
"attached_to_name": docname,
"attached_to_field": field,
"is_private": 1,
"content": screenshot_io.getvalue()
})
file_doc.save()

# Convert to WebP
file_url = convert_to_webp(file_doc.file_url, file_doc)
# Update the document with the preview file URL
doc = frappe.get_doc(doctype, docname)
doc.set(field, file_url)
doc.save()

frappe.db.commit()
16 changes: 15 additions & 1 deletion commit/commit/doctype/commit_docs/commit_docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"logo_section",
"light_mode_logo",
"night_mode_logo",
"preview_image",
"navbar_tab",
"navbar_items",
"footer_tab",
Expand All @@ -27,6 +28,7 @@
"github",
"raven",
"telegram",
"discord",
"section_break_gawv",
"footer"
],
Expand Down Expand Up @@ -166,11 +168,22 @@
"fieldname": "description",
"fieldtype": "Small Text",
"label": "Description"
},
{
"fieldname": "preview_image",
"fieldtype": "Attach Image",
"label": "Preview Image"
},
{
"description": "Add Discord URl",
"fieldname": "discord",
"fieldtype": "Data",
"label": "Discord"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-12-07 22:34:40.239467",
"modified": "2025-03-30 12:43:40.306104",
"modified_by": "Administrator",
"module": "commit",
"name": "Commit Docs",
Expand All @@ -190,6 +203,7 @@
"write": 1
}
],
"row_format": "Dynamic",
"sort_field": "creation",
"sort_order": "DESC",
"states": []
Expand Down
Loading