Untitled

mail@pastecode.io avatar
unknown
typescript
3 years ago
4.0 kB
2
Indexable
Never
/* tslint:disable */
/* eslint-disable */
/**
 * OpenAPI postoplan
 * postoplan api
 *
 * The version of the OpenAPI document: 1.0.0
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


import * as runtime from '../runtime';
import {
    MediaUploadResponse,
    MediaUploadResponseFromJSON,
    MediaUploadResponseToJSON,
    Result,
    ResultFromJSON,
    ResultToJSON,
} from '../models';

export interface MediaDeleteRequest {
    id: number;
}

export interface MediaUploadRequest {
    file: Blob;
}

/**
 * 
 */
export class MediaApi extends runtime.BaseAPI {

    /**
     * Delete media
     */
    async mediaDeleteRaw(requestParameters: MediaDeleteRequest): Promise<runtime.ApiResponse<Result>> {
        if (requestParameters.id === null || requestParameters.id === undefined) {
            throw new runtime.RequiredError('id','Required parameter requestParameters.id was null or undefined when calling mediaDelete.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.apiKey) {
            headerParameters["api-token"] = this.configuration.apiKey("api-token"); // api-token authentication
        }

        const response = await this.request({
            path: `/media/delete/{id}`.replace(`{${"id"}}`, encodeURIComponent(String(requestParameters.id))),
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
        });

        return new runtime.JSONApiResponse(response, (jsonValue) => ResultFromJSON(jsonValue));
    }

    /**
     * Delete media
     */
    async mediaDelete(requestParameters: MediaDeleteRequest): Promise<Result> {
        const response = await this.mediaDeleteRaw(requestParameters);
        return await response.value();
    }

    /**
     * Upload media file
     */
    async mediaUploadRaw(requestParameters: MediaUploadRequest): Promise<runtime.ApiResponse<MediaUploadResponse>> {
        if (requestParameters.file === null || requestParameters.file === undefined) {
            throw new runtime.RequiredError('file','Required parameter requestParameters.file was null or undefined when calling mediaUpload.');
        }

        const queryParameters: any = {};

        const headerParameters: runtime.HTTPHeaders = {};

        if (this.configuration && this.configuration.apiKey) {
            headerParameters["api-token"] = this.configuration.apiKey("api-token"); // api-token authentication
        }

        const consumes: runtime.Consume[] = [
            { contentType: 'multipart/form-data' },
        ];
        // @ts-ignore: canConsumeForm may be unused
        const canConsumeForm = runtime.canConsumeForm(consumes);

        let formParams: { append(param: string, value: any): any };
        let useForm = false;
        // use FormData to transmit files using content-type "multipart/form-data"
        useForm = canConsumeForm;
        if (useForm) {
            formParams = new FormData();
        } else {
            formParams = new URLSearchParams();
        }

        if (requestParameters.file !== undefined) {
            formParams.append('file', requestParameters.file as any);
        }

        const response = await this.request({
            path: `/media/upload`,
            method: 'POST',
            headers: headerParameters,
            query: queryParameters,
            body: formParams,
        });

        return new runtime.JSONApiResponse(response, (jsonValue) => MediaUploadResponseFromJSON(jsonValue));
    }

    /**
     * Upload media file
     */
    async mediaUpload(requestParameters: MediaUploadRequest): Promise<MediaUploadResponse> {
        const response = await this.mediaUploadRaw(requestParameters);
        return await response.value();
    }

}