Skip to main content

surrealdb_core/fnc/script/classes/
file.rs

1use js::JsLifetime;
2use js::class::Trace;
3
4use crate::val;
5
6#[derive(Clone, Trace, JsLifetime)]
7#[js::class]
8pub struct File {
9	#[qjs(skip_trace)]
10	pub(crate) value: val::File,
11}
12
13#[js::methods]
14impl File {
15	#[qjs(constructor)]
16	pub fn new(bucket: String, key: String) -> Self {
17		Self {
18			value: val::File::new(bucket, key),
19		}
20	}
21
22	#[qjs(get)]
23	pub fn value(&self) -> String {
24		self.value.to_string()
25	}
26	// Compare two File instances
27	pub fn is(a: &File, b: &File) -> bool {
28		a.value == b.value
29	}
30	/// Convert the object to a string
31	#[qjs(rename = "toString")]
32	pub fn js_to_string(&self) -> String {
33		self.value.display_inner()
34	}
35	/// Convert the object to JSON
36	#[qjs(rename = "toJSON")]
37	pub fn to_json(&self) -> String {
38		self.value.display_inner()
39	}
40	// Get the bucket for this file
41	pub fn bucket(&self) -> String {
42		self.value.bucket.clone()
43	}
44	// Get the key for this file
45	pub fn key(&self) -> String {
46		self.value.key.clone()
47	}
48}