Skip to content

Commit

Permalink
better promisifying the download images calls
Browse files Browse the repository at this point in the history
  • Loading branch information
pellicceama committed Aug 18, 2022
1 parent ba7eea3 commit 773c8cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
49 changes: 26 additions & 23 deletions src/model/Logos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,36 @@ export class Logos {
}

async downloadAndPersistLogos(directory: string): Promise<void> {
if(!this.png && !this.svg) {
return Promise.resolve();
}

if(this.png) {
try {
if(!fs.existsSync(path.join(directory, "logo.png"))) {
await downloadFile(this.png, directory, 'logo.png');
return new Promise(async (resolve) => {
if(!this.png && !this.svg) {
return resolve();
}

if(this.png) {
try {
if(!fs.existsSync(path.join(directory, "logo.png"))) {
await downloadFile(this.png, directory, 'logo.png');
}
this.png = getGithubHostedFileUrl(directory, 'logo.png');
} catch (err) {
console.error(`Error downloading png. Skipping: ${err}`)
}
this.png = getGithubHostedFileUrl(directory, 'logo.png');
} catch (err) {
console.error(`Error downloading png. Skipping: ${err}`)
}
}

if(this.svg) {
try {
if(!fs.existsSync(path.join(directory, "logo.svg"))) {
await downloadFile(this.svg, directory, 'logo.svg');

if(this.svg) {
try {
if(!fs.existsSync(path.join(directory, "logo.svg"))) {
await downloadFile(this.svg, directory, 'logo.svg');
}
this.svg = getGithubHostedFileUrl(directory, 'logo.svg');
} catch (err) {
console.error(`Error downloading svg. Skipping: ${err}`)
}
this.svg = getGithubHostedFileUrl(directory, 'logo.svg');
} catch (err) {
console.error(`Error downloading svg. Skipping: ${err}`)
}
}

return Promise.resolve();

return resolve();
});

}

static getLogosFromUri(logoURI?: string): Logos {
Expand Down
2 changes: 1 addition & 1 deletion src/validate/rules/network/NetworkImagesRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const NetworkImagesRules: ValidationRule[] = [
name: `${baseName}:ShouldHaveImagesRule`,
network: 'all',
validate: async (network: string, repoPath: string): Promise<ValidationResult> => {
// TODO: implement
// TODO: implement if it either has a png and/or svg in the info file but we can't find the images
return {
valid: true,
errors: []
Expand Down

0 comments on commit 773c8cf

Please sign in to comment.