refactor: Consolidate workspace utilities into new workspaceUtils.ts with typed entry keys, replacing appLayoutUtils.ts, and update related components.
This commit is contained in:
@@ -42,7 +42,7 @@ export const resolveAssetUrl = (asset?: { download?: { url: string } | null } |
|
||||
export type EnsureAssetUrl = (
|
||||
documentId: Identifier,
|
||||
asset: AssetLike,
|
||||
options?: { force?: boolean; [key: string]: unknown },
|
||||
options?: { force?: boolean;[key: string]: unknown },
|
||||
) => Promise<unknown>;
|
||||
|
||||
export type GetAsset = (document: DocumentLike, assetType: string) => Nullable<AssetLike>;
|
||||
@@ -171,7 +171,7 @@ export const resolveDocumentAssetUrl = (
|
||||
}: {
|
||||
ensureAssetUrl?: EnsureAssetUrl;
|
||||
getAsset?: GetAsset;
|
||||
ensureOptions?: { force?: boolean; [key: string]: unknown };
|
||||
ensureOptions?: { force?: boolean;[key: string]: unknown };
|
||||
} = {},
|
||||
): Nullable<string> => {
|
||||
if (!doc || !type) {
|
||||
@@ -191,24 +191,23 @@ export const resolveDocumentAssetUrl = (
|
||||
}
|
||||
if (doc.id && asset.id && ensureAssetUrl) {
|
||||
const force = Boolean(url && expiresAt && expiresAt <= now);
|
||||
const options: { force: boolean; [key: string]: unknown } = {
|
||||
const options: { force: boolean;[key: string]: unknown } = {
|
||||
force,
|
||||
...(ensureOptions || {}),
|
||||
};
|
||||
ensureAssetUrl(doc.id, asset, options).catch(() => {});
|
||||
ensureAssetUrl(doc.id, asset, options).catch(() => { });
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
class AssetManager {
|
||||
fetchAsset: ((id: Identifier) => Promise<AssetLike | null>) | null;
|
||||
assetPresignTtlMs: number;
|
||||
|
||||
assetCache: Map<Identifier, AssetLike>;
|
||||
assetInflight: Map<string, Promise<AssetLike | null>>;
|
||||
|
||||
constructor({ fetchAsset, assetPresignTtlMs }: { fetchAsset: ((id: Identifier) => Promise<AssetLike | null>) | null; assetPresignTtlMs: number }) {
|
||||
constructor({ fetchAsset }: { fetchAsset: ((id: Identifier) => Promise<AssetLike | null>) | null }) {
|
||||
this.fetchAsset = fetchAsset;
|
||||
this.assetPresignTtlMs = assetPresignTtlMs;
|
||||
this.assetCache = new Map();
|
||||
this.assetInflight = new Map();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user