use crate::{helpers, metadata::Custom, Error, Result};
use std::ffi::CString;
use std::time::Duration;
use uplink_sys as ulksys;
pub struct CommitUpload<'a> {
custom_metadata: &'a mut Custom,
}
impl<'a> CommitUpload<'a> {
pub fn new(custom_metadata: &'a mut Custom) -> Self {
Self { custom_metadata }
}
#[allow(clippy::wrong_self_convention)]
pub(crate) fn to_ffi_commit_upload_options(&mut self) -> ulksys::UplinkCommitUploadOptions {
ulksys::UplinkCommitUploadOptions {
custom_metadata: self.custom_metadata.to_ffi_custom_metadata(),
}
}
}
#[derive(Default)]
pub struct CopyObject {}
impl CopyObject {
pub(crate) fn as_ffi_copy_object_options(&self) -> ulksys::UplinkCopyObjectOptions {
ulksys::UplinkCopyObjectOptions {}
}
}
#[derive(Default)]
pub struct Download {
pub offset: i64,
pub length: i64,
}
impl Download {
pub(crate) fn as_ffi_download_options(&self) -> ulksys::UplinkDownloadOptions {
ulksys::UplinkDownloadOptions {
offset: self.offset,
length: self.length,
}
}
}
#[derive(Default)]
pub struct ListBuckets {
inner_cursor: CString,
}
impl ListBuckets {
pub fn with_cursor(cursor: &str) -> Result<Self> {
let inner_cursor = helpers::cstring_from_str_fn_arg("cursor", cursor)?;
Ok(Self { inner_cursor })
}
pub(crate) fn as_ffi_list_buckets_options(&self) -> ulksys::UplinkListBucketsOptions {
ulksys::UplinkListBucketsOptions {
cursor: self.inner_cursor.as_ptr(),
}
}
}
#[derive(Default)]
pub struct ListObjects<'a> {
prefix: &'a str,
inner_prefix: CString,
cursor: &'a str,
inner_cursor: CString,
pub recursive: bool,
pub system: bool,
pub custom: bool,
}
impl<'a> ListObjects<'a> {
pub fn with_prefix(prefix: &'a str) -> Result<Self> {
if !prefix.ends_with('/') {
return Err(Error::new_invalid_arguments(
"prefix",
"cannot be empty and must end with '/'",
));
}
Self::new(prefix, "")
}
pub fn with_cursor(cursor: &'a str) -> Result<Self> {
if cursor.is_empty() {
return Err(Error::new_invalid_arguments("cursor", "cannot be empty"));
}
Self::new("", cursor)
}
pub fn with_prefix_and_cursor(prefix: &'a str, cursor: &'a str) -> Result<Self> {
if !prefix.ends_with('/') {
return Err(Error::new_invalid_arguments(
"prefix",
"cannot be empty and must end with '/'",
));
}
if cursor.is_empty() {
return Err(Error::new_invalid_arguments("cursor", "cannot be empty"));
}
Self::new(prefix, cursor)
}
fn new(prefix: &'a str, cursor: &'a str) -> Result<Self> {
let inner_prefix = helpers::cstring_from_str_fn_arg("prefix", prefix)?;
let inner_cursor = helpers::cstring_from_str_fn_arg("cursor", cursor)?;
Ok(Self {
prefix,
inner_prefix,
cursor,
inner_cursor,
..Default::default()
})
}
pub(crate) fn as_ffi_list_objects_options(&self) -> ulksys::UplinkListObjectsOptions {
ulksys::UplinkListObjectsOptions {
prefix: self.inner_prefix.as_ptr(),
cursor: self.inner_cursor.as_ptr(),
recursive: self.recursive,
system: self.system,
custom: self.custom,
}
}
}
#[derive(Default)]
pub struct ListUploads<'a> {
prefix: &'a str,
inner_prefix: CString,
cursor: &'a str,
inner_cursor: CString,
pub recursive: bool,
pub system: bool,
pub custom: bool,
}
impl<'a> ListUploads<'a> {
pub fn with_prefix(prefix: &'a str) -> Result<Self> {
if !prefix.ends_with('/') {
return Err(Error::new_invalid_arguments(
"prefix",
"cannot be empty and must end with '/'",
));
}
Self::new(prefix, "")
}
pub fn with_cursor(cursor: &'a str) -> Result<Self> {
if cursor.is_empty() {
return Err(Error::new_invalid_arguments("cursor", "cannot be empty"));
}
Self::new("", cursor)
}
pub fn with_prefix_and_cursor(prefix: &'a str, cursor: &'a str) -> Result<Self> {
if !prefix.ends_with('/') {
return Err(Error::new_invalid_arguments(
"prefix",
"cannot be empty and must end with '/'",
));
}
if cursor.is_empty() {
return Err(Error::new_invalid_arguments("cursor", "cannot be empty"));
}
Self::new(prefix, cursor)
}
fn new(prefix: &'a str, cursor: &'a str) -> Result<Self> {
let inner_prefix = helpers::cstring_from_str_fn_arg("prefix", prefix)?;
let inner_cursor = helpers::cstring_from_str_fn_arg("cursor", cursor)?;
Ok(Self {
prefix,
inner_prefix,
cursor,
inner_cursor,
..Default::default()
})
}
pub(crate) fn as_ffi_list_uploads_options(&self) -> ulksys::UplinkListUploadsOptions {
ulksys::UplinkListUploadsOptions {
prefix: self.inner_prefix.as_ptr(),
cursor: self.inner_cursor.as_ptr(),
recursive: self.recursive,
system: self.system,
custom: self.custom,
}
}
}
#[derive(Default)]
pub struct ListUploadParts {
pub cursor: u32,
}
impl ListUploadParts {
pub(crate) fn as_ffi_list_upload_parts_options(&self) -> ulksys::UplinkListUploadPartsOptions {
ulksys::UplinkListUploadPartsOptions {
cursor: self.cursor,
}
}
}
#[derive(Default)]
pub struct MoveObject {}
impl MoveObject {
pub(crate) fn as_ffi_move_object_options(&self) -> ulksys::UplinkMoveObjectOptions {
ulksys::UplinkMoveObjectOptions {}
}
}
#[derive(Default)]
pub struct Upload {
pub expires: Option<Duration>,
}
impl Upload {
pub(crate) fn as_ffi_upload_options(&self) -> ulksys::UplinkUploadOptions {
let expires = self.expires.unwrap_or(Duration::ZERO);
ulksys::UplinkUploadOptions {
expires: expires.as_secs() as i64,
}
}
}
#[derive(Default)]
pub struct UploadObjectMetadata {}
impl UploadObjectMetadata {
pub(crate) fn as_ffi_upload_object_metadata_options(
&self,
) -> ulksys::UplinkUploadObjectMetadataOptions {
ulksys::UplinkUploadObjectMetadataOptions {}
}
}
#[cfg(test)]
mod test {
#[test]
fn test_list_buckets_with_cursor() {
}
#[test]
fn test_list_objects_with_prefix() {
}
#[test]
fn test_list_objects_with_cursor() {
}
#[test]
fn test_list_objects_with_prefix_and_cursor() {
}
#[test]
fn test_list_uploads_with_prefix() {
}
#[test]
fn test_list_uploads_with_cursor() {
}
#[test]
fn test_list_uploads_with_prefix_and_cursor() {
}
}