Files
webstudio/apps/builder/app/shared/asset-client.ts
Oleg Isonen 82c3d83fd1 fix: optimize CLI import for large data amount (#5831)
## Summary

- Add CLI project import support from synced `.webstudio/data.json` into
another project via a destination share link.
- Move project bundle import/export contract into
`@webstudio-is/protocol`, including bundle versioning, staged upload
constants, schema validation, and fixture coverage.
- Upload project bundle data through staged TUS upload before calling
the import RPC to avoid request body limits.
- Upload referenced assets as binary files through the existing asset
upload route before importing asset rows.
- Add `--skip-assets` and `--ignore-version-check` import options.
- Add retry handling for transient missing imported asset files by
re-uploading only the reported missing assets.
- Share missing-asset import error formatting/parsing through protocol
to avoid duplicated string contracts.
- Preserve browser asset upload behavior while adding API upload
support.
- Normalize schema naming across the branch to lower-case names without
`Schema` suffix.
2026-06-23 18:50:01 +02:00

36 lines
981 B
TypeScript

import * as path from "node:path";
import { maxSize } from "@webstudio-is/asset-uploader";
import {
createFsClient,
createS3Client,
} from "@webstudio-is/asset-uploader/index.server";
import env from "~/env/env.server";
export const fileUploadPath = "public/cgi/asset";
export const createAssetClient = () => {
const maxUploadSize = maxSize.parse(env.MAX_UPLOAD_SIZE);
if (
env.S3_ENDPOINT !== undefined &&
env.S3_REGION !== undefined &&
env.S3_ACCESS_KEY_ID !== undefined &&
env.S3_SECRET_ACCESS_KEY !== undefined &&
env.S3_BUCKET !== undefined
) {
return createS3Client({
endpoint: env.S3_ENDPOINT,
region: env.S3_REGION,
accessKeyId: env.S3_ACCESS_KEY_ID,
secretAccessKey: env.S3_SECRET_ACCESS_KEY,
bucket: env.S3_BUCKET,
acl: env.S3_ACL,
maxUploadSize,
});
} else {
return createFsClient({
maxUploadSize,
fileDirectory: path.join(process.cwd(), fileUploadPath),
});
}
};