mirror of
https://github.com/webstudio-is/webstudio.git
synced 2026-11-07 20:44:05 +09:00
create remote url option
This commit is contained in:
1 parent
49ca020bdf
commit
ea699c112e
1 file changed
+8
@@ -2,6 +2,7 @@ import { type Project } from "@webstudio-is/react-sdk";
|
||||
import { prisma } from "./prisma.server";
|
||||
import sharp from "sharp";
|
||||
import fs from "fs";
|
||||
import { fetch } from "@remix-run/node";
|
||||
|
||||
export const loadByProject = async (projectId?: Project["id"]) => {
|
||||
if (typeof projectId !== "string") {
|
||||
@@ -23,8 +24,15 @@ export const create = async (
|
||||
let size = 0;
|
||||
const image = await sharp(absolutePath);
|
||||
const metadata = await image.metadata();
|
||||
|
||||
// if there is no absolute path then it means it's a remote image and we can use fetch
|
||||
if (absolutePath) {
|
||||
size = fs.statSync(absolutePath).size;
|
||||
} else {
|
||||
const arrayBuffer = await fetch(values.path).then((rsp) =>
|
||||
rsp.arrayBuffer()
|
||||
);
|
||||
size = arrayBuffer.byteLength;
|
||||
}
|
||||
|
||||
const newAsset = await prisma.asset.create({
|
||||
|
||||
Reference in new issue
Block a user