From 07ff30b47860cb3fb4dcfde0ea75839cd4dba199 Mon Sep 17 00:00:00 2001 From: jellejurre Date: Tue, 12 Nov 2024 17:04:33 +0100 Subject: [PATCH] Add multipart content support --- api.ts | 256 +++++++++++++++++++++++++++++++++++++++++++++++++++ generate.sh | 6 +- package.json | 1 + 3 files changed, 262 insertions(+), 1 deletion(-) diff --git a/api.ts b/api.ts index 3e84496..0c6d8a7 100644 --- a/api.ts +++ b/api.ts @@ -20,6 +20,11 @@ import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObj // @ts-ignore import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } from './base'; import axiosCookieJarSupport from "axios-cookiejar-support";axiosCookieJarSupport(globalAxios);import { CookieJar } from "tough-cookie";globalAxios.defaults.jar = new CookieJar();globalAxios.defaults.withCredentials = true; +let formData = require("form-data"); +type File = { + name: string, + data: Buffer +} /** * @@ -11223,6 +11228,149 @@ export const FilesApiAxiosParamCreator = function (configuration?: Configuration let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @summary Upload gallery image + * @param {File} file The binary blob of the png file. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + uploadGalleryImage: async (file: File, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'file' is not null or undefined + assertParamExists('uploadGalleryImage', 'file', file) + const localVarPath = `/gallery`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + const localVarFormParams = new formData(); + + + if (file !== undefined) { + localVarFormParams.append('file', file.data, { filename: file.name, contentType: file.name.endsWith('.png') ? 'image/png' : 'application/octet-stream' }); + } + + + localVarHeaderParameter['Content-Type'] = 'multipart/form-data'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = localVarFormParams.getBuffer(); +localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers, ...localVarFormParams.getHeaders()}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @summary Upload icon + * @param {File} file The binary blob of the png file. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + uploadIcon: async (file: File, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'file' is not null or undefined + assertParamExists('uploadIcon', 'file', file) + const localVarPath = `/icon`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + const localVarFormParams = new formData(); + + + if (file !== undefined) { + localVarFormParams.append('file', file.data, { filename: file.name, contentType: file.name.endsWith('.png') ? 'image/png' : 'application/octet-stream' }); + } + + + localVarHeaderParameter['Content-Type'] = 'multipart/form-data'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = localVarFormParams.getBuffer(); +localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers, ...localVarFormParams.getHeaders()}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * + * @summary Upload gallery image, icon, emoji or sticker + * @param {File} file The binary blob of the png file. + * @param {string} tag Needs to be either icon, gallery, sticker or emoji + * @param {string} [animationStyle] Animation style for sticker, required for sticker. + * @param {string} [maskTag] Mask of the sticker, optional for sticker. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + uploadImage: async (file: File, tag: string, animationStyle?: string, maskTag?: string, options: AxiosRequestConfig = {}): Promise => { + // verify required parameter 'file' is not null or undefined + assertParamExists('uploadImage', 'file', file) + // verify required parameter 'tag' is not null or undefined + assertParamExists('uploadImage', 'tag', tag) + const localVarPath = `/file/image`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + const localVarFormParams = new formData(); + + + if (file !== undefined) { + localVarFormParams.append('file', file.data, { filename: file.name, contentType: file.name.endsWith('.png') ? 'image/png' : 'application/octet-stream' }); + } + + if (tag !== undefined) { + localVarFormParams.append('tag', tag as any); + } + + if (animationStyle !== undefined) { + localVarFormParams.append('animationStyle', animationStyle as any); + } + + if (maskTag !== undefined) { + localVarFormParams.append('maskTag', maskTag as any); + } + + + localVarHeaderParameter['Content-Type'] = 'multipart/form-data'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = localVarFormParams.getBuffer(); +localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers, ...localVarFormParams.getHeaders()}; + return { url: toPathString(localVarUrlObj), options: localVarRequestOptions, @@ -11362,6 +11510,42 @@ export const FilesApiFp = function(configuration?: Configuration) { const localVarAxiosArgs = await localVarAxiosParamCreator.startFileDataUpload(fileId, versionId, fileType, partNumber, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, + /** + * + * @summary Upload gallery image + * @param {File} file The binary blob of the png file. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async uploadGalleryImage(file: File, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.uploadGalleryImage(file, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, + /** + * + * @summary Upload icon + * @param {File} file The binary blob of the png file. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async uploadIcon(file: File, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.uploadIcon(file, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, + /** + * + * @summary Upload gallery image, icon, emoji or sticker + * @param {File} file The binary blob of the png file. + * @param {string} tag Needs to be either icon, gallery, sticker or emoji + * @param {string} [animationStyle] Animation style for sticker, required for sticker. + * @param {string} [maskTag] Mask of the sticker, optional for sticker. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async uploadImage(file: File, tag: string, animationStyle?: string, maskTag?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.uploadImage(file, tag, animationStyle, maskTag, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, } }; @@ -11486,6 +11670,39 @@ export const FilesApiFactory = function (configuration?: Configuration, basePath startFileDataUpload(fileId: string, versionId: number, fileType: 'file' | 'signature' | 'delta', partNumber?: number, options?: any): AxiosPromise { return localVarFp.startFileDataUpload(fileId, versionId, fileType, partNumber, options).then((request) => request(axios, basePath)); }, + /** + * + * @summary Upload gallery image + * @param {File} file The binary blob of the png file. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + uploadGalleryImage(file: File, options?: any): AxiosPromise { + return localVarFp.uploadGalleryImage(file, options).then((request) => request(axios, basePath)); + }, + /** + * + * @summary Upload icon + * @param {File} file The binary blob of the png file. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + uploadIcon(file: File, options?: any): AxiosPromise { + return localVarFp.uploadIcon(file, options).then((request) => request(axios, basePath)); + }, + /** + * + * @summary Upload gallery image, icon, emoji or sticker + * @param {File} file The binary blob of the png file. + * @param {string} tag Needs to be either icon, gallery, sticker or emoji + * @param {string} [animationStyle] Animation style for sticker, required for sticker. + * @param {string} [maskTag] Mask of the sticker, optional for sticker. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + uploadImage(file: File, tag: string, animationStyle?: string, maskTag?: string, options?: any): AxiosPromise { + return localVarFp.uploadImage(file, tag, animationStyle, maskTag, options).then((request) => request(axios, basePath)); + }, }; }; @@ -11629,6 +11846,45 @@ export class FilesApi extends BaseAPI { public startFileDataUpload(fileId: string, versionId: number, fileType: 'file' | 'signature' | 'delta', partNumber?: number, options?: AxiosRequestConfig) { return FilesApiFp(this.configuration).startFileDataUpload(fileId, versionId, fileType, partNumber, options).then((request) => request(this.axios, this.basePath)); } + + /** + * + * @summary Upload gallery image + * @param {File} file The binary blob of the png file. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof FilesApi + */ + public uploadGalleryImage(file: File, options?: AxiosRequestConfig) { + return FilesApiFp(this.configuration).uploadGalleryImage(file, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * + * @summary Upload icon + * @param {File} file The binary blob of the png file. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof FilesApi + */ + public uploadIcon(file: File, options?: AxiosRequestConfig) { + return FilesApiFp(this.configuration).uploadIcon(file, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * + * @summary Upload gallery image, icon, emoji or sticker + * @param {File} file The binary blob of the png file. + * @param {string} tag Needs to be either icon, gallery, sticker or emoji + * @param {string} [animationStyle] Animation style for sticker, required for sticker. + * @param {string} [maskTag] Mask of the sticker, optional for sticker. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof FilesApi + */ + public uploadImage(file: File, tag: string, animationStyle?: string, maskTag?: string, options?: AxiosRequestConfig) { + return FilesApiFp(this.configuration).uploadImage(file, tag, animationStyle, maskTag, options).then((request) => request(this.axios, this.basePath)); + } } diff --git a/generate.sh b/generate.sh index 9a4bce7..fbf4a43 100755 --- a/generate.sh +++ b/generate.sh @@ -18,12 +18,16 @@ sed -i 's/OpenAPI client for vrchat/🟡🔵 VRChat API Library for JavaScript a sed -i 's/Unlicense/MIT/g' ./package.json # Enable global cookies -sed -i '/^import { BASE_PATH/a import axiosCookieJarSupport from "axios-cookiejar-support";axiosCookieJarSupport(globalAxios);import { CookieJar } from "tough-cookie";globalAxios.defaults.jar = new CookieJar();globalAxios.defaults.withCredentials = true;' ./api.ts +sed -i '/^import { BASE_PATH/a import axiosCookieJarSupport from "axios-cookiejar-support";axiosCookieJarSupport(globalAxios);import { CookieJar } from "tough-cookie";globalAxios.defaults.jar = new CookieJar();globalAxios.defaults.withCredentials = true;\nlet formData = require("form-data");\ntype File = {\n\tname: string,\n\tdata: Buffer\n}' ./api.ts sed -i '/"dependencies"/a "@types/tough-cookie": "^4.0.1",' ./package.json sed -i '/"dependencies"/a "axios-cookiejar-support": "^1.0.1",' ./package.json sed -i '/"dependencies"/a "tough-cookie": "^4.0.0",' ./package.json +sed -i '/"dependencies"/a "form-data": "^4.0.1",' ./package.json +sed -i 's/const localVarFormParams = new ((configuration && configuration.formDataCtor) || FormData)();/const localVarFormParams = new formData();/' ./api.ts +sed -i "s/localVarFormParams.append('file', file as any);/localVarFormParams.append('file', file.data, { filename: file.name, contentType: file.name.endsWith('.png') ? 'image\/png' : 'application\/octet-stream' });/" ./api.ts +sed -i 's/localVarRequestOptions.data = localVarFormParams;/localVarRequestOptions.data = localVarFormParams.getBuffer();\nlocalVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers, ...localVarFormParams.getHeaders()};/' ./api.ts # Remove messily pasted markdown at top of every file for i in *.ts; do sed -i '/VRChat API Banner/d' $i diff --git a/package.json b/package.json index 02695ac..8067d82 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "prepare": "npm run build" }, "dependencies": { +"form-data": "^4.0.1", "tough-cookie": "^4.0.0", "axios-cookiejar-support": "^1.0.1", "@types/tough-cookie": "^4.0.1",