80 lines
3.0 KiB
JavaScript
80 lines
3.0 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const publicImagesDir = '/ADPanel/ADPanel-Enterprise/public/images';
|
|
const localFiles = fs.readdirSync(publicImagesDir);
|
|
const localFilesLower = new Map(localFiles.map(f => [f.toLowerCase(), f]));
|
|
|
|
const scanDirs = ['views', 'public', 'data', 'scripts', 'utils', 'routes', 'Store', 'Templates'];
|
|
|
|
function getFiles() {
|
|
const fileList = [];
|
|
const rootFiles = fs.readdirSync('/ADPanel/ADPanel-Enterprise');
|
|
for (const f of rootFiles) {
|
|
if (f.endsWith('.json') || f.endsWith('.js') || f.endsWith('.html') || f.endsWith('.md')) {
|
|
fileList.push(path.join('/ADPanel/ADPanel-Enterprise', f));
|
|
}
|
|
}
|
|
for (const dir of scanDirs) {
|
|
const fullDir = path.join('/ADPanel/ADPanel-Enterprise', dir);
|
|
if (!fs.existsSync(fullDir)) continue;
|
|
function walkDir(d) {
|
|
if (d.includes('/public/images') || d.includes('/public/uploads')) return;
|
|
for (const item of fs.readdirSync(d)) {
|
|
const itemPath = path.join(d, item);
|
|
const st = fs.statSync(itemPath);
|
|
if (st.isDirectory()) {
|
|
walkDir(itemPath);
|
|
} else if (item.endsWith('.ejs') || item.endsWith('.js') || item.endsWith('.html') || item.endsWith('.css') || item.endsWith('.json')) {
|
|
fileList.push(itemPath);
|
|
}
|
|
}
|
|
}
|
|
walkDir(fullDir);
|
|
}
|
|
return fileList;
|
|
}
|
|
|
|
const files = getFiles();
|
|
|
|
const cdnReferences = new Map();
|
|
const imgReferences = new Map();
|
|
|
|
for (const file of files) {
|
|
const content = fs.readFileSync(file, 'utf8');
|
|
for (const m of content.matchAll(/https:\/\/cdn\.jsdelivr\.net\/gh\/antonndev\/ADCDn\/([a-zA-Z0-9_.-]+)/g)) {
|
|
const asset = m[1].split('?')[0].split('#')[0];
|
|
if (!cdnReferences.has(asset)) cdnReferences.set(asset, []);
|
|
cdnReferences.get(asset).push(file);
|
|
}
|
|
for (const m of content.matchAll(/\/images\/([a-zA-Z0-9_.-]+)/g)) {
|
|
const asset = m[1].split('?')[0].split('#')[0];
|
|
if (!imgReferences.has(asset)) imgReferences.set(asset, []);
|
|
imgReferences.get(asset).push(file);
|
|
}
|
|
}
|
|
|
|
console.log('=== Checking CDN References against local public/images ===');
|
|
let missingCdn = 0;
|
|
for (const [asset, fileList] of cdnReferences.entries()) {
|
|
const existsExact = fs.existsSync(path.join(publicImagesDir, asset));
|
|
if (!existsExact) {
|
|
console.log(`[MISSING CDN ASSET] ${asset} referenced in:`);
|
|
fileList.slice(0, 3).forEach(f => console.log(' - ' + f));
|
|
missingCdn++;
|
|
}
|
|
}
|
|
if (missingCdn === 0) console.log('ALL CDN referenced assets exist locally in public/images!');
|
|
|
|
console.log('\n=== Checking /images/ References against local public/images ===');
|
|
let missingImg = 0;
|
|
for (const [asset, fileList] of imgReferences.entries()) {
|
|
const existsExact = fs.existsSync(path.join(publicImagesDir, asset));
|
|
if (!existsExact) {
|
|
console.log(`[MISSING LOCAL /images/ ASSET] ${asset} referenced in:`);
|
|
fileList.slice(0, 3).forEach(f => console.log(' - ' + f));
|
|
missingImg++;
|
|
}
|
|
}
|
|
if (missingImg === 0) console.log('ALL /images/ referenced assets exist locally in public/images!');
|