Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikskog committed May 6, 2024
1 parent 71de5f3 commit efcb7f1
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 34 deletions.
4 changes: 2 additions & 2 deletions apps/dashboard/src/app/(dashboard)/offline/write-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ interface UseOfflineWriteFormProps {
}

export const FormValidationSchema = OfflineWriteSchema.omit({
imageId: true
imageId: true,
}).extend({
image: ImageSchema
image: ImageSchema,
})
type FormValidationSchema = z.infer<typeof FormValidationSchema>

Expand Down
8 changes: 3 additions & 5 deletions apps/dashboard/src/app/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export function createImageInput<F extends FieldValues>({
return (
<Box>
<Text>{props.label}</Text>
{state.errors[name] && <ErrorMessage errors={state.errors} name={name} /> }
{state.errors[name] && <ErrorMessage errors={state.errors} name={name} />}
<Controller
control={control}
name={name}
Expand All @@ -272,9 +272,7 @@ export function createImageInput<F extends FieldValues>({
return (
<ImageUpload
onSubmit={(data) => {
field.onChange(
data
)
field.onChange(data)
}}
defaultValues={field.value}
aspect={props.aspect}
Expand All @@ -294,7 +292,7 @@ export function createFileInput<F extends FieldValues>({
return (
<Box>
<Text>{props.label}</Text>
{state.errors[name] && <ErrorMessage errors={state.errors} name={name} /> }
{state.errors[name] && <ErrorMessage errors={state.errors} name={name} />}
<Controller
control={control}
name={name}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client"
import { Anchor } from "@mantine/core"
import type React from "react"
import { useUploadAssetToS3 } from "../../../modules/asset/mutations"
import { Anchor } from "@mantine/core"
import { buildAssetUrl } from "../../../utils/s3"

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ export function CropPreview({ imgSrc, completedCrop, imgRef, scale, hidden }: Sh
const canvasRef = useRef<HTMLCanvasElement>(null)

function renderCanvasPreview() {
if(!imgRef.current) {
if (!imgRef.current) {
console.error("Tried to render canvas preview before image was loaded")
return
}

const crop: PixelCrop = completedCrop ? completedCrop : { x: 0, y: 0, width: imgRef.current?.width, height: imgRef.current.height , unit: "px" }
if (imgRef.current && canvasRef.current) {
// We use canvasPreview as it's much faster than imgPreview.
console.log("canvasPreview")
canvasPreview(imgRef.current, canvasRef.current, crop, scale)
}
const crop: PixelCrop = completedCrop
? completedCrop
: { x: 0, y: 0, width: imgRef.current?.width, height: imgRef.current.height, unit: "px" }
if (imgRef.current && canvasRef.current) {
// We use canvasPreview as it's much faster than imgPreview.
console.log("canvasPreview")
canvasPreview(imgRef.current, canvasRef.current, crop, scale)
}
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export default function ImageUpload({ onSubmit, aspect, defaultValues }: Props)

// Default values are set meaning we are updating an existing image
console.log("toInsert", toInsert)
const res = await updateImage.mutateAsync(toInsert)
onSubmit(res)
const res = await updateImage.mutateAsync(toInsert)
onSubmit(res)
return
}

Expand Down Expand Up @@ -207,7 +207,13 @@ export default function ImageUpload({ onSubmit, aspect, defaultValues }: Props)
</button>
</div>
)}
<CropPreview imgSrc={imgSrc} completedCrop={completedCrop} imgRef={imgRef} scale={scale} hidden={cropOpen || !imgSrc}/>
<CropPreview
imgSrc={imgSrc}
completedCrop={completedCrop}
imgRef={imgRef}
scale={scale}
hidden={cropOpen || !imgSrc}
/>
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export async function canvasPreview(image: HTMLImageElement, canvas: HTMLCanvasE
naturalWidth: image.naturalWidth,
naturalHeight: image.naturalHeight,
crop,
image
image,
})
const ctx = canvas.getContext("2d")

Expand Down
2 changes: 0 additions & 2 deletions apps/dashboard/src/utils/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function buildFinalCloudflareUrl(options: string, assetUrl: string) {
return `${cloudflareImagesBaseUrl}/${options}/${assetUrl}`
}


type Size = { w?: number; h?: number }
export function buildImgUrl(image: Image, size?: Size) {
const assetUrl = buildAssetUrl(image.assetId)
Expand Down Expand Up @@ -69,6 +68,5 @@ export function buildImgUrl(image: Image, size?: Size) {

const optionsString = options.join(",")


return buildFinalCloudflareUrl(optionsString, assetUrl)
}
22 changes: 11 additions & 11 deletions packages/core/src/modules/offline/offline-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ export interface PresignedPost {

function encodeS3URI(filename: string): string {
// Define characters that are generally safe for use in key names
const safeCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!-_.*\'()';
const safeCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!-_.*'()"

// Replace unsafe characters with safe ones
const safeFilename = filename.replace(/[^a-zA-Z0-9!-_.*'()]/g, (match) => {
// Replace unsafe characters with underscore
if (!safeCharacters.includes(match)) {
return '_';
}
return match;
});
// Replace unsafe characters with underscore
if (!safeCharacters.includes(match)) {
return "_"
}
return match
})

// Ensure the key name is not empty
if (safeFilename.trim() === '') {
throw new Error('Filename results in an empty key name.');
if (safeFilename.trim() === "") {
throw new Error("Filename results in an empty key name.")
}

return safeFilename;
return safeFilename
}

export interface OfflineService {
Expand Down Expand Up @@ -77,7 +77,7 @@ export class OfflineServiceImpl implements OfflineService {
}

async createPresignedPost(filename: string, mimeType: string) {
const generatedKey = crypto.randomUUID() + filename
const generatedKey = crypto.randomUUID() + filename
const encodedKey = encodeS3URI(generatedKey)
console.log("Generated asset key", encodedKey)
const presignedUrl = await this.s3Repository.createPresignedPost(
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/offline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const OfflineSchema = z.object({

export const OfflineWriteSchema = OfflineSchema.omit({
id: true,
image: true
image: true,
}).extend({
imageId: z.string(),
})
Expand Down
1 change: 0 additions & 1 deletion tools/migrator/src/fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
getJobListingLocationLinkFixtures,
} from "./fixtures/job-listing"
import { getMarkFixtures } from "./fixtures/mark"
import { getOfflineFixtures } from "./fixtures/offline"
import { getProductFixtures } from "./fixtures/product"
import { getProductPaymentProviderFixtures } from "./fixtures/product-payment-provider"

Expand Down

0 comments on commit efcb7f1

Please sign in to comment.