|
1 | 1 | import type { AssetResource } from "@t3tools/contracts"; |
2 | 2 | import { |
| 3 | + attentionSoundMimeTypeFromExtension, |
3 | 4 | AssetAttachmentNotFoundError, |
4 | 5 | AssetPreviewTypeValidationError, |
5 | 6 | AssetProjectFaviconInspectionError, |
@@ -101,6 +102,14 @@ const AssetClaimsSchema = Schema.Union([ |
101 | 102 | inode: Schema.String, |
102 | 103 | expiresAt: Schema.Number, |
103 | 104 | }), |
| 105 | + Schema.Struct({ |
| 106 | + version: Schema.Literal(1), |
| 107 | + kind: Schema.Literal("attention-sound-exact"), |
| 108 | + filePath: Schema.String, |
| 109 | + device: Schema.String, |
| 110 | + inode: Schema.String, |
| 111 | + expiresAt: Schema.Number, |
| 112 | + }), |
104 | 113 | Schema.Struct({ |
105 | 114 | version: Schema.Literal(1), |
106 | 115 | kind: Schema.Literal("attachment"), |
@@ -336,6 +345,48 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i |
336 | 345 | fileName = path.basename(canonicalFile); |
337 | 346 | break; |
338 | 347 | } |
| 348 | + case "attention-sound": { |
| 349 | + // Audio only, and only a real file: the extension check is what keeps |
| 350 | + // this from becoming a second, wider read-anything route. |
| 351 | + const requestedPath = input.resource.path; |
| 352 | + if (!path.isAbsolute(requestedPath)) { |
| 353 | + return yield* new AssetWorkspaceContextNotFoundError({ resource: input.resource }); |
| 354 | + } |
| 355 | + if (attentionSoundMimeTypeFromExtension(path.extname(requestedPath)) === null) { |
| 356 | + return yield* new AssetPreviewTypeValidationError({ resource: input.resource }); |
| 357 | + } |
| 358 | + const canonicalSound = yield* resolveCanonicalFile(requestedPath).pipe( |
| 359 | + Effect.mapError( |
| 360 | + (cause) => new AssetWorkspaceAssetInspectionError({ resource: input.resource, cause }), |
| 361 | + ), |
| 362 | + ); |
| 363 | + if (!canonicalSound) { |
| 364 | + return yield* new AssetWorkspaceAssetNotFoundError({ resource: input.resource }); |
| 365 | + } |
| 366 | + const openedSound = yield* openMediaFile(canonicalSound).pipe( |
| 367 | + Effect.map((file) => |
| 368 | + file === null |
| 369 | + ? null |
| 370 | + : { device: file.info.dev.toString(), inode: file.info.ino.toString() }, |
| 371 | + ), |
| 372 | + Effect.scoped, |
| 373 | + Effect.mapError( |
| 374 | + (cause) => new AssetWorkspaceAssetInspectionError({ resource: input.resource, cause }), |
| 375 | + ), |
| 376 | + ); |
| 377 | + if (!openedSound) { |
| 378 | + return yield* new AssetWorkspaceAssetNotFoundError({ resource: input.resource }); |
| 379 | + } |
| 380 | + claims = { |
| 381 | + version: 1, |
| 382 | + kind: "attention-sound-exact", |
| 383 | + filePath: canonicalSound, |
| 384 | + ...openedSound, |
| 385 | + expiresAt, |
| 386 | + }; |
| 387 | + fileName = path.basename(canonicalSound); |
| 388 | + break; |
| 389 | + } |
339 | 390 | case "workspace-file": { |
340 | 391 | if (!input.workspaceRoot) { |
341 | 392 | return yield* new AssetWorkspaceContextNotFoundError({ |
@@ -722,6 +773,26 @@ export const resolveAsset = Effect.fn("AssetAccess.resolveAsset")(function* ( |
722 | 773 | ? ({ kind: "file", path: canonicalFile, mimeType, file } satisfies ResolvedAsset) |
723 | 774 | : null; |
724 | 775 | } |
| 776 | + if (claims.kind === "attention-sound-exact") { |
| 777 | + if (decodedPath !== path.basename(claims.filePath)) return null; |
| 778 | + const canonicalSound = yield* resolveCanonicalFile(claims.filePath).pipe( |
| 779 | + Effect.orElseSucceed(() => null), |
| 780 | + ); |
| 781 | + if (canonicalSound !== claims.filePath) return null; |
| 782 | + const soundMimeType = attentionSoundMimeTypeFromExtension(path.extname(canonicalSound)); |
| 783 | + if (!soundMimeType) return null; |
| 784 | + const soundFile = yield* openMediaFile(canonicalSound, claims).pipe( |
| 785 | + Effect.orElseSucceed(() => null), |
| 786 | + ); |
| 787 | + return soundFile |
| 788 | + ? ({ |
| 789 | + kind: "file", |
| 790 | + path: canonicalSound, |
| 791 | + mimeType: soundMimeType, |
| 792 | + file: soundFile, |
| 793 | + } satisfies ResolvedAsset) |
| 794 | + : null; |
| 795 | + } |
725 | 796 | if (claims.kind === "workspace-file-exact") { |
726 | 797 | if (decodedPath !== path.basename(claims.relativePath)) return null; |
727 | 798 | const exactWorkspaceFile = yield* resolveCanonicalWorkspaceFileForRequest({ |
|
0 commit comments