mirror of
https://github.com/urbit/shrub.git
synced 2025-01-07 05:26:56 +03:00
s3: fixes #4039
This commit is contained in:
parent
e5ea163bfa
commit
489a3351c4
@ -90,7 +90,7 @@ export function useFileDrag(dragged: (f: FileList | File[], e: DragEvent) => voi
|
|||||||
return () => {
|
return () => {
|
||||||
document.body.removeEventListener('mouseout', mouseleave);
|
document.body.removeEventListener('mouseout', mouseleave);
|
||||||
}
|
}
|
||||||
}, [setDragging]);
|
}, []);
|
||||||
|
|
||||||
const bind = {
|
const bind = {
|
||||||
onDragLeave,
|
onDragLeave,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { useCallback, useMemo, useEffect, useRef, useState } from "react";
|
import { useCallback, useMemo, useEffect, useRef, useState } from "react";
|
||||||
import { S3State } from "../../types/s3-update";
|
import { S3State } from "../../types/s3-update";
|
||||||
import S3 from "aws-sdk/clients/s3";
|
import S3 from "aws-sdk/clients/s3";
|
||||||
|
import { dateToDa, deSig } from "./util";
|
||||||
|
|
||||||
export interface IuseS3 {
|
export interface IuseS3 {
|
||||||
canUpload: boolean;
|
canUpload: boolean;
|
||||||
@ -37,9 +38,14 @@ const useS3 = (s3: S3State, { accept = '*' } = { accept: '*' }): IuseS3 => {
|
|||||||
throw new Error("S3 not ready");
|
throw new Error("S3 not ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fileParts = file.name.split('.');
|
||||||
|
const fileName = fileParts.slice(0, -1);
|
||||||
|
const fileExtension = fileParts.pop();
|
||||||
|
const timestamp = deSig(dateToDa(new Date()));
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
Bucket: bucket,
|
Bucket: bucket,
|
||||||
Key: file.name,
|
Key: `${window.ship}/${timestamp}-${fileName}.${fileExtension}`,
|
||||||
Body: file,
|
Body: file,
|
||||||
ACL: "public-read",
|
ACL: "public-read",
|
||||||
ContentType: file.type,
|
ContentType: file.type,
|
||||||
@ -61,7 +67,7 @@ const useS3 = (s3: S3State, { accept = '*' } = { accept: '*' }): IuseS3 => {
|
|||||||
throw new Error("current bucket not set");
|
throw new Error("current bucket not set");
|
||||||
}
|
}
|
||||||
return upload(file, s3.configuration.currentBucket);
|
return upload(file, s3.configuration.currentBucket);
|
||||||
}, []);
|
}, [s3]);
|
||||||
|
|
||||||
const promptUpload = useCallback(
|
const promptUpload = useCallback(
|
||||||
() => {
|
() => {
|
||||||
|
@ -87,7 +87,7 @@ const LinkSubmit = (props: LinkSubmitProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onFileDrag = useCallback(
|
const onFileDrag = useCallback(
|
||||||
async (files: FileList | File[], e: DragEvent) => {
|
(files: FileList | File[], e: DragEvent): void => {
|
||||||
if (!canUpload) {
|
if (!canUpload) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -117,17 +117,15 @@ const LinkSubmit = (props: LinkSubmitProps) => {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
uploadDefault(event.clipboardData.files[0]).then(setLinkValue);
|
uploadDefault(event.clipboardData.files[0]).then(setLinkValue);
|
||||||
}, [setLinkValue]
|
}, [setLinkValue, uploadDefault]
|
||||||
);
|
);
|
||||||
|
|
||||||
const onKeyPress = useCallback(
|
const onKeyPress = (e) => {
|
||||||
(e) => {
|
if (e.key === 'Enter') {
|
||||||
if (e.key === 'Enter') {
|
e.preventDefault();
|
||||||
e.preventDefault();
|
doPost();
|
||||||
doPost();
|
}
|
||||||
}
|
};
|
||||||
}, []
|
|
||||||
);
|
|
||||||
|
|
||||||
const placeholder = <Text
|
const placeholder = <Text
|
||||||
gray
|
gray
|
||||||
|
@ -98,7 +98,7 @@ export function MarkdownEditor(
|
|||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
height="100%"
|
height="100%"
|
||||||
position="static"
|
position="relative"
|
||||||
className="publish"
|
className="publish"
|
||||||
p={1}
|
p={1}
|
||||||
border={1}
|
border={1}
|
||||||
|
Loading…
Reference in New Issue
Block a user