From d2e7cb27bc56bb1d7b4d2a03c13487db19bd1788 Mon Sep 17 00:00:00 2001 From: Serg Dort Date: Fri, 27 Feb 2026 15:28:17 +0000 Subject: [PATCH 1/5] ci: add strict GitHub Actions workflow --- .github/workflows/ci.yml | 40 ++++++++++ README.md | 8 ++ apps/cli/src/cli.ts | 8 +- apps/web/src/app/app-shell.tsx | 59 +++++++++++---- .../src/features/inbox/ui/inbox-filters.tsx | 17 +++-- apps/web/src/features/save/ui/save-form.tsx | 7 +- .../src/features/status/ui/status-toggle.tsx | 7 +- apps/web/src/features/tags/api/tags-api.ts | 5 +- .../features/tts/api/list-item-tts-jobs.ts | 4 +- apps/web/src/features/tts/ui/tts-panel.tsx | 37 +++++++++- packages/core/src/features/common/db.ts | 6 +- packages/core/src/features/items/service.ts | 18 ++++- packages/core/src/features/status/service.ts | 10 ++- packages/core/src/features/tags/service.ts | 20 ++--- packages/core/src/features/tts/jobs.ts | 17 ++++- packages/core/src/features/tts/service.ts | 23 +++++- packages/core/src/lib/extract-x-browser.ts | 32 ++++---- packages/core/src/lib/extract.ts | 5 +- packages/core/src/lib/tts/command.ts | 6 +- packages/core/src/lib/tts/providers/gtts.ts | 4 +- .../core/src/lib/tts/providers/macos-say.ts | 35 +++++++-- packages/core/src/lib/tts/types.ts | 6 +- packages/core/test/extract-x-browser.test.ts | 17 ++++- packages/core/test/extract.test.ts | 12 ++- packages/core/test/tts-jobs.test.ts | 6 +- packages/web-server/src/app/server.ts | 4 +- packages/web-server/src/features/tts/dto.ts | 6 +- .../test/web-server.integration.test.ts | 74 +++++++++---------- 28 files changed, 356 insertions(+), 137 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1d54872 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,40 @@ +name: CI + +on: + pull_request: + push: + branches: [main] + +permissions: + contents: read + +concurrency: + group: ci-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + validate: + runs-on: ubuntu-latest + timeout-minutes: 25 + env: + CI: "true" + TZ: UTC + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + with: + version: 10.16.1 + - uses: actions/setup-node@v4 + with: + node-version-file: .nvmrc + cache: pnpm + - name: Install dependencies + run: pnpm install --frozen-lockfile + - name: Check formatting + run: pnpm run format:check + - name: Lint + run: pnpm run lint + - name: Test (includes TS build for dist) + run: pnpm run test + - name: Build web app + run: pnpm --dir apps/web build diff --git a/README.md b/README.md index b62dc74..4773038 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,14 @@ pnpm run format:check pnpm run check ``` +## CI + +GitHub Actions runs on pull requests and pushes to `main` with strict checks: + +```bash +pnpm run format:check && pnpm run lint && pnpm run test && pnpm --dir apps/web build +``` + To apply formatting and safe lint fixes: ```bash diff --git a/apps/cli/src/cli.ts b/apps/cli/src/cli.ts index b6b5bf6..fe4bbbf 100644 --- a/apps/cli/src/cli.ts +++ b/apps/cli/src/cli.ts @@ -40,12 +40,8 @@ const DEFAULT_WEB_DIST_DIR = resolveExistingPath([ path.resolve(process.cwd(), "apps/web/dist"), ]) const DEFAULT_WEB_HOST = process.env.STASH_WEB_HOST ?? "127.0.0.1" -const DEFAULT_API_PORT = process.env.STASH_API_PORT - ? parsePort(process.env.STASH_API_PORT) - : 4173 -const DEFAULT_PWA_PORT = process.env.STASH_PWA_PORT - ? parsePort(process.env.STASH_PWA_PORT) - : 5173 +const DEFAULT_API_PORT = process.env.STASH_API_PORT ? parsePort(process.env.STASH_API_PORT) : 4173 +const DEFAULT_PWA_PORT = process.env.STASH_PWA_PORT ? parsePort(process.env.STASH_PWA_PORT) : 5173 const DEFAULT_TTS_VOICE = "tts_models/en/vctk/vits|p241" // Coqui male voice type ItemStatus = "unread" | "read" | "archived" diff --git a/apps/web/src/app/app-shell.tsx b/apps/web/src/app/app-shell.tsx index ded9b64..735b6f3 100644 --- a/apps/web/src/app/app-shell.tsx +++ b/apps/web/src/app/app-shell.tsx @@ -17,7 +17,11 @@ import { useEffect, useMemo, useRef, useState } from "react" import { useExtract } from "../features/extract" import { useInbox } from "../features/inbox" -import type { InboxStatusFilter, InboxTagModeFilter, ListInboxItemsInput } from "../features/inbox/api/list-items" +import type { + InboxStatusFilter, + InboxTagModeFilter, + ListInboxItemsInput, +} from "../features/inbox/api/list-items" import { useItem } from "../features/item" import { useSaveItem } from "../features/save" import { useStatus } from "../features/status" @@ -25,14 +29,30 @@ import { useTags } from "../features/tags" import { useTts } from "../features/tts" import { AddIcon, InboxIcon } from "../shared/ui/icons" -const SaveForm = lazy(() => import("../features/save/ui/save-form").then((m) => ({ default: m.SaveForm }))) -const InboxFilters = lazy(() => import("../features/inbox/ui/inbox-filters").then((m) => ({ default: m.InboxFilters }))) -const InboxList = lazy(() => import("../features/inbox/ui/inbox-list").then((m) => ({ default: m.InboxList }))) -const ItemDetail = lazy(() => import("../features/item/ui/item-detail").then((m) => ({ default: m.ItemDetail }))) -const StatusToggle = lazy(() => import("../features/status/ui/status-toggle").then((m) => ({ default: m.StatusToggle }))) -const TagEditor = lazy(() => import("../features/tags/ui/tag-editor").then((m) => ({ default: m.TagEditor }))) -const ExtractButton = lazy(() => import("../features/extract/ui/extract-button").then((m) => ({ default: m.ExtractButton }))) -const TtsPanel = lazy(() => import("../features/tts/ui/tts-panel").then((m) => ({ default: m.TtsPanel }))) +const SaveForm = lazy(() => + import("../features/save/ui/save-form").then((m) => ({ default: m.SaveForm })), +) +const InboxFilters = lazy(() => + import("../features/inbox/ui/inbox-filters").then((m) => ({ default: m.InboxFilters })), +) +const InboxList = lazy(() => + import("../features/inbox/ui/inbox-list").then((m) => ({ default: m.InboxList })), +) +const ItemDetail = lazy(() => + import("../features/item/ui/item-detail").then((m) => ({ default: m.ItemDetail })), +) +const StatusToggle = lazy(() => + import("../features/status/ui/status-toggle").then((m) => ({ default: m.StatusToggle })), +) +const TagEditor = lazy(() => + import("../features/tags/ui/tag-editor").then((m) => ({ default: m.TagEditor })), +) +const ExtractButton = lazy(() => + import("../features/extract/ui/extract-button").then((m) => ({ default: m.ExtractButton })), +) +const TtsPanel = lazy(() => + import("../features/tts/ui/tts-panel").then((m) => ({ default: m.TtsPanel })), +) const MOBILE_SHELL_MAX_WIDTH = 680 @@ -166,9 +186,17 @@ export function AppShell(): JSX.Element { Filters - } label={`${unreadInView} unread`} /> + } + label={`${unreadInView} unread`} + /> - @@ -210,12 +238,17 @@ export function AppShell(): JSX.Element { {activeFilterCount > 0 ? ( {statusFilter !== "unread" ? ( - + ) : null} {selectedTags.slice(0, 3).map((tag) => ( ))} - {selectedTags.length > 3 ? : null} + {selectedTags.length > 3 ? ( + + ) : null} ) : null} diff --git a/apps/web/src/features/inbox/ui/inbox-filters.tsx b/apps/web/src/features/inbox/ui/inbox-filters.tsx index 59f680c..dfcf565 100644 --- a/apps/web/src/features/inbox/ui/inbox-filters.tsx +++ b/apps/web/src/features/inbox/ui/inbox-filters.tsx @@ -75,13 +75,16 @@ export function InboxFilters({ const selectedTagSet = useMemo(() => new Set(selectedTags), [selectedTags]) - const toggleTag = useCallback((tagName: string): void => { - if (selectedTagSet.has(tagName)) { - onSelectedTagsChange(selectedTags.filter((name) => name !== tagName)) - return - } - onSelectedTagsChange([...selectedTags, tagName]) - }, [onSelectedTagsChange, selectedTagSet, selectedTags]) + const toggleTag = useCallback( + (tagName: string): void => { + if (selectedTagSet.has(tagName)) { + onSelectedTagsChange(selectedTags.filter((name) => name !== tagName)) + return + } + onSelectedTagsChange([...selectedTags, tagName]) + }, + [onSelectedTagsChange, selectedTagSet, selectedTags], + ) const handleOpenTagsDrawer = useCallback((): void => { setTagsDrawerOpen(true) diff --git a/apps/web/src/features/save/ui/save-form.tsx b/apps/web/src/features/save/ui/save-form.tsx index 7947b3b..33cbe9f 100644 --- a/apps/web/src/features/save/ui/save-form.tsx +++ b/apps/web/src/features/save/ui/save-form.tsx @@ -14,7 +14,12 @@ import { import { AddIcon, ExternalLinkIcon, TagIcon } from "../../../shared/ui/icons" type SaveFormProps = { - onSave: (payload: { url: string; title?: string; tags?: string[]; extract?: boolean }) => Promise + onSave: (payload: { + url: string + title?: string + tags?: string[] + extract?: boolean + }) => Promise saving: boolean } diff --git a/apps/web/src/features/status/ui/status-toggle.tsx b/apps/web/src/features/status/ui/status-toggle.tsx index 219a0e8..ee7c348 100644 --- a/apps/web/src/features/status/ui/status-toggle.tsx +++ b/apps/web/src/features/status/ui/status-toggle.tsx @@ -11,7 +11,12 @@ type StatusToggleProps = { onToggle: (itemId: number, status: "read" | "unread") => Promise } -export function StatusToggle({ itemId, status, loading, onToggle }: StatusToggleProps): JSX.Element { +export function StatusToggle({ + itemId, + status, + loading, + onToggle, +}: StatusToggleProps): JSX.Element { const nextStatus = status === "read" ? "unread" : "read" return ( diff --git a/apps/web/src/features/tags/api/tags-api.ts b/apps/web/src/features/tags/api/tags-api.ts index 7dd35f4..7a85a08 100644 --- a/apps/web/src/features/tags/api/tags-api.ts +++ b/apps/web/src/features/tags/api/tags-api.ts @@ -9,7 +9,10 @@ export async function addTag(itemId: number, tag: string): Promise<{ ok: true; a return httpClient.post<{ ok: true; added: boolean }>(`/api/items/${itemId}/tags`, { tag }) } -export async function removeTag(itemId: number, tag: string): Promise<{ ok: true; removed: boolean }> { +export async function removeTag( + itemId: number, + tag: string, +): Promise<{ ok: true; removed: boolean }> { return httpClient.delete<{ ok: true; removed: boolean }>( `/api/items/${itemId}/tags/${encodeURIComponent(tag)}`, ) diff --git a/apps/web/src/features/tts/api/list-item-tts-jobs.ts b/apps/web/src/features/tts/api/list-item-tts-jobs.ts index e627cfc..0b41fcf 100644 --- a/apps/web/src/features/tts/api/list-item-tts-jobs.ts +++ b/apps/web/src/features/tts/api/list-item-tts-jobs.ts @@ -21,5 +21,7 @@ export async function listItemTtsJobs( limit: String(limit), offset: String(offset), }) - return httpClient.get(`/api/items/${itemId}/tts-jobs?${query.toString()}`) + return httpClient.get( + `/api/items/${itemId}/tts-jobs?${query.toString()}`, + ) } diff --git a/apps/web/src/features/tts/ui/tts-panel.tsx b/apps/web/src/features/tts/ui/tts-panel.tsx index 05ad0c2..3640d02 100644 --- a/apps/web/src/features/tts/ui/tts-panel.tsx +++ b/apps/web/src/features/tts/ui/tts-panel.tsx @@ -1,5 +1,15 @@ import { type JSX, useEffect, useMemo, useRef, useState } from "react" -import { Alert, Box, Button, Chip, IconButton, Link, Slider, Stack, Typography } from "@mui/material" +import { + Alert, + Box, + Button, + Chip, + IconButton, + Link, + Slider, + Stack, + Typography, +} from "@mui/material" import type { ItemTtsAudio } from "../../../shared/types" import type { TtsJob } from "../api/generate-tts" @@ -36,6 +46,11 @@ export function TtsPanel({ const [audioError, setAudioError] = useState(null) const playbackUrl = ttsAudio ? `/api/audio/${encodeURIComponent(ttsAudio.file_name)}` : null const downloadUrl = ttsAudio ? `${playbackUrl}?download=1` : null + const captionText = title?.trim().replace(/\s+/g, " ") || "stash audio" + const captionTrackSrc = useMemo(() => { + const vtt = `WEBVTT\n\n00:00:00.000 --> 99:59:59.000\n${captionText}\n` + return `data:text/vtt;charset=utf-8,${encodeURIComponent(vtt)}` + }, [captionText]) const isActiveJob = job?.status === "queued" || job?.status === "running" const audioRef = useRef(null) @@ -48,11 +63,14 @@ export function TtsPanel({ setIsPlaying(false) setDuration(0) setCurrentTime(0) + if (!playbackUrl) { + return + } }, [playbackUrl]) useEffect(() => { const audio = audioRef.current - if (!audio) return + if (!playbackUrl || !audio) return const onLoadedMetadata = (): void => { setDuration(audio.duration || 0) @@ -117,7 +135,10 @@ export function TtsPanel({ audio.currentTime = Math.max(0, audio.currentTime - 10) }) mediaSession.setActionHandler("seekforward", () => { - audio.currentTime = Math.min(audio.duration || Number.MAX_SAFE_INTEGER, audio.currentTime + 10) + audio.currentTime = Math.min( + audio.duration || Number.MAX_SAFE_INTEGER, + audio.currentTime + 10, + ) }) return () => { @@ -212,7 +233,15 @@ export function TtsPanel({ bgcolor: "rgba(15,23,42,0.03)", }} > -