Skip to content

Commit

Permalink
feat: use svgo for svg optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanvanherwijnen committed Jul 24, 2024
1 parent 57553de commit 1c8a046
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"pg": "^8.12.0",
"pg-boss": "^10.0.0-beta10",
"sharp": "^0.33.4",
"svgo": "^3.3.2",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down
62 changes: 60 additions & 2 deletions packages/api/src/trpc/admin/companies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type FastifyInstance } from 'fastify'
import { TRPCError } from '@trpc/server'
import { t } from '../index.js'
import { z } from 'zod'
import { optimize } from 'svgo'

import { company } from '../../zod/company.js'

Expand Down Expand Up @@ -36,10 +37,19 @@ export const adminCompanyRoutes = ({
telephoneNumber,
website,
prefix,
logoSvg,
defaultNumberPrefixTemplate,
defaultLocale
} = input

let logoSvg = input.logoSvg

if (logoSvg) {
const result = optimize(logoSvg, {
multipass: true
})
logoSvg = result.data
}

const result = await createCompany({
name,
contactPersonName,
Expand Down Expand Up @@ -72,11 +82,59 @@ export const adminCompanyRoutes = ({
}),
updateCompany: procedure.input(company).mutation(async ({ input }) => {
if (input.id) {
const {
name,
contactPersonName,
address,
postalCode,
city,
country,
email,
emailBcc,
cocNumber,
iban,
bic,
vatIdNumber,
telephoneNumber,
website,
prefix,
defaultNumberPrefixTemplate,
defaultLocale
} = input

let logoSvg = input.logoSvg

if (logoSvg) {
const result = optimize(logoSvg, {
multipass: true
})
logoSvg = result.data
}

const result = await updateCompany(
{
id: input.id
},
input
{
name,
contactPersonName,
address,
postalCode,
city,
country,
email,
emailBcc,
cocNumber,
iban,
bic,
vatIdNumber,
telephoneNumber,
website,
prefix,
logoSvg,
defaultNumberPrefixTemplate,
defaultLocale
}
)
if (result) return result
}
Expand Down
3 changes: 2 additions & 1 deletion packages/api/vitrify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export default async function ({ mode, command }): Promise<VitrifyConfig> {
'sharp',
'@mollie/api-client',
'axios',
'playwright'
'playwright',
'svgo'
]
},
manualChunks: ['api.config', 'zod', 'date-fns']
Expand Down
66 changes: 58 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1c8a046

Please sign in to comment.