feat: implement getFileById method
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user