feat: implement getFileById method

This commit is contained in:
StevanFreeborn
2023-02-06 21:28:11 -06:00
parent fac2367052
commit 04e1ebdf8d
8 changed files with 718 additions and 101 deletions
+37
View File
@@ -1,8 +1,10 @@
import { type AxiosResponse } from 'axios';
import { FieldType } from '../enums/FieldType';
import { App } from './App';
import { CollectionResponse } from './CollectionResponse';
import { CreatedWithIdResponse } from './CreatedWithIdResponse';
import { Field } from './Field';
import { File } from './File';
import { FileInfo } from './FileInfo';
import { FormulaField } from './FormulaField';
import { GetPagedAppsResponse } from './GetPagedAppsResponse';
@@ -221,6 +223,41 @@ export class ApiResponse<T> {
);
}
public asFileType(response: AxiosResponse): ApiResponse<File> {
const apiResponse = this as ApiResponse<any>;
let fileName = response.headers['content-disposition']
.split(';')[1]
.split('=')[1];
fileName = fileName.substring(1, fileName.length - 1);
const contentType =
response.headers['content-type'] ??
response.headers['Content-Type'] ??
null;
let contentLength =
response.headers['content-length'] ??
response.headers['Content-Length'] ??
0;
contentLength = parseInt(contentLength);
const file = new File(
apiResponse.data,
fileName,
contentType,
contentLength
);
return new ApiResponse<File>(
apiResponse.statusCode,
apiResponse.message,
file
);
}
/**
* @method asFileCollectionType - Converts the field item to the appropriate field object based upon the field item's type.
* @param fieldItem - The field item to convert.