Simone 442516adad
chore: migrate media-library components to Typescript (#21622)
* chore: migrate to TS AudoPreview component

* chore: migrate to TS PaginationContext component

* chore: migrate to TS Pagination component

* chore: migrate to TS PaginationFolder components

* chore: migrate to TS PaginationFooter index component

* chore: migrate to TS isSelectable util

* chore: migrate to TS PageSize component

* chore: migrate to TS DialogFooter component

* chore: migrate to TS Draggable component

* chore: migrate to TS ContextInfo component

* chore: migrate to TS ContextInfo test and index component

* chore: migrate to TS PreviewBox components file

* chore: migrate to TS DialogHeader component

* chore: migrate to TS RemoveFolderDialog

* chore: migrate to TS EmptyAssetGrid

* chore: migrate to TS EmptyAssets index file

* chore: migrate to TS AssetCardBase

* chore: migrate to TS AudioAssetCard component

* chore: migrate to TS DocAssetCard component

* chore: migrate to TS ImageAssetCard component

* chore: migrate to TS AssetCard unit tests

* chore: migrate to TS SearchAsset component

* chore: migrate to TS UploadProgress component

* chore: migrate to TS FromComputerForm component

* chore: migrate to TS FromUrlForm component

* chore: migrate to TS AddAssetStep component

* chore: migrate to TS VideoPreview component

* chore: migrate to TS VideoAssetCard component

* chore: migrate to TS UploadingAssetCard component

* chore: migrate to TS PreviewCell component

* chore: migrate to TS CellContent component

* chore: migrate to TS TableRows component

* chore: migrate to TS TableList component

* chore: migrate to TS SortPicker component

* chore: migrate to TS Option component with utils

* chore: migrate to TS EmptyStateAsset and CarouselAsset

* chore: migrate to TS CopyLinkButton component

* chore: migrate to TS CarouselAssetActions component

* chore: migrate to TS FolderGridList component

* chore: migrate to TS FolderCardContext

* chore: migrate to TS FolderCard component

* chore: migrate to TS FolderCardBody component

* chore: migrate to TS FolderCardBodyAction component

* chore: migrate to TS FolderCardCheckbox component

* chore: migrate to TS FolderCard unit test

* chore: migrate to TS getFilterList

* chore: migrate to TS FilterValueInput component

* chore: migrate to TS FilterTag

* chore: migrate to TS FilterList

* chore: migrate to TS EditFolderModalHeader component

* chore: migrate to TS AssetPreview component

* chore: migrate to TS CroppingActions component

* chore: migrate to TS RemoveAssetDialog component

* chore: migrate to TS ReplaceMediaButton component

* chore: migrate to TS AssetCard component

* chore: migrate to TS AssetGridList

* chore: migrate to TS PendingAssetStep component

* chore: migrate to TS SelectedStep component

* chore: migrate to TS PreviewBox component

* chore: migrate to TS SelectTree

* chore: migrate to TS SelectTree unit test

* chore: migrate to TS BulkMoveDialog

* chore: migrate to TS EditFolderContent component

* chore: migrate to TS FilterValueInput

* chore: migrato to TS CrumbSimpleMenuAsync

* chore: migrate to TS Breadcrumbs

* chore: migrate to TS Filters component

* chore: migrate to TS EditAssetDialog

* chore: migrate to TS CarouselAssets

* chore: migrate to TS UploadAssetDialog and BrowseStep

* chore: migrate to TS BrowseStep test

* chore: migrate to TS AssetDialog component

* chore: migrate to TS MediaLibraryDialog component

* chore: migrate to TS MediaLibraryDialog component

* chore: remove a useless type guard

* chore: fix small stuff

* chore: fix BulkMoveDialog unit test

* chore: fix some types

* chore: fix prettier problems

* chore: fix review's comments

* chore: fix review comments
2024-10-31 10:00:13 +01:00

237 lines
4.6 KiB
TypeScript

import { errors } from '@strapi/utils';
type SortOrder = 'ASC' | 'DESC';
type SortKey = 'createdAt' | 'name' | 'updatedAt';
// Abstract type for comparison operators where the keys are generic strings
type ComparisonOperators<T> = {
[operator: string]: T | T[] | boolean; // Any string can be used as an operator key
};
// Abstract type for filter conditions with dynamic field names
export type FilterCondition<T> = {
[field: string]: T | ComparisonOperators<T> | FilterCondition<T>; // Field names are dynamic and values are comparison operators
};
// Abstract type for filters where the logical operator (like $and) is a generic string
type Filters<T> = {
[logicOperator: string]: FilterCondition<T>[]; // Logical operator key is a generic string
};
export type Query = {
_q?: string;
folderPath?: string;
folder?:
| null
| number
| {
id: number;
};
page?:
| string
| number
| {
id: string | number;
};
pageSize?: string | number;
pagination?: {
pageSize: number;
};
sort?: `${SortKey}:${SortOrder}`;
filters?: Filters<string | number | boolean>;
state?: boolean;
};
type FileFormat = {
name: string;
hash: string;
ext: string;
mime: string;
path: null | string;
width: number;
height: number;
size: number;
sizeInBytes: number;
url: string;
};
export interface File {
id: number;
name: string;
alternativeText?: string | null;
caption?: string | null;
width?: number | null;
height?: number | null;
formats?:
| Record<string, FileFormat>
| {
thumbnail: {
url: string;
};
}
| null;
hash: string;
ext?: string;
mime?: string;
size?: number;
sizeInBytes?: number;
url?: string;
previewUrl?: string | null;
path?: string | null;
provider?: string;
provider_metadata?: Record<string, unknown> | null;
isUrlSigned?: boolean;
folder?: number | string | null;
folderPath?: string;
related?: {
id: string | number;
__type: string;
__pivot: { field: string };
}[];
createdAt?: string;
updatedAt?: string;
createdBy?: number;
publishedAt?: string;
updatedBy?: number;
isLocal?: boolean;
}
export interface RawFile extends Blob {
size: number;
lastModified: number;
name: string;
type: string;
}
export interface Pagination {
page: number;
pageSize: number;
pageCount: number;
total: number;
}
/**
* GET /upload/files - Get files
*/
export declare namespace GetFiles {
export interface Request {
body: {};
query: {
page?: string;
pageSize?: string;
folder: number | null;
sort?: `${SortKey}:${SortOrder}`;
};
}
export interface Response {
data: {
results: File[];
pagination: Pagination;
};
error?: errors.ApplicationError | errors.NotFoundError;
}
}
/**
* GET /upload/files/:id - Get specific file
*/
export declare namespace GetFile {
export interface Request {
params: { id: number };
query: {};
}
export interface Response {
data: File;
error?: errors.ApplicationError | errors.NotFoundError;
}
}
/**
* POST /upload/actions/bulk-delete - Delete Files
*/
export declare namespace BulkDeleteFiles {
export interface Request {
body: {
fileIds: number[];
};
}
export interface Response {
data: {
data: {
files: File[];
folders: [];
};
};
error?: errors.ApplicationError | errors.ValidationError;
}
}
/**
* POST /upload/actions/bulk-move - Move Files
*/
export declare namespace BulkMoveFiles {
export interface Request {
body: {
fileIds: number[];
destinationFolderId: number;
};
}
export interface Response {
data: {
data: {
files: File[];
folders: [];
};
};
error?: errors.ApplicationError | errors.ValidationError;
}
}
/**
* DELETE /upload/files/:id - Delete a specific asset
*/
export declare namespace DeleteFile {
export interface Request {
params: { id: number };
query: {};
}
export interface Response {
data: File;
error?: errors.ApplicationError | errors.NotFoundError;
}
}
/**
* POST /upload - Create a file
*/
export declare namespace CreateFile {
export interface Request {
body: FormData;
files: File[];
}
export interface Response {
data: File[];
error?: errors.ApplicationError | errors.ValidationError;
}
}
/**
* POST /upload?id=:id - Update asset
*/
export declare namespace UpdateFile {
export interface Request {
body: FormData;
params: { id: number };
}
export interface Response {
data: File;
error?: errors.ApplicationError | errors.ValidationError;
}
}