mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
26 lines
645 B
TypeScript
26 lines
645 B
TypeScript
import {
|
|
IResultWithStatus, IFile, IUploadProgressHandler, IFileWithUUID,
|
|
} from '~/redux/types';
|
|
import {
|
|
api, configWithToken, resultMiddleware, errorMiddleware,
|
|
} from '~/utils/api';
|
|
|
|
import { API } from '~/constants/api';
|
|
|
|
export const postUploadFile = ({
|
|
access,
|
|
file,
|
|
target = 'others',
|
|
type = 'image',
|
|
}: IFileWithUUID & {
|
|
access: string;
|
|
onProgress: IUploadProgressHandler;
|
|
}): Promise<IResultWithStatus<IFile>> => {
|
|
const data = new FormData();
|
|
data.append('file', file);
|
|
|
|
return api
|
|
.post(API.USER.UPLOAD(target, type), data, configWithToken(access))
|
|
.then(resultMiddleware)
|
|
.catch(errorMiddleware);
|
|
};
|