mirror of
https://github.com/unraid/api.git
synced 2026-01-01 14:10:10 -06:00
feat: glob for files
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { existsSync, write } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { readdir, readFile, writeFile } from 'fs/promises';
|
import { glob, readFile, writeFile } from 'fs/promises';
|
||||||
import path from 'path';
|
|
||||||
|
|
||||||
import { logger } from '@app/core/log';
|
import { logger } from '@app/core/log';
|
||||||
|
|
||||||
@@ -8,29 +7,17 @@ import { logger } from '@app/core/log';
|
|||||||
const AUTH_REQUEST_FILE = '/usr/local/emhttp/auth-request.php';
|
const AUTH_REQUEST_FILE = '/usr/local/emhttp/auth-request.php';
|
||||||
const WEB_COMPS_DIR = '/usr/local/emhttp/plugins/dynamix.my.servers/unraid-components/_nuxt/';
|
const WEB_COMPS_DIR = '/usr/local/emhttp/plugins/dynamix.my.servers/unraid-components/_nuxt/';
|
||||||
|
|
||||||
|
const getJsFiles = async (dir: string) => {
|
||||||
|
const files = await glob(`${dir}/**/*.js`);
|
||||||
|
const filesArray: string[] = [];
|
||||||
|
for await (const file of files) {
|
||||||
|
filesArray.push(file.replace('/usr/local/emhttp', ''));
|
||||||
|
}
|
||||||
|
return filesArray;
|
||||||
|
};
|
||||||
|
|
||||||
export const setupAuthRequest = async () => {
|
export const setupAuthRequest = async () => {
|
||||||
// Function to log debug messages
|
const JS_FILES = await getJsFiles(WEB_COMPS_DIR);
|
||||||
// Find all .js files in WEB_COMPS_DIR
|
|
||||||
const getJSFiles = async (dir) => {
|
|
||||||
const jsFiles: string[] = [];
|
|
||||||
|
|
||||||
const findFiles = async (currentDir) => {
|
|
||||||
const files = await readdir(currentDir, { withFileTypes: true });
|
|
||||||
for (const file of files) {
|
|
||||||
const fullPath = path.join(currentDir, file.name);
|
|
||||||
if (file.isDirectory()) {
|
|
||||||
findFiles(fullPath);
|
|
||||||
} else if (file.isFile() && file.name.endsWith('.js')) {
|
|
||||||
jsFiles.push(fullPath.replace('/usr/local/emhttp', ''));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
await findFiles(dir);
|
|
||||||
return jsFiles;
|
|
||||||
};
|
|
||||||
|
|
||||||
const JS_FILES = await getJSFiles(WEB_COMPS_DIR);
|
|
||||||
logger.debug(`Found ${JS_FILES.length} .js files in ${WEB_COMPS_DIR}`);
|
logger.debug(`Found ${JS_FILES.length} .js files in ${WEB_COMPS_DIR}`);
|
||||||
|
|
||||||
const FILES_TO_ADD = ['/webGui/images/partner-logo.svg', ...JS_FILES];
|
const FILES_TO_ADD = ['/webGui/images/partner-logo.svg', ...JS_FILES];
|
||||||
|
|||||||
Reference in New Issue
Block a user