Skip to content

Commit

Permalink
feat: redirect short links!
Browse files Browse the repository at this point in the history
  • Loading branch information
NagariaHussain committed Dec 21, 2024
1 parent 6a2537e commit 83677a5
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 0 deletions.
3 changes: 3 additions & 0 deletions linklite/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
app_email = "[email protected]"
app_license = "agpl-3.0"


website_path_resolver = "linklite.utils.path_resolver"

# Apps
# ------------------

Expand Down
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions linklite/linklite/doctype/short_link/short_link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024, Build With Hussain and contributors
// For license information, please see license.txt

// frappe.ui.form.on("Short Link", {
// refresh(frm) {

// },
// });
66 changes: 66 additions & 0 deletions linklite/linklite/doctype/short_link/short_link.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"actions": [],
"allow_rename": 1,
"autoname": "field:short_link",
"creation": "2024-12-21 12:43:49.300176",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"destination_url",
"column_break_awjo",
"short_link",
"description"
],
"fields": [
{
"fieldname": "destination_url",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Destination URL",
"options": "URL",
"reqd": 1
},
{
"fieldname": "column_break_awjo",
"fieldtype": "Column Break"
},
{
"fieldname": "short_link",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Short Link",
"reqd": 1,
"unique": 1
},
{
"fieldname": "description",
"fieldtype": "Small Text",
"label": "Description"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-12-21 12:45:50.795245",
"modified_by": "Administrator",
"module": "LinkLite",
"name": "Short Link",
"naming_rule": "By fieldname",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
9 changes: 9 additions & 0 deletions linklite/linklite/doctype/short_link/short_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2024, Build With Hussain and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document


class ShortLink(Document):
pass
30 changes: 30 additions & 0 deletions linklite/linklite/doctype/short_link/test_short_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2024, Build With Hussain and Contributors
# See license.txt

# import frappe
from frappe.tests import IntegrationTestCase, UnitTestCase


# On IntegrationTestCase, the doctype test records and all
# link-field test record depdendencies are recursively loaded
# Use these module variables to add/remove to/from that list
EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]
IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]


class UnitTestShortLink(UnitTestCase):
"""
Unit tests for ShortLink.
Use this class for testing individual functions and methods.
"""

pass


class IntegrationTestShortLink(IntegrationTestCase):
"""
Integration tests for ShortLink.
Use this class for testing interactions between multiple components.
"""

pass
14 changes: 14 additions & 0 deletions linklite/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import frappe

from frappe.website.path_resolver import resolve_path as original_resolve_path

def path_resolver(path: str):
# if we want to handle the short link
if frappe.db.exists("Short Link", {"short_link": path}):
# we want to redirect
destination = frappe.db.get_value("Short Link", {"short_link": path}, "destination_url")
frappe.redirect(destination)


# else pass it on!
return original_resolve_path(path)

0 comments on commit 83677a5

Please sign in to comment.