Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for image uploads #26

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion vrchat_dart/tool/patch_output.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,30 @@ void patchApi() {
.whereType<File>();

for (final file in apiFiles) {
final content = file.readAsStringSync();
var content = file.readAsStringSync();

if (file.path.contains('files_api.dart')) {
content = content
.patchMultipartUpload(
path: '/file/image',
bodyData: '''
FormData.fromMap({
'file': file,
'tag': tag,
if (animationStyle != null) 'animationStyle': animationStyle,
if (maskTag != null) 'maskTag': maskTag,
});''',
)
.patchMultipartUpload(
path: '/icon',
bodyData: "FormData.fromMap({'file': file});",
)
.patchMultipartUpload(
path: '/gallery',
bodyData: "FormData.fromMap({'file': file});",
);
}

file.writeAsStringSync(content);
}
}
Expand Down Expand Up @@ -157,3 +180,20 @@ void patchAnalysisIssues() {
file.writeAsStringSync(contents);
}
}

extension on String {
String patchMultipartUpload({
required String path,
required String bodyData,
}) {
final escapedPath = RegExp.escape(path);
final tabbedBodyData = bodyData.replaceAll('\n', '\n ');
return replaceFirstMapped(
RegExp("final _path = r'$escapedPath';(.+?)try {}", dotAll: true),
(m) => '''
final _path = r'$path';${m[1]}try {
_bodyData = $tabbedBodyData
}''',
);
}
}
3 changes: 3 additions & 0 deletions vrchat_dart_generated/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ Class | Method | HTTP request | Description
[*FilesApi*](doc/FilesApi.md) | [**getFileDataUploadStatus**](doc/FilesApi.md#getfiledatauploadstatus) | **GET** /file/{fileId}/{versionId}/{fileType}/status | Check FileData Upload Status
[*FilesApi*](doc/FilesApi.md) | [**getFiles**](doc/FilesApi.md#getfiles) | **GET** /files | List Files
[*FilesApi*](doc/FilesApi.md) | [**startFileDataUpload**](doc/FilesApi.md#startfiledataupload) | **PUT** /file/{fileId}/{versionId}/{fileType}/start | Start FileData Upload
[*FilesApi*](doc/FilesApi.md) | [**uploadGalleryImage**](doc/FilesApi.md#uploadgalleryimage) | **POST** /gallery | Upload gallery image
[*FilesApi*](doc/FilesApi.md) | [**uploadIcon**](doc/FilesApi.md#uploadicon) | **POST** /icon | Upload icon
[*FilesApi*](doc/FilesApi.md) | [**uploadImage**](doc/FilesApi.md#uploadimage) | **POST** /file/image | Upload gallery image, icon, emoji or sticker
[*FriendsApi*](doc/FriendsApi.md) | [**deleteFriendRequest**](doc/FriendsApi.md#deletefriendrequest) | **DELETE** /user/{userId}/friendRequest | Delete Friend Request
[*FriendsApi*](doc/FriendsApi.md) | [**friend**](doc/FriendsApi.md#friend) | **POST** /user/{userId}/friendRequest | Send Friend Request
[*FriendsApi*](doc/FriendsApi.md) | [**getFriendStatus**](doc/FriendsApi.md#getfriendstatus) | **GET** /user/{userId}/friendStatus | Check Friend Status
Expand Down
2 changes: 2 additions & 0 deletions vrchat_dart_generated/doc/File.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import 'package:vrchat_dart_generated/api.dart';
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**animationStyle** | **String** | | [optional]
**maskTag** | **String** | | [optional]
**extension_** | **String** | |
**id** | **String** | |
**mimeType** | [**MIMEType**](MIMEType.md) | |
Expand Down
150 changes: 150 additions & 0 deletions vrchat_dart_generated/doc/FilesApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Method | HTTP request | Description
[**getFileDataUploadStatus**](FilesApi.md#getfiledatauploadstatus) | **GET** /file/{fileId}/{versionId}/{fileType}/status | Check FileData Upload Status
[**getFiles**](FilesApi.md#getfiles) | **GET** /files | List Files
[**startFileDataUpload**](FilesApi.md#startfiledataupload) | **PUT** /file/{fileId}/{versionId}/{fileType}/start | Start FileData Upload
[**uploadGalleryImage**](FilesApi.md#uploadgalleryimage) | **POST** /gallery | Upload gallery image
[**uploadIcon**](FilesApi.md#uploadicon) | **POST** /icon | Upload icon
[**uploadImage**](FilesApi.md#uploadimage) | **POST** /file/image | Upload gallery image, icon, emoji or sticker


# **createFile**
Expand Down Expand Up @@ -518,3 +521,150 @@ Name | Type | Description | Notes

[[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)

# **uploadGalleryImage**
> File uploadGalleryImage(file)

Upload gallery image

Upload a gallery image

### Example
```dart
import 'package:vrchat_dart_generated/api.dart';
// TODO Configure API key authorization: authCookie
//defaultApiClient.getAuthentication<ApiKeyAuth>('authCookie').apiKey = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//defaultApiClient.getAuthentication<ApiKeyAuth>('authCookie').apiKeyPrefix = 'Bearer';

final api = VrchatDartGenerated().getFilesApi();
final MultipartFile file = BINARY_DATA_HERE; // MultipartFile | The binary blob of the png file.

try {
final response = api.uploadGalleryImage(file);
print(response);
} catch on DioException (e) {
print('Exception when calling FilesApi->uploadGalleryImage: $e\n');
}
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**file** | **MultipartFile**| The binary blob of the png file. |

### Return type

[**File**](File.md)

### Authorization

[authCookie](../README.md#authCookie)

### HTTP request headers

- **Content-Type**: multipart/form-data
- **Accept**: application/json

[[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)

# **uploadIcon**
> File uploadIcon(file)

Upload icon

Upload an icon

### Example
```dart
import 'package:vrchat_dart_generated/api.dart';
// TODO Configure API key authorization: authCookie
//defaultApiClient.getAuthentication<ApiKeyAuth>('authCookie').apiKey = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//defaultApiClient.getAuthentication<ApiKeyAuth>('authCookie').apiKeyPrefix = 'Bearer';

final api = VrchatDartGenerated().getFilesApi();
final MultipartFile file = BINARY_DATA_HERE; // MultipartFile | The binary blob of the png file.

try {
final response = api.uploadIcon(file);
print(response);
} catch on DioException (e) {
print('Exception when calling FilesApi->uploadIcon: $e\n');
}
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**file** | **MultipartFile**| The binary blob of the png file. |

### Return type

[**File**](File.md)

### Authorization

[authCookie](../README.md#authCookie)

### HTTP request headers

- **Content-Type**: multipart/form-data
- **Accept**: application/json

[[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)

# **uploadImage**
> File uploadImage(file, tag, animationStyle, maskTag)

Upload gallery image, icon, emoji or sticker

Upload an image, which can be an icon, gallery image, sticker or emoji

### Example
```dart
import 'package:vrchat_dart_generated/api.dart';
// TODO Configure API key authorization: authCookie
//defaultApiClient.getAuthentication<ApiKeyAuth>('authCookie').apiKey = 'YOUR_API_KEY';
// uncomment below to setup prefix (e.g. Bearer) for API key, if needed
//defaultApiClient.getAuthentication<ApiKeyAuth>('authCookie').apiKeyPrefix = 'Bearer';

final api = VrchatDartGenerated().getFilesApi();
final MultipartFile file = BINARY_DATA_HERE; // MultipartFile | The binary blob of the png file.
final String tag = tag_example; // String | Needs to be either icon, gallery, sticker or emoji
final String animationStyle = animationStyle_example; // String | Animation style for sticker, required for sticker.
final String maskTag = maskTag_example; // String | Mask of the sticker, optional for sticker.

try {
final response = api.uploadImage(file, tag, animationStyle, maskTag);
print(response);
} catch on DioException (e) {
print('Exception when calling FilesApi->uploadImage: $e\n');
}
```

### Parameters

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**file** | **MultipartFile**| The binary blob of the png file. |
**tag** | **String**| Needs to be either icon, gallery, sticker or emoji |
**animationStyle** | **String**| Animation style for sticker, required for sticker. | [optional]
**maskTag** | **String**| Mask of the sticker, optional for sticker. | [optional]

### Return type

[**File**](File.md)

### Authorization

[authCookie](../README.md#authCookie)

### HTTP request headers

- **Content-Type**: multipart/form-data
- **Accept**: application/json

[[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)

Loading