//----------------------
//
// Generated using the NSwag toolchain v14.0.3.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0)) (http://NSwag.org)
//
//----------------------
/* tslint:disable */
/* eslint-disable */
// ReSharper disable InconsistentNaming
export class UploaderClient {
private http: { fetch(url: RequestInfo, init?: RequestInit): Promise };
private baseUrl: string;
protected jsonParseReviver: ((key: string, value: any) => any) | undefined = undefined;
constructor(baseUrl?: string, http?: { fetch(url: RequestInfo, init?: RequestInit): Promise }) {
this.http = http ? http : window as any;
this.baseUrl = baseUrl ?? "https://localhost:6001";
}
getMediaById(mediaId: string): Promise {
let url_ = this.baseUrl + "/umbraco/backoffice/api/Uploader/media/{mediaId}";
if (mediaId === undefined || mediaId === null)
throw new Error("The parameter 'mediaId' must be defined.");
url_ = url_.replace("{mediaId}", encodeURIComponent("" + mediaId));
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processGetMediaById(_response);
});
}
protected processGetMediaById(response: Response): Promise {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as FileMedia;
return result200;
});
} else if (status === 400) {
return response.text().then((_responseText) => {
let result400: any = null;
result400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as ProblemDetails;
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status === 500) {
return response.text().then((_responseText) => {
return throwException("A server side error occurred.", status, _responseText, _headers);
});
} else if (status === 404) {
return response.text().then((_responseText) => {
let result404: any = null;
result404 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as ProblemDetails;
return throwException("A server side error occurred.", status, _responseText, _headers, result404);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve(null as any);
}
upload(allowedExtensions: string | null | undefined, imagesOnly: boolean | null | undefined, maxFileSizeMb: number | null | undefined, maxHeight: number | null | undefined, maxWidth: number | null | undefined, minHeight: number | null | undefined, minWidth: number | null | undefined, file: FileParameter | null | undefined): Promise {
let url_ = this.baseUrl + "/umbraco/backoffice/api/Uploader/upload";
url_ = url_.replace(/[?&]$/, "");
const content_ = new FormData();
if (allowedExtensions !== null && allowedExtensions !== undefined)
content_.append("AllowedExtensions", allowedExtensions.toString());
if (imagesOnly !== null && imagesOnly !== undefined)
content_.append("ImagesOnly", imagesOnly.toString());
if (maxFileSizeMb !== null && maxFileSizeMb !== undefined)
content_.append("MaxFileSizeMb", maxFileSizeMb.toString());
if (maxHeight !== null && maxHeight !== undefined)
content_.append("MaxHeight", maxHeight.toString());
if (maxWidth !== null && maxWidth !== undefined)
content_.append("MaxWidth", maxWidth.toString());
if (minHeight !== null && minHeight !== undefined)
content_.append("MinHeight", minHeight.toString());
if (minWidth !== null && minWidth !== undefined)
content_.append("MinWidth", minWidth.toString());
if (file !== null && file !== undefined)
content_.append("File", file.data, file.fileName ? file.fileName : "File");
let options_: RequestInit = {
body: content_,
method: "POST",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processUpload(_response);
});
}
protected processUpload(response: Response): Promise {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as FileMedia;
return result200;
});
} else if (status === 400) {
return response.text().then((_responseText) => {
let result400: any = null;
result400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as ProblemDetails;
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status === 500) {
return response.text().then((_responseText) => {
return throwException("A server side error occurred.", status, _responseText, _headers);
});
} else if (status === 412) {
return response.text().then((_responseText) => {
let result412: any = null;
result412 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as ProblemDetails;
return throwException("A server side error occurred.", status, _responseText, _headers, result412);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve(null as any);
}
getResponse(storagePath: string | null | undefined, filesizeBytes: number | undefined): Promise {
let url_ = this.baseUrl + "/umbraco/backoffice/api/Uploader?";
if (storagePath !== undefined && storagePath !== null)
url_ += "storagePath=" + encodeURIComponent("" + storagePath) + "&";
if (filesizeBytes === null)
throw new Error("The parameter 'filesizeBytes' cannot be null.");
else if (filesizeBytes !== undefined)
url_ += "filesizeBytes=" + encodeURIComponent("" + filesizeBytes) + "&";
url_ = url_.replace(/[?&]$/, "");
let options_: RequestInit = {
method: "GET",
headers: {
"Accept": "application/json"
}
};
return this.http.fetch(url_, options_).then((_response: Response) => {
return this.processGetResponse(_response);
});
}
protected processGetResponse(response: Response): Promise {
const status = response.status;
let _headers: any = {}; if (response.headers && response.headers.forEach) { response.headers.forEach((v: any, k: any) => _headers[k] = v); };
if (status === 200) {
return response.text().then((_responseText) => {
let result200: any = null;
result200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as FileMedia;
return result200;
});
} else if (status === 400) {
return response.text().then((_responseText) => {
let result400: any = null;
result400 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver) as ProblemDetails;
return throwException("A server side error occurred.", status, _responseText, _headers, result400);
});
} else if (status === 500) {
return response.text().then((_responseText) => {
return throwException("A server side error occurred.", status, _responseText, _headers);
});
} else if (status !== 200 && status !== 204) {
return response.text().then((_responseText) => {
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
});
}
return Promise.resolve(null as any);
}
}
export interface FileMedia {
urlPath?: string | undefined;
mediaId?: string | undefined;
filename?: string | undefined;
extension?: string | undefined;
sizeMb?: number;
}
export interface ProblemDetails {
type?: string | undefined;
title?: string | undefined;
status?: number | undefined;
detail?: string | undefined;
instance?: string | undefined;
[key: string]: any;
}
export interface FileParameter {
data: any;
fileName: string;
}
export class ApiException extends Error {
message: string;
status: number;
response: string;
headers: { [key: string]: any; };
result: any;
constructor(message: string, status: number, response: string, headers: { [key: string]: any; }, result: any) {
super();
this.message = message;
this.status = status;
this.response = response;
this.headers = headers;
this.result = result;
}
protected isApiException = true;
static isApiException(obj: any): obj is ApiException {
return obj.isApiException === true;
}
}
function throwException(message: string, status: number, response: string, headers: { [key: string]: any; }, result?: any): any {
if (result !== null && result !== undefined)
throw result;
else
throw new ApiException(message, status, response, headers, null);
}