feat: #1408 add local icon repository (#1413)

This commit is contained in:
Manuel
2024-11-04 10:02:54 +01:00
committed by GitHub
parent aec9ec1efd
commit f31ccf2d6a
8 changed files with 39 additions and 10 deletions

View File

@@ -35,11 +35,8 @@ export class GitHubIconRepository extends IconRepository {
.map(({ path, size: sizeInBytes, sha: checksum }) => {
const file = parse(path);
const fileNameWithExtension = file.base;
const imageUrl = new URL(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.repositoryBlobUrlTemplate!.replace("{0}", path).replace("{1}", file.name),
);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const imageUrl = this.repositoryBlobUrlTemplate!.replace("{0}", path).replace("{1}", file.name);
return {
imageUrl,
fileNameWithExtension,

View File

@@ -33,7 +33,7 @@ export class JsdelivrIconRepository extends IconRepository {
const fileNameWithExtension = file.base;
return {
imageUrl: new URL(this.repositoryBlobUrlTemplate.replace("{0}", path).replace("{1}", file.name)),
imageUrl: this.repositoryBlobUrlTemplate.replace("{0}", path).replace("{1}", file.name),
fileNameWithExtension,
local: false,
sizeInBytes,

View File

@@ -0,0 +1,26 @@
import { createHash } from "crypto";
import { db } from "@homarr/db";
import type { RepositoryIconGroup } from "../types";
import { IconRepository } from "./icon-repository";
export class LocalIconRepository extends IconRepository {
constructor() {
super("Local", "local", undefined, undefined, undefined, undefined);
}
protected async getAllIconsInternalAsync(): Promise<RepositoryIconGroup> {
const medias = await db.query.medias.findMany();
return {
success: true,
icons: medias.map((media) => ({
local: true,
fileNameWithExtension: media.name,
imageUrl: `/api/user-medias/${media.id}`,
checksum: createHash("md5").update(media.content).digest("hex"),
sizeInBytes: media.size,
})),
slug: "local",
};
}
}