♻️ Refactor icon picker (#724)

This commit is contained in:
Manuel
2023-02-20 22:11:30 +01:00
committed by GitHub
parent 2c1b329dfd
commit f5686fbf2c
17 changed files with 441 additions and 258 deletions

View File

@@ -0,0 +1,44 @@
import fs from 'fs';
import {
AbstractIconRepository,
NormalizedIcon,
NormalizedIconRepositoryResult,
} from './abstract-icons-repository';
export class LocalIconsRepository extends AbstractIconRepository {
constructor() {
super('');
}
protected async fetchInternally(): Promise<NormalizedIconRepositoryResult> {
if (!fs.existsSync('./public/icons')) {
return {
count: 0,
entries: [],
name: 'Local',
success: true,
copyright: this.copyright,
};
}
const files = fs.readdirSync('./public/icons');
const normalizedEntries = files
.filter((file) => ['.png', '.svg', '.jpeg', '.jpg'].some((x) => file.endsWith(x)))
.map(
(file): NormalizedIcon => ({
name: file,
url: `./icons/${file}`,
size: 0,
})
);
return {
entries: normalizedEntries,
count: normalizedEntries.length,
success: true,
name: 'Local',
copyright: this.copyright,
};
}
}