mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
refactor: 🚨 Make class methods that don't use this static
This commit is contained in:
parent
53688095cc
commit
835cdc3f18
7 changed files with 47 additions and 40 deletions
|
|
@ -104,10 +104,9 @@ export class ImageConversionPreprocessor implements MediaPreprocessor {
|
|||
fileName: string,
|
||||
newExtension: string,
|
||||
): string {
|
||||
return this.extractFilenameFromPath(fileName).replace(
|
||||
/\.[^/.]+$/,
|
||||
`.${newExtension}`,
|
||||
);
|
||||
return ImageConversionPreprocessor.extractFilenameFromPath(
|
||||
fileName,
|
||||
).replace(/\.[^/.]+$/, `.${newExtension}`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -115,7 +114,7 @@ export class ImageConversionPreprocessor implements MediaPreprocessor {
|
|||
* @param path - The path to extract the filename from.
|
||||
* @returns The extracted filename.
|
||||
*/
|
||||
private extractFilenameFromPath(path: string): string {
|
||||
private static extractFilenameFromPath(path: string): string {
|
||||
const pathParts = path.split(/(?<!\\)\//);
|
||||
return pathParts[pathParts.length - 1];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ describe("PluginLoader", () => {
|
|||
]);
|
||||
|
||||
// biome-ignore lint/complexity/useLiteralKeys: Private method
|
||||
const directories = await pluginLoader["getDirectories"]("/some/path");
|
||||
const directories = await PluginLoader["getDirectories"]("/some/path");
|
||||
expect(directories).toEqual(["dir1", "dir2"]);
|
||||
});
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ describe("PluginLoader", () => {
|
|||
|
||||
const manifestFile =
|
||||
// biome-ignore lint/complexity/useLiteralKeys: Private method
|
||||
await pluginLoader["findManifestFile"]("/some/path");
|
||||
await PluginLoader["findManifestFile"]("/some/path");
|
||||
expect(manifestFile).toBe("manifest.json");
|
||||
});
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ describe("PluginLoader", () => {
|
|||
mockReaddir.mockResolvedValue(["index.ts", "otherfile.txt"]);
|
||||
|
||||
// biome-ignore lint/complexity/useLiteralKeys: Private method
|
||||
const hasEntrypoint = await pluginLoader["hasEntrypoint"]("/some/path");
|
||||
const hasEntrypoint = await PluginLoader["hasEntrypoint"]("/some/path");
|
||||
expect(hasEntrypoint).toBe(true);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export class PluginLoader {
|
|||
* @param {string} dir - The directory to search.
|
||||
* @returns {Promise<string[]>} - An array of directory names.
|
||||
*/
|
||||
private async getDirectories(dir: string): Promise<string[]> {
|
||||
private static async getDirectories(dir: string): Promise<string[]> {
|
||||
const files = await readdir(dir, { withFileTypes: true });
|
||||
return files.filter((f) => f.isDirectory()).map((f) => f.name);
|
||||
}
|
||||
|
|
@ -28,7 +28,9 @@ export class PluginLoader {
|
|||
* @param {string} dir - The directory to search.
|
||||
* @returns {Promise<string | undefined>} - The manifest file name if found, otherwise undefined.
|
||||
*/
|
||||
private async findManifestFile(dir: string): Promise<string | undefined> {
|
||||
private static async findManifestFile(
|
||||
dir: string,
|
||||
): Promise<string | undefined> {
|
||||
const files = await readdir(dir);
|
||||
return files.find((f) => f.match(/^manifest\.(json|json5|jsonc)$/));
|
||||
}
|
||||
|
|
@ -38,7 +40,7 @@ export class PluginLoader {
|
|||
* @param {string} dir - The directory to search.
|
||||
* @returns {Promise<boolean>} - True if the entrypoint file is found, otherwise false.
|
||||
*/
|
||||
private async hasEntrypoint(dir: string): Promise<boolean> {
|
||||
private static async hasEntrypoint(dir: string): Promise<boolean> {
|
||||
const files = await readdir(dir);
|
||||
return files.includes("index.ts") || files.includes("index.js");
|
||||
}
|
||||
|
|
@ -79,16 +81,16 @@ export class PluginLoader {
|
|||
* @returns {Promise<string[]>} - An array of plugin directories.
|
||||
*/
|
||||
public async findPlugins(dir: string): Promise<string[]> {
|
||||
const directories = await this.getDirectories(dir);
|
||||
const directories = await PluginLoader.getDirectories(dir);
|
||||
const plugins: string[] = [];
|
||||
|
||||
for (const directory of directories) {
|
||||
const manifestFile = await this.findManifestFile(
|
||||
const manifestFile = await PluginLoader.findManifestFile(
|
||||
`${dir}/${directory}`,
|
||||
);
|
||||
if (
|
||||
manifestFile &&
|
||||
(await this.hasEntrypoint(`${dir}/${directory}`))
|
||||
(await PluginLoader.hasEntrypoint(`${dir}/${directory}`))
|
||||
) {
|
||||
plugins.push(directory);
|
||||
}
|
||||
|
|
@ -105,7 +107,9 @@ export class PluginLoader {
|
|||
* @throws Will throw an error if the manifest file is missing or invalid.
|
||||
*/
|
||||
public async parseManifest(dir: string, plugin: string): Promise<Manifest> {
|
||||
const manifestFile = await this.findManifestFile(`${dir}/${plugin}`);
|
||||
const manifestFile = await PluginLoader.findManifestFile(
|
||||
`${dir}/${plugin}`,
|
||||
);
|
||||
|
||||
if (!manifestFile) {
|
||||
throw new Error(`Plugin ${plugin} is missing a manifest file`);
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ export class SonicSearchManager {
|
|||
* @param n Batch number
|
||||
* @param batchSize Size of the batch
|
||||
*/
|
||||
private getNthDatabaseAccountBatch(
|
||||
private static getNthDatabaseAccountBatch(
|
||||
n: number,
|
||||
batchSize = 1000,
|
||||
): Promise<Record<string, string | Date>[]> {
|
||||
|
|
@ -172,7 +172,7 @@ export class SonicSearchManager {
|
|||
* @param n Batch number
|
||||
* @param batchSize Size of the batch
|
||||
*/
|
||||
private getNthDatabaseStatusBatch(
|
||||
private static getNthDatabaseStatusBatch(
|
||||
n: number,
|
||||
batchSize = 1000,
|
||||
): Promise<Record<string, string | Date>[]> {
|
||||
|
|
@ -221,10 +221,11 @@ export class SonicSearchManager {
|
|||
const batchCount = Math.ceil(accountCount / batchSize);
|
||||
|
||||
for (let i = 0; i < batchCount; i++) {
|
||||
const accounts = await this.getNthDatabaseAccountBatch(
|
||||
i,
|
||||
batchSize,
|
||||
);
|
||||
const accounts =
|
||||
await SonicSearchManager.getNthDatabaseAccountBatch(
|
||||
i,
|
||||
batchSize,
|
||||
);
|
||||
await Promise.all(
|
||||
accounts.map((account) =>
|
||||
this.ingestChannel.push(
|
||||
|
|
@ -252,7 +253,10 @@ export class SonicSearchManager {
|
|||
const batchCount = Math.ceil(statusCount / batchSize);
|
||||
|
||||
for (let i = 0; i < batchCount; i++) {
|
||||
const statuses = await this.getNthDatabaseStatusBatch(i, batchSize);
|
||||
const statuses = await SonicSearchManager.getNthDatabaseStatusBatch(
|
||||
i,
|
||||
batchSize,
|
||||
);
|
||||
await Promise.all(
|
||||
statuses.map((status) =>
|
||||
this.ingestChannel.push(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue