π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Refactor code structure for improved readability and maintainability
Aswin Asok29221b4ed7cc
diff --git a/web/apps/paste/eslint.config.mjs b/web/apps/paste/eslint.config.mjsindex 641d994d1e..7afc362f15 100644--- a/web/apps/paste/eslint.config.mjs+++ b/web/apps/paste/eslint.config.mjs@@ -1 +1,9 @@-export { default } from "ente-build-config/eslintrc-next-app.mjs";+import baseConfig from "ente-build-config/eslintrc-next-app.mjs";++export default [+ ...baseConfig,+ {+ // Vendored upstream QR generator source; keep lint checks off this file.+ ignores: ["src/features/paste/utils/qrcodegen.ts"],+ },+];diff --git a/web/apps/paste/public/images/pastelogo.png b/web/apps/paste/public/images/pastelogo.pngnew file mode 100644index 0000000000..27c235ac68Binary files /dev/null and b/web/apps/paste/public/images/pastelogo.png differdiff --git a/web/apps/paste/src/features/paste/components/PasteFrame.tsx b/web/apps/paste/src/features/paste/components/PasteFrame.tsxindex 3a7f375d1a..48379bf251 100644--- a/web/apps/paste/src/features/paste/components/PasteFrame.tsx+++ b/web/apps/paste/src/features/paste/components/PasteFrame.tsx@@ -1,5 +1,5 @@import GitHubIcon from "@mui/icons-material/GitHub";-import { Box, IconButton, Typography } from "@mui/material";+import { Box, IconButton } from "@mui/material";import type { ReactNode } from "react";interface PasteFrameProps {@@ -60,16 +60,17 @@ export const PasteFrame = ({ children, footer }: PasteFrameProps) => (pt: { xs: 3, md: 3.5 },}}>- <Typography+ <Box+ component="img"+ src="/images/pastelogo.png"+ alt="Ente Paste"sx={{- fontSize: { xs: "1.5rem", md: "1.75rem" },- lineHeight: 1.05,- fontWeight: 700,- color: "#f4f7ff",+ display: "block",+ width: "auto",+ height: { xs: 34, md: 40 },+ maxWidth: { xs: 220, md: 260 },}}- >- Ente Paste- </Typography>+ /><IconButtoncomponent="a"href="https://github.com/ente-io/ente"diff --git a/web/apps/paste/src/features/paste/components/PasteLinkCard.tsx b/web/apps/paste/src/features/paste/components/PasteLinkCard.tsxindex b6c6291f97..43671ca711 100644--- a/web/apps/paste/src/features/paste/components/PasteLinkCard.tsx+++ b/web/apps/paste/src/features/paste/components/PasteLinkCard.tsx@@ -70,11 +70,11 @@ export const PasteLinkCard = ({const response = await fetch("/arrow.json");if (!response.ok) return;- const json = await response.json();+ const json: unknown = await response.json();if (cancelled) return;const parsed = parseArrowLottie(json);- if (!cancelled) setArrow(parsed);+ setArrow(parsed);} catch {// No-op: The link row works without the hint animation.}@@ -113,8 +113,7 @@ export const PasteLinkCard = ({};}).filter(- (item): item is MeasuredPath =>- item.parsed !== undefined && item.parsed !== null,+ (item): item is MeasuredPath => item.parsed !== undefined,);for (const { path, len, parsed } of measured) {diff --git a/web/apps/paste/src/features/paste/utils/lottie.ts b/web/apps/paste/src/features/paste/utils/lottie.tsindex 4c720279f9..09b367d057 100644--- a/web/apps/paste/src/features/paste/utils/lottie.ts+++ b/web/apps/paste/src/features/paste/utils/lottie.ts@@ -24,13 +24,83 @@ export interface ParsedArrow {width: number;}+const isRecord = (value: unknown): value is Record<string, unknown> =>+ typeof value === "object" && value !== null;++const toRecordArray = (value: unknown): Record<string, unknown>[] | undefined => {+ if (!Array.isArray(value)) return undefined;++ const records: Record<string, unknown>[] = [];+ for (const item of value) {+ if (isRecord(item)) records.push(item);+ }++ return records;+};++const toNumber = (value: unknown, fallback: number) =>+ typeof value === "number" ? value : fallback;++const toNumberArray = (value: unknown): number[] | undefined =>+ Array.isArray(value) && value.every((item) => typeof item === "number")+ ? value+ : undefined;++const toNestedRecord = (+ object: Record<string, unknown>,+ key: string,+): Record<string, unknown> | undefined => {+ const value = object[key];+ return isRecord(value) ? value : undefined;+};++const toPoint = (value: unknown): LottiePoint | null => {+ if (!Array.isArray(value)) return null;++ const coordinates = value as unknown[];+ const x = coordinates[0];+ const y = coordinates[1];+ if (typeof x !== "number" || typeof y !== "number") return null;++ return [x, y];+};++const toPoints = (value: unknown): LottiePoint[] | null => {+ if (!Array.isArray(value)) return null;++ const points: LottiePoint[] = [];+ for (const item of value) {+ const point = toPoint(item);+ if (!point) return null;+ points.push(point);+ }++ return points;+};++const toShapePath = (value: unknown): LottieShapePath | null => {+ if (!isRecord(value)) return null;++ const i = toPoints(value.i);+ const o = toPoints(value.o);+ const v = toPoints(value.v);+ if (!i || !o || !v) return null;++ return {+ c: value.c === true,+ i,+ o,+ v,+ };+};+const safePoint = (point?: LottiePoint): [number, number] => [point?.[0] ?? 0,point?.[1] ?? 0,];const toPathD = (shape: LottieShapePath) => {- if (!shape?.v?.length) return "";+ if (!shape.v.length) return "";const { c, i, o, v } = shape;const [startX, startY] = safePoint(v[0]);@@ -81,54 +151,77 @@ const toLineCap = (value: number): ParsedArrowPath["lineCap"] =>const toLineJoin = (value: number): ParsedArrowPath["lineJoin"] =>value === 2 ? "round" : value === 3 ? "bevel" : "miter";-const toRGB = (rgb: number[]) => {- const r = Number(rgb?.[0] ?? 1);- const g = Number(rgb?.[1] ?? 1);- const b = Number(rgb?.[2] ?? 1);+const toRGB = (rgb: readonly number[]) => {+ const r = Number(rgb[0] ?? 1);+ const g = Number(rgb[1] ?? 1);+ const b = Number(rgb[2] ?? 1);return `rgb(${Math.round(r * 255)} ${Math.round(g * 255)} ${Math.round(b * 255)})`;};-export const parseArrowLottie = (lottie: any): ParsedArrow | null => {- const layer = lottie?.layers?.[0];- if (!layer?.shapes?.length) return null;+export const parseArrowLottie = (lottie: unknown): ParsedArrow | null => {+ if (!isRecord(lottie)) return null;++ const layers = toRecordArray(lottie.layers);+ const layer = layers?.[0];+ if (!layer) return null;++ const groups = toRecordArray(layer.shapes);+ if (!groups?.length) return null;++ const ks = toNestedRecord(layer, "ks");+ const scaleValues = ks+ ? toNumberArray(toNestedRecord(ks, "s")?.k)+ : undefined;+ const positionValues = ks+ ? toNumberArray(toNestedRecord(ks, "p")?.k)+ : undefined;- const sx = (Number(layer?.ks?.s?.k?.[0] ?? 100) || 100) / 100;- const sy =- (Number(layer?.ks?.s?.k?.[1] ?? layer?.ks?.s?.k?.[0] ?? 100) || 100) /- 100;- const px = Number(layer?.ks?.p?.k?.[0] ?? 0) || 0;- const py = Number(layer?.ks?.p?.k?.[1] ?? 0) || 0;+ const sx = (toNumber(scaleValues?.[0], 100) || 100) / 100;+ const sy = (toNumber(scaleValues?.[1], scaleValues?.[0] ?? 100) || 100) / 100;+ const px = toNumber(positionValues?.[0], 0) || 0;+ const py = toNumber(positionValues?.[1], 0) || 0;const paths: ParsedArrowPath[] = [];- for (const group of layer.shapes) {- if (group?.ty !== "gr" || !Array.isArray(group?.it)) continue;+ for (const group of groups) {+ if (group.ty !== "gr") continue;- const shape = group.it.find((item: any) => item?.ty === "sh")?.ks?.k as- | LottieShapePath- | undefined;- const stroke = group.it.find((item: any) => item?.ty === "st");+ const items = toRecordArray(group.it);+ if (!items) continue;++ const shapeItem = items.find((item) => item.ty === "sh");+ const stroke = items.find((item) => item.ty === "st");++ const shape = shapeItem+ ? toShapePath(toNestedRecord(shapeItem, "ks")?.k)+ : null;if (!shape || !stroke) continue;- const groupName = String(group?.nm ?? "");++ const groupName = typeof group.nm === "string" ? group.nm : "";const d = toPathD(shape);if (!d) continue;+ const strokeColor = toNumberArray(toNestedRecord(stroke, "c")?.k) ?? [+ 1, 1, 1,+ ];+ const strokeWidth = toNumber(toNestedRecord(stroke, "w")?.k, 2);+paths.push({- color: toRGB(stroke?.c?.k),+ color: toRGB(strokeColor),d,- lineCap: toLineCap(Number(stroke?.lc ?? 1)),- lineJoin: toLineJoin(Number(stroke?.lj ?? 1)),+ lineCap: toLineCap(toNumber(stroke.lc, 1)),+ lineJoin: toLineJoin(toNumber(stroke.lj, 1)),name: groupName,strokeScale: 0.58,- width: Number(stroke?.w?.k ?? 2),+ width: strokeWidth,});}if (!paths.length) return null;return {- height: Number(lottie?.h ?? 84) || 84,+ height: toNumber(lottie.h, 84) || 84,paths,transform: `translate(${px} ${py}) scale(${sx} ${sy})`,- width: Number(lottie?.w ?? 150) || 150,+ width: toNumber(lottie.w, 150) || 150,};};