Apply the auto-fixable lint rules and the formatter, and drop the Vite build artifacts.
This commit is contained in:
@@ -51,7 +51,9 @@ type PublishedCatalog = {
|
||||
items: DiscordCollectibleItem[];
|
||||
};
|
||||
|
||||
function isPublishedCatalog(value: unknown): value is { schema_version: number; items: DiscordCollectibleItem[] } {
|
||||
function isPublishedCatalog(
|
||||
value: unknown,
|
||||
): value is { schema_version: number; items: DiscordCollectibleItem[] } {
|
||||
if (!value || typeof value !== 'object') return false;
|
||||
const catalog = value as Record<string, unknown>;
|
||||
return (
|
||||
@@ -62,7 +64,7 @@ function isPublishedCatalog(value: unknown): value is { schema_version: number;
|
||||
item &&
|
||||
typeof item === 'object' &&
|
||||
typeof (item as DiscordCollectibleItem).id === 'string' &&
|
||||
Array.isArray((item as DiscordCollectibleItem).assets)
|
||||
Array.isArray((item as DiscordCollectibleItem).assets),
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -94,7 +96,7 @@ function saveCachedCatalog(catalog: PublishedCatalog): void {
|
||||
}
|
||||
|
||||
export async function fetchPublishedCollectiblesCatalog(
|
||||
force = false
|
||||
force = false,
|
||||
): Promise<DiscordCollectibleItem[]> {
|
||||
const cached = loadCachedCatalog();
|
||||
if (!force && cached) return cached.items;
|
||||
@@ -107,7 +109,7 @@ export async function fetchPublishedCollectiblesCatalog(
|
||||
const catalog = await response.json();
|
||||
if (!isPublishedCatalog(catalog)) throw new Error('Catalog has an unsupported schema.');
|
||||
return catalog;
|
||||
})
|
||||
}),
|
||||
);
|
||||
const items = documents.flatMap((catalog) => catalog.items);
|
||||
if (items.length === 0) throw new Error('Catalog is empty.');
|
||||
@@ -148,7 +150,7 @@ function replaceCdnUrls<T>(value: T, urlToMxc: Map<string, string>): T {
|
||||
}
|
||||
|
||||
export async function downloadCollectibleAssets(
|
||||
assets: DiscordCollectibleAsset[]
|
||||
assets: DiscordCollectibleAsset[],
|
||||
): Promise<DownloadedCollectibleAsset[]> {
|
||||
const api = window.electron?.discordCollectibles;
|
||||
if (api) {
|
||||
@@ -169,19 +171,20 @@ export async function downloadCollectibleAssets(
|
||||
assets.map(async (asset) => {
|
||||
if (!isCdnUrl(asset.url)) throw new Error('Collectible asset URL is not a Discord CDN URL.');
|
||||
const response = await fetch(asset.url);
|
||||
if (!response.ok) throw new Error(`Failed to download ${asset.filename}: HTTP ${response.status}.`);
|
||||
if (!response.ok)
|
||||
throw new Error(`Failed to download ${asset.filename}: HTTP ${response.status}.`);
|
||||
return {
|
||||
...asset,
|
||||
data: new Uint8Array(await response.arrayBuffer()),
|
||||
};
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export async function uploadCollectibleToMatrix(
|
||||
mx: MatrixClient,
|
||||
item: DiscordCollectibleItem,
|
||||
onProgress?: (message: string) => void
|
||||
onProgress?: (message: string) => void,
|
||||
): Promise<StoredCollectible> {
|
||||
onProgress?.('Downloading from Discord…');
|
||||
const downloaded = await downloadCollectibleAssets(item.assets);
|
||||
@@ -287,7 +290,7 @@ export function groupCollectibleItems(items: DiscordCollectibleItem[]): Collecti
|
||||
return [...map.entries()]
|
||||
.map(([id, groupItems]) => {
|
||||
const items = dedupeVariantItems(groupItems).sort((a, b) =>
|
||||
variantItemLabel(a).localeCompare(variantItemLabel(b))
|
||||
variantItemLabel(a).localeCompare(variantItemLabel(b)),
|
||||
);
|
||||
return {
|
||||
id,
|
||||
|
||||
Reference in New Issue
Block a user