Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions frontend/components/write/metadata/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { BsUpload } from "react-icons/bs";
import { useUploadMetadata } from "../../../hooks/useUploadNote";

type FileUploadProps = {
accept?: string;
multiple?: boolean;
name: string;
isImage?: boolean;
};

export type FileControlProps = FormControlProps &
Expand All @@ -27,10 +27,11 @@ export const FileControl: React.FC<FileControlProps> = React.forwardRef(
label,
buttonProps,
multiple = false,
accept = ".jpg,.jpeg,.png,.gif,.pdf,.docx,.csv",
isImage,
...rest
} = props;
const [{ onChange, ...field }, , { setValue }] = useField(name);
const accept = isImage ? ".jpg,.jpeg,.png,.gif" : ".pdf,.docx,.csv";
const [{ ...field }, , { setValue }] = useField(name);
const inputRef = useRef<HTMLInputElement | null>(null);
const toast = useToast();
const { upload } = useUploadMetadata();
Expand Down
11 changes: 9 additions & 2 deletions frontend/components/write/metadata/MetadataBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ function MetadataBox() {
flexGrow={1}
maxW="100%"
>
<ExternalUrlField fieldName="externalUrl" placeholder="" />
<HStack width="full">
<Box flexGrow={1} flexShrink={0}>
<ExternalUrlField fieldName="externalUrl" placeholder="" />
</Box>
<Box flexShrink={1}>
<FileControl name="externalUrl" isImage={false} />
</Box>
</HStack>
</Flex>
<Flex
alignItems="center"
Expand All @@ -44,7 +51,7 @@ function MetadataBox() {
<ImageUrlField fieldName="imageUrl" placeholder="" />
</Box>
<Box flexShrink={1}>
<FileControl name="imageUrl" />
<FileControl name="imageUrl" isImage={true} />
</Box>
</HStack>
</Flex>
Expand Down
11 changes: 2 additions & 9 deletions services/metadata_upload/nft_storage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import multer from "multer";

import lighthouse from "@lighthouse-web3/sdk";

import imageType from "image-type";

const app = express();

app.use(function (req, res, next) {
Expand Down Expand Up @@ -42,12 +40,7 @@ app.post("/lighthouse", cpUpload, async function (req, res) {

obj.filename = req.files.file[0].originalname;
obj.file = response.data.Hash;

const type = await imageType(fileContent);
const isImage = !!type;
if (isImage) {
obj.image = "ipfs://" + response.data.Hash;
}
obj.fileUrl = "ipfs://" + response.data.Hash;
}

if (req.files.document) {
Expand All @@ -66,7 +59,7 @@ app.post("/lighthouse", cpUpload, async function (req, res) {

res.send({
key: response.data.Hash,
imageUrl: obj.image ?? "",
fileUrl: obj.fileUrl ?? "",
url: "https://gateway.lighthouse.storage/ipfs/" + response.data.Hash,
});
} catch (err) {
Expand Down