feat(rices): refactor rice metadata retrieval and enhance HTML response

This commit is contained in:
mr. M 2024-12-30 07:41:20 +01:00
parent aa45364f4d
commit d5f39678c4
No known key found for this signature in database
GPG key ID: CBD57A2AEDBDA1FB
2 changed files with 19 additions and 7 deletions

View file

@ -60,22 +60,27 @@ export class RicesController {
})
@Get(':slug')
async getRice(@Param('slug') slug: string, @Res() res: Response) {
const riceMetadata = await this.ricesService.findOne(slug);
const riceMetadata = await this.ricesService.getRiceMetadata(slug);
const htmlContent = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="robots" content="noindex">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
const zenrice = ${riceMetadata};
</script>
<title>ZenRice download ${slug}</title>
<meta name="zen-content-verified" content="unverified">
<meta name="zen-rice-data" data-author="${riceMetadata.author}" data-name="${riceMetadata.name}" data-id="${riceMetadata.id}">
<title>Zen Rice - ${riceMetadata.name}</title>
</head>
<body>
<script>
<script defer>
document.addEventListener('DOMContentLoaded', () => {
window.location.href = 'https://zen-browser.app/download';
/* Set time out so the meta tag is set after the next DOM repaint */
setTimeout(() => {
if (document.querySelector('meta[name="zen-content-verified"]')?.content !== 'verified') {
window.location.replace('https://zen-browser.app/download');
}
});
});
</script>
<!-- Body content is intentionally left blank -->

View file

@ -170,6 +170,13 @@ export class RicesService {
return fileContent;
}
async getRiceMetadata(slug: string) {
const rice = await this.supabaseService.getRiceBySlug(slug);
if (!rice) throw new NotFoundException('Rice not found');
return rice;
}
async update(
slug: string,
token: string,