Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.2k
Add user-local project icons#4401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
aa3d9cbe9173f6a189fe416a0e5c1362d4563e4237bd1e4de269697b59f207c6f052c8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -38,6 +38,8 @@ import * as ServerSecretStore from "../auth/ServerSecretStore.ts"; | ||
| import { resolveAttachmentPathById } from "../attachmentStore.ts"; | ||
| import * as ServerConfig from "../config.ts"; | ||
| import * as ProjectFaviconResolver from "../project/ProjectFaviconResolver.ts"; | ||
| import * as RepositoryIdentityResolver from "../project/RepositoryIdentityResolver.ts"; | ||
| import * as ServerSettings from "../serverSettings.ts"; | ||
| import * as WorkspacePaths from "../workspace/WorkspacePaths.ts"; | ||
| export const ASSET_ROUTE_PREFIX = "/api/assets"; | ||
| @@ -84,6 +86,12 @@ const AssetClaimsSchema = Schema.Union([ | ||
| relativePath: Schema.NullOr(Schema.String), | ||
| expiresAt: Schema.Number, | ||
| }), | ||
| Schema.Struct({ | ||
| version: Schema.Literal(2), | ||
| kind: Schema.Literal("project-icon"), | ||
| absolutePath: Schema.NullOr(Schema.String), | ||
| expiresAt: Schema.Number, | ||
| }), | ||
| ]); | ||
| type AssetClaims = typeof AssetClaimsSchema.Type; | ||
| @@ -282,8 +290,8 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i | ||
| }), | ||
| ), | ||
| ); | ||
| const faviconResolver = yield* ProjectFaviconResolver.ProjectFaviconResolver; | ||
| const faviconPath = yield* faviconResolver.resolvePath(workspaceRoot).pipe( | ||
| const settings = yield* ServerSettings.ServerSettingsService; | ||
| const serverSettings = yield* settings.getSettings.pipe( | ||
| Effect.mapError( | ||
| (cause) => | ||
| new AssetProjectFaviconResolutionError({ | ||
| @@ -292,39 +300,67 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i | ||
| }), | ||
| ), | ||
| ); | ||
| const relativePath = faviconPath ? path.relative(workspaceRoot, faviconPath) : null; | ||
| if ( | ||
| relativePath && | ||
| !(yield* resolveCanonicalWorkspaceFile({ workspaceRoot, relativePath }).pipe( | ||
| const faviconResolver = yield* ProjectFaviconResolver.ProjectFaviconResolver; | ||
| const repositoryIdentityResolver = | ||
| yield* RepositoryIdentityResolver.RepositoryIdentityResolver; | ||
| const repositoryIdentity = yield* repositoryIdentityResolver.resolve(workspaceRoot); | ||
| const customIconPaths = [ | ||
| serverSettings.projectIcons[workspaceRoot] ?? | ||
| serverSettings.projectIcons[input.resource.cwd], | ||
| ...(repositoryIdentity | ||
| ? [serverSettings.projectIconsByGitRemote[repositoryIdentity.canonicalKey]] | ||
| : []), | ||
| ].filter((iconPath): iconPath is string => iconPath !== undefined); | ||
| const resolvedFavicon = yield* faviconResolver | ||
| .resolve(workspaceRoot, customIconPaths.length === 0 ? undefined : { customIconPaths }) | ||
| .pipe( | ||
| Effect.mapError( | ||
| (cause) => | ||
| new AssetProjectFaviconInspectionError({ | ||
| new AssetProjectFaviconResolutionError({ | ||
| resource: input.resource, | ||
| cause, | ||
| }), | ||
| ), | ||
| )) | ||
| ) { | ||
| return yield* new AssetProjectFaviconNotFoundError({ | ||
| resource: input.resource, | ||
| }); | ||
| ); | ||
| const canonicalFaviconPath = resolvedFavicon | ||
| ? resolvedFavicon.source === "custom-setting" | ||
| ? yield* optionOnNotFound(fileSystem.realPath(resolvedFavicon.path)).pipe( | ||
| Effect.mapError( | ||
| (cause) => | ||
| new AssetProjectFaviconInspectionError({ | ||
| resource: input.resource, | ||
| cause, | ||
| }), | ||
| ), | ||
| ) | ||
| : yield* Effect.gen(function* () { | ||
| const canonicalPath = yield* resolveCanonicalWorkspaceFile({ | ||
| workspaceRoot, | ||
| relativePath: path.relative(workspaceRoot, resolvedFavicon.path), | ||
| }).pipe( | ||
| Effect.mapError( | ||
| (cause) => | ||
| new AssetProjectFaviconInspectionError({ | ||
| resource: input.resource, | ||
| cause, | ||
| }), | ||
| ), | ||
| ); | ||
| return canonicalPath === null ? Option.none<string>() : Option.some(canonicalPath); | ||
| }) | ||
| : Option.none<string>(); | ||
| if (resolvedFavicon && Option.isNone(canonicalFaviconPath)) { | ||
| return yield* new AssetProjectFaviconNotFoundError({ resource: input.resource }); | ||
| } | ||
| claims = { | ||
| version: 1, | ||
| kind: "project-favicon", | ||
| workspaceRoot: yield* fileSystem.realPath(workspaceRoot).pipe( | ||
| Effect.mapError( | ||
| (cause) => | ||
| new AssetWorkspaceResolutionError({ | ||
| resource: input.resource, | ||
| cause, | ||
| }), | ||
| ), | ||
| ), | ||
| relativePath, | ||
| version: 2, | ||
| kind: "project-icon", | ||
| absolutePath: Option.getOrNull(canonicalFaviconPath), | ||
| expiresAt, | ||
| }; | ||
| fileName = relativePath ? path.basename(relativePath) : PROJECT_FAVICON_FALLBACK_MARKER; | ||
| fileName = resolvedFavicon | ||
| ? path.basename(resolvedFavicon.path) | ||
| : PROJECT_FAVICON_FALLBACK_MARKER; | ||
| break; | ||
| } | ||
| } | ||
| @@ -396,6 +432,32 @@ export const resolveAsset = Effect.fn("AssetAccess.resolveAsset")(function* ( | ||
| }); | ||
| return faviconPath ? ({ kind: "file", path: faviconPath } satisfies ResolvedAsset) : null; | ||
| } | ||
| if (claims.kind === "project-icon") { | ||
macroscopeapp[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (claims.absolutePath === null) return null; | ||
| const fileSystem = yield* FileSystem.FileSystem; | ||
| const canonicalPath = yield* optionOnNotFound(fileSystem.realPath(claims.absolutePath)).pipe( | ||
| Effect.tapError((cause) => | ||
| Effect.logError("Failed to canonicalize configured project icon.", { | ||
| path: claims.absolutePath, | ||
| cause, | ||
| }), | ||
| ), | ||
| Effect.orElseSucceed(() => Option.none()), | ||
| ); | ||
| if (Option.isNone(canonicalPath) || canonicalPath.value !== claims.absolutePath) return null; | ||
| const info = yield* optionOnNotFound(fileSystem.stat(canonicalPath.value)).pipe( | ||
| Effect.tapError((cause) => | ||
| Effect.logError("Failed to inspect configured project icon.", { | ||
| path: canonicalPath.value, | ||
| cause, | ||
| }), | ||
| ), | ||
| Effect.orElseSucceed(() => Option.none()), | ||
| ); | ||
| return Option.isSome(info) && info.value.type === "File" | ||
| ? ({ kind: "file", path: canonicalPath.value } satisfies ResolvedAsset) | ||
| : null; | ||
colonelpanic8 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| const decodedPath = decodeRelativePath(relativePath); | ||
| if (decodedPath === null) return null; | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.