Skip to content

Commit 402dddb

Browse files
Add multipart content type (#30)
* Add multipart content type * Regenerate with vrchatapi/specification#408 Signed-off-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> * Use async file io and don't `unwrap` * Don't use file-io for multipart uploads/image endpoints --------- Signed-off-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com> Co-authored-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com>
1 parent af466f2 commit 402dddb

13 files changed

+340
-2
lines changed

.openapi-generator/FILES

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ docs/ApiConfigReportReasons.md
2323
docs/ApiHealth.md
2424
docs/AuthenticationApi.md
2525
docs/Avatar.md
26+
docs/AvatarStyles.md
2627
docs/AvatarUnityPackageUrlObject.md
2728
docs/AvatarsApi.md
2829
docs/Badge.md
@@ -220,6 +221,7 @@ src/models/api_config_report_categories.rs
220221
src/models/api_config_report_reasons.rs
221222
src/models/api_health.rs
222223
src/models/avatar.rs
224+
src/models/avatar_styles.rs
223225
src/models/avatar_unity_package_url_object.rs
224226
src/models/badge.rs
225227
src/models/ban_group_member_request.rs

docs/Avatar.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Name | Type | Description | Notes
1515
**image_url** | **String** | |
1616
**name** | **String** | |
1717
**release_status** | [**models::ReleaseStatus**](ReleaseStatus.md) | |
18+
**styles** | [**models::AvatarStyles**](Avatar_styles.md) | |
1819
**tags** | **Vec<String>** | |
1920
**thumbnail_image_url** | **String** | |
2021
**unity_package_url** | **String** | |

docs/AvatarStyles.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# AvatarStyles
2+
3+
## Properties
4+
5+
Name | Type | Description | Notes
6+
------------ | ------------- | ------------- | -------------
7+
**primary** | Option<**String**> | | [optional]
8+
**secondary** | Option<**String**> | | [optional]
9+
**supplementary** | Option<**Vec<String>**> | | [optional]
10+
11+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
12+
13+

docs/File.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
Name | Type | Description | Notes
66
------------ | ------------- | ------------- | -------------
7+
**animation_style** | Option<**String**> | | [optional]
8+
**mask_tag** | Option<**String**> | | [optional]
79
**extension** | **String** | |
810
**id** | **String** | |
911
**mime_type** | [**models::MimeType**](MIMEType.md) | |

docs/FilesApi.md

+96
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ Method | HTTP request | Description
1414
[**get_file_data_upload_status**](FilesApi.md#get_file_data_upload_status) | **GET** /file/{fileId}/{versionId}/{fileType}/status | Check FileData Upload Status
1515
[**get_files**](FilesApi.md#get_files) | **GET** /files | List Files
1616
[**start_file_data_upload**](FilesApi.md#start_file_data_upload) | **PUT** /file/{fileId}/{versionId}/{fileType}/start | Start FileData Upload
17+
[**upload_gallery_image**](FilesApi.md#upload_gallery_image) | **POST** /gallery | Upload gallery image
18+
[**upload_icon**](FilesApi.md#upload_icon) | **POST** /icon | Upload icon
19+
[**upload_image**](FilesApi.md#upload_image) | **POST** /file/image | Upload gallery image, icon, emoji or sticker
1720

1821

1922

@@ -330,3 +333,96 @@ Name | Type | Description | Required | Notes
330333

331334
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
332335

336+
337+
## upload_gallery_image
338+
339+
> models::File upload_gallery_image(file)
340+
Upload gallery image
341+
342+
Upload a gallery image
343+
344+
### Parameters
345+
346+
347+
Name | Type | Description | Required | Notes
348+
------------- | ------------- | ------------- | ------------- | -------------
349+
**file** | **std::path::PathBuf** | The binary blob of the png file. | [required] |
350+
351+
### Return type
352+
353+
[**models::File**](File.md)
354+
355+
### Authorization
356+
357+
[authCookie](../README.md#authCookie)
358+
359+
### HTTP request headers
360+
361+
- **Content-Type**: multipart/form-data
362+
- **Accept**: application/json
363+
364+
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
365+
366+
367+
## upload_icon
368+
369+
> models::File upload_icon(file)
370+
Upload icon
371+
372+
Upload an icon
373+
374+
### Parameters
375+
376+
377+
Name | Type | Description | Required | Notes
378+
------------- | ------------- | ------------- | ------------- | -------------
379+
**file** | **std::path::PathBuf** | The binary blob of the png file. | [required] |
380+
381+
### Return type
382+
383+
[**models::File**](File.md)
384+
385+
### Authorization
386+
387+
[authCookie](../README.md#authCookie)
388+
389+
### HTTP request headers
390+
391+
- **Content-Type**: multipart/form-data
392+
- **Accept**: application/json
393+
394+
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
395+
396+
397+
## upload_image
398+
399+
> models::File upload_image(file, tag, animation_style, mask_tag)
400+
Upload gallery image, icon, emoji or sticker
401+
402+
Upload an image, which can be an icon, gallery image, sticker or emoji
403+
404+
### Parameters
405+
406+
407+
Name | Type | Description | Required | Notes
408+
------------- | ------------- | ------------- | ------------- | -------------
409+
**file** | **std::path::PathBuf** | The binary blob of the png file. | [required] |
410+
**tag** | **String** | Needs to be either icon, gallery, sticker or emoji | [required] |
411+
**animation_style** | Option<**String**> | Animation style for sticker, required for sticker. | |
412+
**mask_tag** | Option<**String**> | Mask of the sticker, optional for sticker. | |
413+
414+
### Return type
415+
416+
[**models::File**](File.md)
417+
418+
### Authorization
419+
420+
[authCookie](../README.md#authCookie)
421+
422+
### HTTP request headers
423+
424+
- **Content-Type**: multipart/form-data
425+
- **Accept**: application/json
426+
427+
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
428+

docs/GroupsApi.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ Name | Type | Description | Required | Notes
240240
> models::GroupAnnouncement create_group_announcement(group_id, create_group_announcement_request)
241241
Create Group Announcement
242242

243-
Creates an Announcement for a Group.
243+
Creates an Announcement for a Group. Warning: This will also remove all announcements. To make proper announcements, use the posts endpoint instead
244244

245245
### Parameters
246246

generate.sh

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ sed -i 's/Result<models::CurrentUser, Error<GetCurrentUserError>>/Result<models:
4242
# https://github.com/vrchatapi/vrchatapi-rust/pull/29
4343
sed -i "s/local_var_req_builder = local_var_req_builder.json(&\(.*\));/if let Some(\1) = \1 { \0 }/g" src/apis/files_api.rs
4444

45+
#https://github.com/vrchatapi/vrchatapi-rust/pull/30
46+
perl -0pi -e 's|(fn\s+[^(]*\([^)]*)file:\s+:?:?std::path::PathBuf,?([^)]*)((?:(?!\/\/ TODO: support file upload for '\''file'\'' parameter)[\s\S])*)\/\/ TODO: support file upload for '\''file'\'' parameter|\1file: impl Into<::std::borrow::Cow<'\''static, [u8]>>,\n\tfilename: impl Into<::std::borrow::Cow<'\''static, str>>,\n\tmime_type: &str,\2\3let part = reqwest::multipart::Part::bytes(file).file_name(filename).mime_str(mime_type)?;\n\tlocal_var_form = local_var_form.part("file", part);|g' src/apis/files_api.rs
47+
4548
cargo fmt
4649
cargo build
4750
cargo test

src/apis/files_api.rs

+169
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,27 @@ pub enum StartFileDataUploadError {
8787
UnknownValue(serde_json::Value),
8888
}
8989

90+
/// struct for typed errors of method [`upload_gallery_image`]
91+
#[derive(Debug, Clone, Serialize, Deserialize)]
92+
#[serde(untagged)]
93+
pub enum UploadGalleryImageError {
94+
UnknownValue(serde_json::Value),
95+
}
96+
97+
/// struct for typed errors of method [`upload_icon`]
98+
#[derive(Debug, Clone, Serialize, Deserialize)]
99+
#[serde(untagged)]
100+
pub enum UploadIconError {
101+
UnknownValue(serde_json::Value),
102+
}
103+
104+
/// struct for typed errors of method [`upload_image`]
105+
#[derive(Debug, Clone, Serialize, Deserialize)]
106+
#[serde(untagged)]
107+
pub enum UploadImageError {
108+
UnknownValue(serde_json::Value),
109+
}
110+
90111
/// Creates a new File object
91112
pub async fn create_file(
92113
configuration: &configuration::Configuration,
@@ -545,3 +566,151 @@ pub async fn start_file_data_upload(
545566
Err(Error::ResponseError(local_var_error))
546567
}
547568
}
569+
570+
/// Upload a gallery image
571+
pub async fn upload_gallery_image(
572+
configuration: &configuration::Configuration,
573+
file: impl Into<::std::borrow::Cow<'static, [u8]>>,
574+
filename: impl Into<::std::borrow::Cow<'static, str>>,
575+
mime_type: &str,
576+
) -> Result<models::File, Error<UploadGalleryImageError>> {
577+
let local_var_configuration = configuration;
578+
579+
let local_var_client = &local_var_configuration.client;
580+
581+
let local_var_uri_str = format!("{}/gallery", local_var_configuration.base_path);
582+
let mut local_var_req_builder =
583+
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
584+
585+
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
586+
local_var_req_builder =
587+
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
588+
}
589+
let mut local_var_form = reqwest::multipart::Form::new();
590+
let part = reqwest::multipart::Part::bytes(file)
591+
.file_name(filename)
592+
.mime_str(mime_type)?;
593+
local_var_form = local_var_form.part("file", part);
594+
local_var_req_builder = local_var_req_builder.multipart(local_var_form);
595+
596+
let local_var_req = local_var_req_builder.build()?;
597+
let local_var_resp = local_var_client.execute(local_var_req).await?;
598+
599+
let local_var_status = local_var_resp.status();
600+
let local_var_content = local_var_resp.text().await?;
601+
602+
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
603+
serde_json::from_str(&local_var_content).map_err(Error::from)
604+
} else {
605+
let local_var_entity: Option<UploadGalleryImageError> =
606+
serde_json::from_str(&local_var_content).ok();
607+
let local_var_error = ResponseContent {
608+
status: local_var_status,
609+
content: local_var_content,
610+
entity: local_var_entity,
611+
};
612+
Err(Error::ResponseError(local_var_error))
613+
}
614+
}
615+
616+
/// Upload an icon
617+
pub async fn upload_icon(
618+
configuration: &configuration::Configuration,
619+
file: impl Into<::std::borrow::Cow<'static, [u8]>>,
620+
filename: impl Into<::std::borrow::Cow<'static, str>>,
621+
mime_type: &str,
622+
) -> Result<models::File, Error<UploadIconError>> {
623+
let local_var_configuration = configuration;
624+
625+
let local_var_client = &local_var_configuration.client;
626+
627+
let local_var_uri_str = format!("{}/icon", local_var_configuration.base_path);
628+
let mut local_var_req_builder =
629+
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
630+
631+
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
632+
local_var_req_builder =
633+
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
634+
}
635+
let mut local_var_form = reqwest::multipart::Form::new();
636+
let part = reqwest::multipart::Part::bytes(file)
637+
.file_name(filename)
638+
.mime_str(mime_type)?;
639+
local_var_form = local_var_form.part("file", part);
640+
local_var_req_builder = local_var_req_builder.multipart(local_var_form);
641+
642+
let local_var_req = local_var_req_builder.build()?;
643+
let local_var_resp = local_var_client.execute(local_var_req).await?;
644+
645+
let local_var_status = local_var_resp.status();
646+
let local_var_content = local_var_resp.text().await?;
647+
648+
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
649+
serde_json::from_str(&local_var_content).map_err(Error::from)
650+
} else {
651+
let local_var_entity: Option<UploadIconError> =
652+
serde_json::from_str(&local_var_content).ok();
653+
let local_var_error = ResponseContent {
654+
status: local_var_status,
655+
content: local_var_content,
656+
entity: local_var_entity,
657+
};
658+
Err(Error::ResponseError(local_var_error))
659+
}
660+
}
661+
662+
/// Upload an image, which can be an icon, gallery image, sticker or emoji
663+
pub async fn upload_image(
664+
configuration: &configuration::Configuration,
665+
file: impl Into<::std::borrow::Cow<'static, [u8]>>,
666+
filename: impl Into<::std::borrow::Cow<'static, str>>,
667+
mime_type: &str,
668+
tag: &str,
669+
animation_style: Option<&str>,
670+
mask_tag: Option<&str>,
671+
) -> Result<models::File, Error<UploadImageError>> {
672+
let local_var_configuration = configuration;
673+
674+
let local_var_client = &local_var_configuration.client;
675+
676+
let local_var_uri_str = format!("{}/file/image", local_var_configuration.base_path);
677+
let mut local_var_req_builder =
678+
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
679+
680+
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
681+
local_var_req_builder =
682+
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
683+
}
684+
let mut local_var_form = reqwest::multipart::Form::new();
685+
let part = reqwest::multipart::Part::bytes(file)
686+
.file_name(filename)
687+
.mime_str(mime_type)?;
688+
local_var_form = local_var_form.part("file", part);
689+
local_var_form = local_var_form.text("tag", tag.to_string());
690+
if let Some(local_var_param_value) = animation_style {
691+
local_var_form = local_var_form.text("animationStyle", local_var_param_value.to_string());
692+
}
693+
if let Some(local_var_param_value) = mask_tag {
694+
local_var_form = local_var_form.text("maskTag", local_var_param_value.to_string());
695+
}
696+
local_var_req_builder = local_var_req_builder.multipart(local_var_form);
697+
698+
let local_var_req = local_var_req_builder.build()?;
699+
let local_var_resp = local_var_client.execute(local_var_req).await?;
700+
701+
let local_var_status = local_var_resp.status();
702+
let local_var_content = local_var_resp.text().await?;
703+
704+
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
705+
serde_json::from_str(&local_var_content).map_err(Error::from)
706+
} else {
707+
let local_var_entity: Option<UploadImageError> =
708+
serde_json::from_str(&local_var_content).ok();
709+
let local_var_error = ResponseContent {
710+
status: local_var_status,
711+
content: local_var_content,
712+
entity: local_var_entity,
713+
};
714+
Err(Error::ResponseError(local_var_error))
715+
}
716+
}

src/apis/groups_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ pub async fn create_group(
658658
}
659659
}
660660

661-
/// Creates an Announcement for a Group.
661+
/// Creates an Announcement for a Group. Warning: This will also remove all announcements. To make proper announcements, use the posts endpoint instead
662662
pub async fn create_group_announcement(
663663
configuration: &configuration::Configuration,
664664
group_id: &str,

src/models/avatar.rs

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ pub struct Avatar {
3737
pub name: String,
3838
#[serde(rename = "releaseStatus")]
3939
pub release_status: models::ReleaseStatus,
40+
#[serde(rename = "styles")]
41+
pub styles: models::AvatarStyles,
4042
#[serde(rename = "tags")]
4143
pub tags: Vec<String>,
4244
#[serde(rename = "thumbnailImageUrl")]
@@ -64,6 +66,7 @@ impl Avatar {
6466
image_url: String,
6567
name: String,
6668
release_status: models::ReleaseStatus,
69+
styles: models::AvatarStyles,
6770
tags: Vec<String>,
6871
thumbnail_image_url: String,
6972
unity_package_url: String,
@@ -84,6 +87,7 @@ impl Avatar {
8487
image_url,
8588
name,
8689
release_status,
90+
styles,
8791
tags,
8892
thumbnail_image_url,
8993
unity_package_url,

0 commit comments

Comments
 (0)