feat: add lighthouse score in database fields
This commit is contained in:
parent
9cf46e679c
commit
6c2a093842
@ -0,0 +1,5 @@
|
|||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "WebsiteLighthouseReport" ADD COLUMN "accessibilityScore" INTEGER NOT NULL DEFAULT 0,
|
||||||
|
ADD COLUMN "bestPracticesScore" INTEGER NOT NULL DEFAULT 0,
|
||||||
|
ADD COLUMN "performanceScore" INTEGER NOT NULL DEFAULT 0,
|
||||||
|
ADD COLUMN "seoScore" INTEGER NOT NULL DEFAULT 0;
|
@ -260,6 +260,10 @@ model WebsiteLighthouseReport {
|
|||||||
url String
|
url String
|
||||||
result String // json string
|
result String // json string
|
||||||
status WebsiteLighthouseReportStatus @default(Pending)
|
status WebsiteLighthouseReportStatus @default(Pending)
|
||||||
|
performanceScore Int @default(0)
|
||||||
|
accessibilityScore Int @default(0)
|
||||||
|
bestPracticesScore Int @default(0)
|
||||||
|
seoScore Int @default(0)
|
||||||
|
|
||||||
@@index([createdAt])
|
@@index([createdAt])
|
||||||
@@index([websiteId])
|
@@index([websiteId])
|
||||||
|
@ -10,4 +10,8 @@ export const WebsiteLighthouseReportModelSchema = z.object({
|
|||||||
url: z.string(),
|
url: z.string(),
|
||||||
result: z.string(),
|
result: z.string(),
|
||||||
status: z.nativeEnum(WebsiteLighthouseReportStatus),
|
status: z.nativeEnum(WebsiteLighthouseReportStatus),
|
||||||
|
performanceScore: z.number().int(),
|
||||||
|
accessibilityScore: z.number().int(),
|
||||||
|
bestPracticesScore: z.number().int(),
|
||||||
|
seoScore: z.number().int(),
|
||||||
})
|
})
|
||||||
|
@ -38,6 +38,7 @@ import { generateLighthouse } from '../../utils/screenshot/lighthouse.js';
|
|||||||
import { WebsiteLighthouseReportModelSchema } from '../../prisma/zod/websitelighthousereport.js';
|
import { WebsiteLighthouseReportModelSchema } from '../../prisma/zod/websitelighthousereport.js';
|
||||||
import { buildCursorResponseSchema } from '../../utils/schema.js';
|
import { buildCursorResponseSchema } from '../../utils/schema.js';
|
||||||
import { logger } from '../../utils/logger.js';
|
import { logger } from '../../utils/logger.js';
|
||||||
|
import { get } from 'lodash-es';
|
||||||
|
|
||||||
const websiteNameSchema = z.string().max(100);
|
const websiteNameSchema = z.string().max(100);
|
||||||
const websiteDomainSchema = z.union([
|
const websiteDomainSchema = z.union([
|
||||||
@ -613,6 +614,19 @@ export const websiteRouter = router({
|
|||||||
generateLighthouse(url)
|
generateLighthouse(url)
|
||||||
.then(async (result) => {
|
.then(async (result) => {
|
||||||
logger.info('Successfully generated lighthouse report');
|
logger.info('Successfully generated lighthouse report');
|
||||||
|
|
||||||
|
const performanceScore =
|
||||||
|
Number(get(result, ['categories', 'performance', 'score'], 0)) *
|
||||||
|
100;
|
||||||
|
const accessibilityScore =
|
||||||
|
Number(get(result, ['categories', 'accessibility', 'score'], 0)) *
|
||||||
|
100;
|
||||||
|
const bestPracticesScore =
|
||||||
|
Number(get(result, ['categories', 'best-practices', 'score'], 0)) *
|
||||||
|
100;
|
||||||
|
const seoScore =
|
||||||
|
Number(get(result, ['categories', 'seo', 'score'], 0)) * 100;
|
||||||
|
|
||||||
await prisma.websiteLighthouseReport.update({
|
await prisma.websiteLighthouseReport.update({
|
||||||
where: {
|
where: {
|
||||||
id: websiteInfo.id,
|
id: websiteInfo.id,
|
||||||
@ -620,6 +634,10 @@ export const websiteRouter = router({
|
|||||||
data: {
|
data: {
|
||||||
status: WebsiteLighthouseReportStatus.Success,
|
status: WebsiteLighthouseReportStatus.Success,
|
||||||
result: JSON.stringify(result),
|
result: JSON.stringify(result),
|
||||||
|
performanceScore,
|
||||||
|
accessibilityScore,
|
||||||
|
bestPracticesScore,
|
||||||
|
seoScore,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user