* feat: Add Simple-Icons and Selfh.st collections refactor: icon file path parsing * refactor: allowed extensions check
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import { logger } from "@homarr/log";
|
|
|
|
import type { IconRepositoryLicense } from "../types/icon-repository-license";
|
|
import type { RepositoryIconGroup } from "../types/repository-icon-group";
|
|
|
|
export abstract class IconRepository {
|
|
protected readonly allowedImageFileTypes = [".png", ".svg", ".jpeg"];
|
|
|
|
protected constructor(
|
|
public readonly name: string,
|
|
public readonly slug: string,
|
|
public readonly license: IconRepositoryLicense,
|
|
public readonly repositoryUrl?: URL,
|
|
public readonly repositoryIndexingUrl?: URL,
|
|
public readonly repositoryBlobUrlTemplate?: string,
|
|
) {}
|
|
|
|
public async getAllIconsAsync(): Promise<RepositoryIconGroup> {
|
|
try {
|
|
return await this.getAllIconsInternalAsync();
|
|
} catch (err) {
|
|
logger.error(`Unable to request icons from repository "${this.slug}": ${JSON.stringify(err)}`);
|
|
return {
|
|
success: false,
|
|
icons: [],
|
|
slug: this.slug,
|
|
};
|
|
}
|
|
}
|
|
|
|
protected abstract getAllIconsInternalAsync(): Promise<RepositoryIconGroup>;
|
|
}
|