- Replace attachment and favicon routes with signed asset URLs - Harden workspace and attachment asset resolution - Update browser preview components and shared contracts
39 lines
1.2 KiB
TypeScript
39 lines
1.2 KiB
TypeScript
import * as Schema from "effect/Schema";
|
|
|
|
import { ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
|
|
|
|
const ASSET_PATH_MAX_LENGTH = 1024;
|
|
|
|
export const AssetResource = Schema.Union([
|
|
Schema.TaggedStruct("workspace-file", {
|
|
threadId: ThreadId,
|
|
path: TrimmedNonEmptyString.check(Schema.isMaxLength(ASSET_PATH_MAX_LENGTH)),
|
|
}),
|
|
Schema.TaggedStruct("attachment", {
|
|
attachmentId: TrimmedNonEmptyString.check(Schema.isMaxLength(256)),
|
|
}),
|
|
Schema.TaggedStruct("project-favicon", {
|
|
cwd: TrimmedNonEmptyString.check(Schema.isMaxLength(ASSET_PATH_MAX_LENGTH)),
|
|
}),
|
|
]);
|
|
export type AssetResource = typeof AssetResource.Type;
|
|
|
|
export const AssetCreateUrlInput = Schema.Struct({
|
|
resource: AssetResource,
|
|
});
|
|
export type AssetCreateUrlInput = typeof AssetCreateUrlInput.Type;
|
|
|
|
export const AssetCreateUrlResult = Schema.Struct({
|
|
relativeUrl: TrimmedNonEmptyString.check(Schema.isMaxLength(4096)),
|
|
expiresAt: Schema.Number,
|
|
});
|
|
export type AssetCreateUrlResult = typeof AssetCreateUrlResult.Type;
|
|
|
|
export class AssetAccessError extends Schema.TaggedErrorClass<AssetAccessError>()(
|
|
"AssetAccessError",
|
|
{
|
|
message: TrimmedNonEmptyString,
|
|
cause: Schema.optional(Schema.Defect()),
|
|
},
|
|
) {}
|