1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

fixed uploads

This commit is contained in:
muerwre 2019-08-21 18:50:13 +07:00
parent cad4e683bc
commit 32b9a0dbbb
9 changed files with 52 additions and 37 deletions

View file

@ -11,11 +11,11 @@ export const getStyle = (oElm: any, strCssRule: string) => {
};
function polarToCartesian(centerX, centerY, radius, angleInDegrees) {
const angleInRadians = (angleInDegrees - 90) * Math.PI / 180.0;
const angleInRadians = ((angleInDegrees - 90) * Math.PI) / 180.0;
return {
x: centerX + (radius * Math.cos(angleInRadians)),
y: centerY + (radius * Math.sin(angleInRadians)),
x: centerX + radius * Math.cos(angleInRadians),
y: centerY + radius * Math.sin(angleInRadians),
};
}
@ -24,7 +24,7 @@ export const describeArc = (
y: number,
radius: number,
startAngle: number = 0,
endAngle: number = 360,
endAngle: number = 360
): string => {
const start = polarToCartesian(x, y, radius, endAngle);
const end = polarToCartesian(x, y, radius, startAngle);
@ -32,9 +32,24 @@ export const describeArc = (
const largeArcFlag = endAngle - startAngle <= 180 ? 0 : 1;
return [
'M', start.x, start.y,
'A', radius, radius, 0, largeArcFlag, 0, end.x, end.y,
'L', x, y,
'L', start.x, start.y,
'M',
start.x,
start.y,
'A',
radius,
radius,
0,
largeArcFlag,
0,
end.x,
end.y,
'L',
x,
y,
'L',
start.x,
start.y,
].join(' ');
};
export const getURL = url => `${process.env.API_HOST}${url}`;

View file

@ -10,7 +10,10 @@ export const IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/
export function createUploader<T extends {}, R extends {}>(
callback: (args: any) => any,
payload: R
): [(args: T) => (args: T & { onProgress: (current: number, total: number) => void }) => any, EventChannel<any>] {
): [
(args: T) => (args: T & { onProgress: (current: number, total: number) => void }) => any,
EventChannel<any>
] {
let emit;
const chan = eventChannel((emitter) => {
@ -18,8 +21,8 @@ export function createUploader<T extends {}, R extends {}>(
return () => null;
});
const onProgress = (current: number, total: number): void => {
emit(current >= total ? END : { ...payload, progress: parseFloat((current / total).toFixed(1)) });
const onProgress = ({ loaded, total }: { loaded: number; total: number }): void => {
emit(loaded >= total ? END : { ...payload, progress: parseFloat((loaded / total).toFixed(1)) });
};
const wrappedCallback = args => callback({ ...args, onProgress });
@ -40,7 +43,7 @@ export const uploadGetThumb = async (file) => {
export const fakeUploader = ({
file,
onProgress,
mustSucceed
mustSucceed,
}: {
file: { url?: string; error?: string };
onProgress: (current: number, total: number) => void;