Skip to content

Commit e4b9b5e

Browse files
Cloud Storage: Add get_metadata method
1 parent efc8a4c commit e4b9b5e

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

firebase/export_scripts_template/modules/Firestore.gd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ func _connect_signals():
1717
_plugin_singleton.connect("firestore_delete_task_completed", delete_task_completed.emit)
1818
_plugin_singleton.connect("firestore_document_changed", document_changed.emit)
1919

20-
func add_document(collection: String, documentId: String) -> void:
20+
func add_document(collection: String, data: Dictionary) -> void:
2121
if _plugin_singleton:
22-
_plugin_singleton.firestoreAddDocument(collection, documentId)
22+
_plugin_singleton.firestoreAddDocument(collection, data)
2323

2424
func set_document(collection: String, documentId: String, data: Dictionary, merge: bool = false) -> void:
2525
if _plugin_singleton:

firebase/export_scripts_template/modules/Storage.gd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ func download_file(path: String, destinationPath: String) -> void:
2323
if _plugin_singleton:
2424
_plugin_singleton.storageDownloadFile(path, destinationPath)
2525

26+
func get_metadata(path: String) -> void:
27+
if _plugin_singleton:
28+
_plugin_singleton.storageGetMetadata(path)
29+
2630
func delete_file(path: String) -> void:
2731
if _plugin_singleton:
2832
_plugin_singleton.storageDeleteFile(path)

firebase/src/main/java/org/godotengine/plugin/firebase/CloudStorage.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,29 @@ class CloudStorage(private val plugin: FirebasePlugin) {
7676
}
7777
}
7878

79+
fun getMetadata(path: String) {
80+
val ref = storageRef.child(path)
81+
82+
ref.metadata
83+
.addOnSuccessListener { metadata ->
84+
val metadataDict = Dictionary()
85+
metadataDict["content_type"] = metadata.contentType
86+
metadataDict["size_bytes"] = metadata.sizeBytes
87+
metadataDict["updated_time"] = metadata.updatedTimeMillis
88+
metadataDict["creation_time"] = metadata.creationTimeMillis
89+
metadataDict["name"] = metadata.name
90+
metadataDict["path"] = metadata.path
91+
metadataDict["bucket"] = metadata.bucket
92+
93+
Log.d(TAG, "Metadata retrieved for $path")
94+
plugin.emitGodotSignal("storage_download_task_completed", createResultDict(true, path, data = metadataDict))
95+
}
96+
.addOnFailureListener { e ->
97+
Log.e(TAG, "Failed to get metadata for $path", e)
98+
plugin.emitGodotSignal("storage_download_task_completed", createResultDict(false, path, e.message))
99+
}
100+
}
101+
79102
fun deleteFile(path: String) {
80103
val ref = storageRef.child(path)
81104

firebase/src/main/java/org/godotengine/plugin/firebase/FirebasePlugin.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ class FirebasePlugin(godot: Godot) : GodotPlugin(godot) {
114114
@UsedByGodot
115115
fun storageDownloadFile(path: String, destinationPath: String) = storage.downloadFile(path, destinationPath)
116116

117+
@UsedByGodot
118+
fun storageGetMetadata(path: String) = storage.getMetadata(path)
119+
117120
@UsedByGodot
118121
fun storageDeleteFile(path: String) = storage.deleteFile(path)
119122

0 commit comments

Comments
 (0)