mirror of
https://github.com/0belous/universal-plugin-repo.git
synced 2025-12-20 03:31:18 -03:00
Add source code to description
This commit is contained in:
parent
707db18220
commit
94ddb3fe88
1 changed files with 40 additions and 1 deletions
41
update.js
41
update.js
|
|
@ -50,7 +50,7 @@ async function clearImagesFolder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function downloadImage(url, filename) {
|
async function downloadImage(url, filename) {
|
||||||
console.log(` -> Downloading image: ${url} as ${filename}`);
|
console.log(`Downloading image: ${url} as ${filename}`);
|
||||||
try {
|
try {
|
||||||
const res = await fetch(url, { headers: { 'User-Agent': userAgent } });
|
const res = await fetch(url, { headers: { 'User-Agent': userAgent } });
|
||||||
if (!res.ok) throw new Error(`Failed to fetch image: ${res.status}`);
|
if (!res.ok) throw new Error(`Failed to fetch image: ${res.status}`);
|
||||||
|
|
@ -76,6 +76,44 @@ function hashString(str) {
|
||||||
return crypto.createHash('md5').update(str).digest('hex');
|
return crypto.createHash('md5').update(str).digest('hex');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findGithubUrl(obj) {
|
||||||
|
if (!obj) return null;
|
||||||
|
for (const key in obj) {
|
||||||
|
if (typeof obj[key] === 'string') {
|
||||||
|
const match = obj[key].match(/https?:\/\/github\.com\/[^\/]+\/[^\/]+/);
|
||||||
|
if (match) {
|
||||||
|
return match[0];
|
||||||
|
}
|
||||||
|
} else if (typeof obj[key] === 'object' && obj[key] !== null) {
|
||||||
|
const url = findGithubUrl(obj[key]);
|
||||||
|
if (url) return url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function processDescriptions(pluginData) {
|
||||||
|
try {
|
||||||
|
for (const plugin of pluginData) {
|
||||||
|
const repoUrl = findGithubUrl(plugin);
|
||||||
|
if (repoUrl) {
|
||||||
|
const sourceLink = `\n\n[Source Code](${repoUrl})`;
|
||||||
|
const descriptionProp = plugin.overview ? 'overview' : (plugin.Description ? 'Description' : null);
|
||||||
|
if (descriptionProp) {
|
||||||
|
if (!plugin[descriptionProp].includes(repoUrl)) {
|
||||||
|
plugin[descriptionProp] += sourceLink;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
plugin.overview = sourceLink.trim();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(`Sucessfully injected source URLs`);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error processing descriptions:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function processImages(pluginData) {
|
async function processImages(pluginData) {
|
||||||
await clearImagesFolder();
|
await clearImagesFolder();
|
||||||
for (const plugin of pluginData) {
|
for (const plugin of pluginData) {
|
||||||
|
|
@ -113,6 +151,7 @@ async function writeManifest(dataToWrite){
|
||||||
async function main() {
|
async function main() {
|
||||||
const plugins = await getSources();
|
const plugins = await getSources();
|
||||||
await processImages(plugins);
|
await processImages(plugins);
|
||||||
|
await processDescriptions(plugins);
|
||||||
await writeManifest(plugins);
|
await writeManifest(plugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue