Skip to content

Commit

Permalink
fix: Include link to photographer in random image
Browse files Browse the repository at this point in the history
refs: #1435
  • Loading branch information
Zachatoo committed Sep 4, 2024
1 parent 6f1236a commit c81bc7d
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/core/functions/internal_functions/web/InternalModuleWeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export class InternalModuleWeb extends InternalModule {
"random_picture",
this.generate_random_picture()
);

}

async create_dynamic_templates(): Promise<void> {}
Expand Down Expand Up @@ -73,31 +72,30 @@ export class InternalModuleWeb extends InternalModule {
}
}
if (include_size) {
return `![photo by ${response.photog} on Unsplash|${size}](${url})`;
return `![photo by ${response.photog}(${response.photogUrl}) on Unsplash|${size}](${url})`;
}
return `![photo by ${response.photog} on Unsplash](${url})`;
return `![photo by ${response.photog}(${response.photogUrl}) on Unsplash](${url})`;
} catch (error) {
new TemplaterError("Error generating random picture");
return "Error generating random picture";
}
};
}

generate_request(): (
url: string,
path?: string,
) => Promise<string> {
generate_request(): (url: string, path?: string) => Promise<string> {
return async (url: string, path?: string) => {
try {
const response = await this.getRequest(url);
const jsonData = await response.json();

if (path && jsonData) {
return path.split('.').reduce((obj, key) => {
return path.split(".").reduce((obj, key) => {
if (obj && obj.hasOwnProperty(key)) {
return obj[key];
} else {
throw new Error(`Path ${path} not found in the JSON response`);
throw new Error(
`Path ${path} not found in the JSON response`
);
}
}, jsonData);
}
Expand Down

0 comments on commit c81bc7d

Please sign in to comment.