Skip to content

Commit

Permalink
fix: add whitelist decorater for file content method
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohan Bansal committed Aug 19, 2024
1 parent 328d8e8 commit c443a7e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cloud_storage/cloud_storage/overrides/file.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (c) 2024, AgriTheory and contributors
# For license information, please see license.txt

import json
import os
import re
Expand Down Expand Up @@ -168,6 +171,7 @@ def remove_file_association(self, dt: str, dn: str) -> None:
association.idx = idx
self.save()

@frappe.whitelist()
def get_content(self) -> bytes:
if self.is_folder:
frappe.throw(_("Cannot get file contents of a Folder"))
Expand All @@ -182,7 +186,6 @@ def get_content(self) -> bytes:

if self.file_url:
self.validate_file_url()
file_path = quote(self.get_full_path())

if self.file_url.startswith("/api/method/retrieve"):
client = get_cloud_storage_client()
Expand All @@ -191,7 +194,7 @@ def get_content(self) -> bytes:
elif self.file_url.startswith("http://") or self.file_url.startswith("https://"):
self._content = urlopen(self.file_url).read()
else:
# read the file
file_path = quote(self.get_full_path())
with open(file_path, mode="rb") as f:
self._content = f.read()
try:
Expand Down

0 comments on commit c443a7e

Please sign in to comment.