mirror of
https://github.com/ajnart/homarr.git
synced 2026-02-28 01:10:54 +01:00
@@ -62,7 +62,7 @@ export const iconsUpdaterJob = createCronJob("iconsUpdater", EVERY_WEEK, {
|
||||
id: createId(),
|
||||
checksum: icon.checksum,
|
||||
name: icon.fileNameWithExtension,
|
||||
url: icon.imageUrl.href,
|
||||
url: icon.imageUrl,
|
||||
iconRepositoryId: repositoryIconGroupId,
|
||||
});
|
||||
countInserted++;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
"prettier": "@homarr/prettier-config",
|
||||
"dependencies": {
|
||||
"@homarr/common": "workspace:^0.1.0",
|
||||
"@homarr/db": "workspace:^0.1.0",
|
||||
"@homarr/log": "workspace:^0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { GitHubIconRepository } from "./repositories/github.icon-repository";
|
||||
import { JsdelivrIconRepository } from "./repositories/jsdelivr.icon-repository";
|
||||
import { LocalIconRepository } from "./repositories/local.icon-repository";
|
||||
import type { RepositoryIconGroup } from "./types";
|
||||
|
||||
const repositories = [
|
||||
@@ -43,6 +44,7 @@ const repositories = [
|
||||
new URL("https://data.jsdelivr.com/v1/packages/gh/loganmarchione/homelab-svg-assets@main?structure=flat"),
|
||||
"https://cdn.jsdelivr.net/gh/loganmarchione/homelab-svg-assets/{0}",
|
||||
),
|
||||
new LocalIconRepository(),
|
||||
];
|
||||
|
||||
export const fetchIconsAsync = async (): Promise<RepositoryIconGroup[]> => {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
26
packages/icons/src/repositories/local.icon-repository.ts
Normal file
26
packages/icons/src/repositories/local.icon-repository.ts
Normal 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",
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
export interface RepositoryIcon {
|
||||
fileNameWithExtension: string;
|
||||
sizeInBytes?: number;
|
||||
imageUrl: URL;
|
||||
imageUrl: string;
|
||||
local: boolean;
|
||||
checksum: string;
|
||||
}
|
||||
|
||||
7
pnpm-lock.yaml
generated
7
pnpm-lock.yaml
generated
@@ -24,7 +24,7 @@ importers:
|
||||
version: 4.3.3(vite@5.4.5(@types/node@22.8.7)(sass@1.80.6)(sugarss@4.0.1(postcss@8.4.47))(terser@5.32.0))
|
||||
'@vitest/coverage-v8':
|
||||
specifier: ^2.1.4
|
||||
version: 2.1.4(vitest@2.1.4)
|
||||
version: 2.1.4(vitest@2.1.4(@types/node@22.8.7)(@vitest/ui@2.1.4)(jsdom@25.0.1)(sass@1.80.6)(sugarss@4.0.1(postcss@8.4.47))(terser@5.32.0))
|
||||
'@vitest/ui':
|
||||
specifier: ^2.1.4
|
||||
version: 2.1.4(vitest@2.1.4)
|
||||
@@ -952,6 +952,9 @@ importers:
|
||||
'@homarr/common':
|
||||
specifier: workspace:^0.1.0
|
||||
version: link:../common
|
||||
'@homarr/db':
|
||||
specifier: workspace:^0.1.0
|
||||
version: link:../db
|
||||
'@homarr/log':
|
||||
specifier: workspace:^0.1.0
|
||||
version: link:../log
|
||||
@@ -10338,7 +10341,7 @@ snapshots:
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
|
||||
'@vitest/coverage-v8@2.1.4(vitest@2.1.4)':
|
||||
'@vitest/coverage-v8@2.1.4(vitest@2.1.4(@types/node@22.8.7)(@vitest/ui@2.1.4)(jsdom@25.0.1)(sass@1.80.6)(sugarss@4.0.1(postcss@8.4.47))(terser@5.32.0))':
|
||||
dependencies:
|
||||
'@ampproject/remapping': 2.3.0
|
||||
'@bcoe/v8-coverage': 0.2.3
|
||||
|
||||
Reference in New Issue
Block a user