Merge pull request #32429 from iamejaaz/37368-invalid-file-url
fix: don't allow attaching an file invalid url
This commit is contained in:
commit
21f79128e5
2 changed files with 26 additions and 2 deletions
|
|
@ -521,14 +521,37 @@ function upload_via_file_browser() {
|
|||
library_file_name: selected_file.value,
|
||||
});
|
||||
}
|
||||
function upload_via_web_link() {
|
||||
|
||||
async function validate_html_url(url) {
|
||||
try {
|
||||
let response = await fetch(url, { method: "HEAD" });
|
||||
let contentType = response.headers.get("Content-Type");
|
||||
|
||||
if (contentType && contentType.includes("text/html")) {
|
||||
return false;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Error fetching URL:", error);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async function upload_via_web_link() {
|
||||
let file_url = web_link.value.url;
|
||||
if (!file_url) {
|
||||
frappe.msgprint(__("Invalid URL"));
|
||||
close_dialog.value = true;
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
file_url = decodeURI(file_url);
|
||||
const is_valid = await validate_html_url(file_url);
|
||||
|
||||
if (!is_valid) {
|
||||
frappe.msgprint(__("Invalid or unsupported URL"));
|
||||
return Promise.reject();
|
||||
}
|
||||
|
||||
close_dialog.value = true;
|
||||
return upload_file({
|
||||
file_url,
|
||||
|
|
|
|||
|
|
@ -78,7 +78,8 @@ def get_context(context) -> PrintContext:
|
|||
body = get_html(
|
||||
doctype=frappe.form_dict.doctype, name=frappe.form_dict.name, print_format=print_format.name
|
||||
)
|
||||
body += trigger_print_script
|
||||
if cint(frappe.form_dict.trigger_print):
|
||||
body += trigger_print_script
|
||||
else:
|
||||
body = get_rendered_template(
|
||||
doc,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue