Skip to content

Commit

Permalink
Merge pull request #4 from fenix-hub/main
Browse files Browse the repository at this point in the history
update _serve_file func
  • Loading branch information
dploeger authored Mar 18, 2022
2 parents a1c697f + fe8530c commit 2538bb1
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions addons/godottpd/http_file_router.gd
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,28 @@ func handle_get(request: HttpRequest, response: HttpResponse) -> void:
else:
response.send_raw(404)

# (Internal function)
# Reads a file as text
#
# #### Parameters
# - file_path: Full path to the file
func _serve_file(file_path: String) -> PoolByteArray:
var content: PoolByteArray = []
var file = File.new()
var file_opened: bool = not bool(file.open(file_path, File.READ))
if file_opened:
var error: int = file.open(file_path, File.READ)
if error:
content = ("Couldn't serve file, ERROR = %s" % error).to_ascii()
else:
content = file.get_buffer(file.get_len())
file.close()
file.close()
return content

# (Internal Function)
# Check if a file exists
#
# #### Parameters
# - file_path: Full path to the file
func _file_exists(file_path: String) -> bool:
return File.new().file_exists(file_path)

# (Internal function)
# Get the full MIME type of a file from its extension
#
# #### Parameters
Expand Down Expand Up @@ -156,4 +155,4 @@ func _get_mime(file_extension: String) -> String:
subtype = "x-msvideo"
"ogx":
subtype = "ogg"
return type + "/" + subtype
return type + "/" + subtype

0 comments on commit 2538bb1

Please sign in to comment.