@@ -62,7 +62,7 @@ export const iconsUpdaterJob = createCronJob("iconsUpdater", EVERY_WEEK, {
|
|||||||
id: createId(),
|
id: createId(),
|
||||||
checksum: icon.checksum,
|
checksum: icon.checksum,
|
||||||
name: icon.fileNameWithExtension,
|
name: icon.fileNameWithExtension,
|
||||||
url: icon.imageUrl.href,
|
url: icon.imageUrl,
|
||||||
iconRepositoryId: repositoryIconGroupId,
|
iconRepositoryId: repositoryIconGroupId,
|
||||||
});
|
});
|
||||||
countInserted++;
|
countInserted++;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
"prettier": "@homarr/prettier-config",
|
"prettier": "@homarr/prettier-config",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@homarr/common": "workspace:^0.1.0",
|
"@homarr/common": "workspace:^0.1.0",
|
||||||
|
"@homarr/db": "workspace:^0.1.0",
|
||||||
"@homarr/log": "workspace:^0.1.0"
|
"@homarr/log": "workspace:^0.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { GitHubIconRepository } from "./repositories/github.icon-repository";
|
import { GitHubIconRepository } from "./repositories/github.icon-repository";
|
||||||
import { JsdelivrIconRepository } from "./repositories/jsdelivr.icon-repository";
|
import { JsdelivrIconRepository } from "./repositories/jsdelivr.icon-repository";
|
||||||
|
import { LocalIconRepository } from "./repositories/local.icon-repository";
|
||||||
import type { RepositoryIconGroup } from "./types";
|
import type { RepositoryIconGroup } from "./types";
|
||||||
|
|
||||||
const repositories = [
|
const repositories = [
|
||||||
@@ -43,6 +44,7 @@ const repositories = [
|
|||||||
new URL("https://data.jsdelivr.com/v1/packages/gh/loganmarchione/homelab-svg-assets@main?structure=flat"),
|
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}",
|
"https://cdn.jsdelivr.net/gh/loganmarchione/homelab-svg-assets/{0}",
|
||||||
),
|
),
|
||||||
|
new LocalIconRepository(),
|
||||||
];
|
];
|
||||||
|
|
||||||
export const fetchIconsAsync = async (): Promise<RepositoryIconGroup[]> => {
|
export const fetchIconsAsync = async (): Promise<RepositoryIconGroup[]> => {
|
||||||
|
|||||||
@@ -35,11 +35,8 @@ export class GitHubIconRepository extends IconRepository {
|
|||||||
.map(({ path, size: sizeInBytes, sha: checksum }) => {
|
.map(({ path, size: sizeInBytes, sha: checksum }) => {
|
||||||
const file = parse(path);
|
const file = parse(path);
|
||||||
const fileNameWithExtension = file.base;
|
const fileNameWithExtension = file.base;
|
||||||
const imageUrl = new URL(
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
const imageUrl = this.repositoryBlobUrlTemplate!.replace("{0}", path).replace("{1}", file.name);
|
||||||
this.repositoryBlobUrlTemplate!.replace("{0}", path).replace("{1}", file.name),
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
imageUrl,
|
imageUrl,
|
||||||
fileNameWithExtension,
|
fileNameWithExtension,
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export class JsdelivrIconRepository extends IconRepository {
|
|||||||
const fileNameWithExtension = file.base;
|
const fileNameWithExtension = file.base;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
imageUrl: new URL(this.repositoryBlobUrlTemplate.replace("{0}", path).replace("{1}", file.name)),
|
imageUrl: this.repositoryBlobUrlTemplate.replace("{0}", path).replace("{1}", file.name),
|
||||||
fileNameWithExtension,
|
fileNameWithExtension,
|
||||||
local: false,
|
local: false,
|
||||||
sizeInBytes,
|
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 {
|
export interface RepositoryIcon {
|
||||||
fileNameWithExtension: string;
|
fileNameWithExtension: string;
|
||||||
sizeInBytes?: number;
|
sizeInBytes?: number;
|
||||||
imageUrl: URL;
|
imageUrl: string;
|
||||||
local: boolean;
|
local: boolean;
|
||||||
checksum: string;
|
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))
|
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':
|
'@vitest/coverage-v8':
|
||||||
specifier: ^2.1.4
|
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':
|
'@vitest/ui':
|
||||||
specifier: ^2.1.4
|
specifier: ^2.1.4
|
||||||
version: 2.1.4(vitest@2.1.4)
|
version: 2.1.4(vitest@2.1.4)
|
||||||
@@ -952,6 +952,9 @@ importers:
|
|||||||
'@homarr/common':
|
'@homarr/common':
|
||||||
specifier: workspace:^0.1.0
|
specifier: workspace:^0.1.0
|
||||||
version: link:../common
|
version: link:../common
|
||||||
|
'@homarr/db':
|
||||||
|
specifier: workspace:^0.1.0
|
||||||
|
version: link:../db
|
||||||
'@homarr/log':
|
'@homarr/log':
|
||||||
specifier: workspace:^0.1.0
|
specifier: workspace:^0.1.0
|
||||||
version: link:../log
|
version: link:../log
|
||||||
@@ -10338,7 +10341,7 @@ snapshots:
|
|||||||
transitivePeerDependencies:
|
transitivePeerDependencies:
|
||||||
- supports-color
|
- 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:
|
dependencies:
|
||||||
'@ampproject/remapping': 2.3.0
|
'@ampproject/remapping': 2.3.0
|
||||||
'@bcoe/v8-coverage': 0.2.3
|
'@bcoe/v8-coverage': 0.2.3
|
||||||
|
|||||||
Reference in New Issue
Block a user