From dd97a923be634547480f376f1f71f71e20dfd3aa Mon Sep 17 00:00:00 2001 From: WardPearce Date: Fri, 3 May 2024 14:55:21 +1200 Subject: [PATCH] Fix liniting --- .github/workflows/vite-checks.yml | 26 ++++++++++ materialious/src/.d.ts | 3 +- materialious/src/lib/Api/index.ts | 50 ++++++++----------- materialious/src/lib/Player.svelte | 4 +- materialious/src/lib/i18n/locales/en.json | 2 +- materialious/src/lib/i18n/locales/ru.json | 2 +- materialious/src/lib/misc.ts | 15 +++--- materialious/src/routes/+error.svelte | 4 +- .../src/routes/search/[slug]/+page.ts | 2 +- materialious/src/routes/watch/[slug]/+page.ts | 15 ++++-- materialious/src/store.ts | 14 ++++-- materialious/tsconfig.json | 16 ++---- materialious/vite.config.ts | 26 +++++----- 13 files changed, 103 insertions(+), 76 deletions(-) create mode 100644 .github/workflows/vite-checks.yml diff --git a/.github/workflows/vite-checks.yml b/.github/workflows/vite-checks.yml new file mode 100644 index 00000000..2dfdf6f7 --- /dev/null +++ b/.github/workflows/vite-checks.yml @@ -0,0 +1,26 @@ +name: Development Vite workflow + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./materialious + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + - name: Install modules + run: npm install + - name: Check linting + run: npm run check + - name: Attempt to build codebase + run: npm run build \ No newline at end of file diff --git a/materialious/src/.d.ts b/materialious/src/.d.ts index 3a8ede95..a80c297c 100644 --- a/materialious/src/.d.ts +++ b/materialious/src/.d.ts @@ -1 +1,2 @@ -declare module 'virtual:pwa-info'; \ No newline at end of file +declare module 'virtual:pwa-info'; +declare type ui = import('beercss').ui; diff --git a/materialious/src/lib/Api/index.ts b/materialious/src/lib/Api/index.ts index 4d6fa107..9d2a67fc 100644 --- a/materialious/src/lib/Api/index.ts +++ b/materialious/src/lib/Api/index.ts @@ -34,14 +34,14 @@ export async function fetchErrorHandle(response: Response): Promise { try { const json = await response.json(); message = 'errorBacktrace' in json ? json.errorBacktrace : json.error; - } catch { } + } catch {} throw Error(message); } return response; } -export function buildAuthHeaders(): { headers: { Authorization: string; }; } { +export function buildAuthHeaders(): { headers: { Authorization: string } } { return { headers: { Authorization: `Bearer ${get(authStore)?.token}` } }; } @@ -191,7 +191,10 @@ export async function deleteUnsubscribe(authorId: string) { export async function getHistory(page: number = 1, maxResults: number = 20): Promise { const resp = await fetchErrorHandle( - await fetch(buildPath(`auth/history?page=${page}&max_results=${maxResults}`), buildAuthHeaders()) + await fetch( + buildPath(`auth/history?page=${page}&max_results=${maxResults}`), + buildAuthHeaders() + ) ); return await resp.json(); } @@ -320,39 +323,30 @@ export async function saveVideoProgress(videoId: string, time: number) { headers['headers']['Content-type'] = 'application/json'; await fetchErrorHandle( - await fetch( - `${get(synciousInstanceStore)}/video/${encodeURIComponent(videoId)}`, - { - ...headers, - method: "POST", - body: JSON.stringify({ - time: time - }) - } - ) + await fetch(`${get(synciousInstanceStore)}/video/${encodeURIComponent(videoId)}`, { + ...headers, + method: 'POST', + body: JSON.stringify({ + time: time + }) + }) ); } export async function deleteVideoProgress(videoId: string) { await fetchErrorHandle( - await fetch( - `${get(synciousInstanceStore)}/video/${videoId}`, - { - method: "DELETE", - ...buildAuthHeaders() - } - ) + await fetch(`${get(synciousInstanceStore)}/video/${videoId}`, { + method: 'DELETE', + ...buildAuthHeaders() + }) ); } export async function deleteAllVideoProgress() { await fetchErrorHandle( - await fetch( - `${get(synciousInstanceStore)}/videos`, - { - method: "DELETE", - ...buildAuthHeaders() - } - ) + await fetch(`${get(synciousInstanceStore)}/videos`, { + method: 'DELETE', + ...buildAuthHeaders() + }) ); -} \ No newline at end of file +} diff --git a/materialious/src/lib/Player.svelte b/materialious/src/lib/Player.svelte index 92d5d33c..266e8143 100644 --- a/materialious/src/lib/Player.svelte +++ b/materialious/src/lib/Player.svelte @@ -5,7 +5,7 @@ import { onDestroy, onMount } from 'svelte'; import { _ } from 'svelte-i18n'; import { get } from 'svelte/store'; - import type { MediaTimeUpdateEvent, PlayerSrc } from 'vidstack'; + import type { MediaTimeUpdateEvent, PlayerSrc, VideoSrc } from 'vidstack'; import type { MediaPlayerElement } from 'vidstack/elements'; import { authStore, @@ -140,7 +140,7 @@ height: Number(quality[1]), width: Number(quality[0]) }; - }); + }) as VideoSrc[]; await loadPlayerPos(); } diff --git a/materialious/src/lib/i18n/locales/en.json b/materialious/src/lib/i18n/locales/en.json index becb3655..4744dbf9 100644 --- a/materialious/src/lib/i18n/locales/en.json +++ b/materialious/src/lib/i18n/locales/en.json @@ -116,4 +116,4 @@ }, "bookmarklet": "Bookmarklet" } -} \ No newline at end of file +} diff --git a/materialious/src/lib/i18n/locales/ru.json b/materialious/src/lib/i18n/locales/ru.json index d02472a1..8462bcc5 100644 --- a/materialious/src/lib/i18n/locales/ru.json +++ b/materialious/src/lib/i18n/locales/ru.json @@ -95,4 +95,4 @@ }, "bookmarklet": "Закладка" } -} \ No newline at end of file +} diff --git a/materialious/src/lib/misc.ts b/materialious/src/lib/misc.ts index 4bb59311..e163d955 100644 --- a/materialious/src/lib/misc.ts +++ b/materialious/src/lib/misc.ts @@ -42,11 +42,11 @@ export function videoLength(lengthSeconds: number): string { export interface PhasedDescription { description: string; - timestamps: { title: string; time: number; timePretty: string; }[]; + timestamps: { title: string; time: number; timePretty: string }[]; } export function phaseDescription(content: string): PhasedDescription { - const timestamps: { title: string; time: number; timePretty: string; }[] = []; + const timestamps: { title: string; time: number; timePretty: string }[] = []; const lines = content.split('\n'); const urlRegex = / 0) { - images = images.filter(image => image.width < maxWidthDimension && image.height < maxHeightDimension); + images = images.filter( + (image) => image.width < maxWidthDimension && image.height < maxHeightDimension + ); if (images.length === 0) { return null; } images.sort((a, b) => { - return (b.width * b.height) - (a.width * a.height); + return b.width * b.height - a.width * a.height; }); return images[0].url; } else { return null; } -} \ No newline at end of file +} diff --git a/materialious/src/routes/+error.svelte b/materialious/src/routes/+error.svelte index 563daa6d..5c56f4cd 100644 --- a/materialious/src/routes/+error.svelte +++ b/materialious/src/routes/+error.svelte @@ -7,7 +7,9 @@
-
+
{ @@ -56,10 +61,10 @@ export async function load({ params, url }) { let returnYTDislikes = null; const returnYTDislikesInstance = get(returnYTDislikesInstanceStore); - if (returnYTDislikesInstance && returnYTDislikesInstance !== "") { + if (returnYTDislikesInstance && returnYTDislikesInstance !== '') { try { returnYTDislikes = get(returnYtDislikesStore) ? getDislikes(params.slug) : null; - } catch { } + } catch {} } return { @@ -71,7 +76,7 @@ export async function load({ params, url }) { personalPlaylists: personalPlaylists, returnYTDislikes: returnYTDislikes, comments: comments, - subscribed: amSubscribed(video.authorId), + subscribed: amSubscribed(video.authorId) } }; } diff --git a/materialious/src/store.ts b/materialious/src/store.ts index d802f686..daf3f777 100644 --- a/materialious/src/store.ts +++ b/materialious/src/store.ts @@ -4,12 +4,11 @@ import type { DataConnection } from 'peerjs'; import { persisted } from 'svelte-persisted-store'; import { writable, type Writable } from 'svelte/store'; -export const authStore: Writable = persisted( +export const authStore: Writable = persisted( 'authToken', null ); - export const darkModeStore: Writable = persisted('darkMode', null); export const themeColorStore: Writable = persisted('themeColor', null); @@ -45,7 +44,10 @@ export const sponsorBlockUrlStore: Writable = persist 'sponsorBlockUrl', import.meta.env.VITE_DEFAULT_SPONSERBLOCK_INSTANCE ); -export const sponsorBlockCategoriesStore: Writable = persisted('sponsorBlockCategories', []); +export const sponsorBlockCategoriesStore: Writable = persisted( + 'sponsorBlockCategories', + [] +); export const deArrowInstanceStore = persisted( 'deArrowInstance', @@ -60,6 +62,8 @@ export const deArrowThumbnailInstanceStore = persisted( export const syncPartyPeerStore: Writable = writable(null); export const syncPartyConnectionsStore: Writable = writable(); -export const playlistSettingsStore: Writable> = writable({}); +export const playlistSettingsStore: Writable> = + writable({}); -export const miniPlayerSrcStore: Writable<{ video: VideoPlay; time: number; } | null> = writable(null); \ No newline at end of file +export const miniPlayerSrcStore: Writable<{ video: VideoPlay; time: number } | null> = + writable(null); diff --git a/materialious/tsconfig.json b/materialious/tsconfig.json index be94989f..f8f9f3fe 100644 --- a/materialious/tsconfig.json +++ b/materialious/tsconfig.json @@ -10,20 +10,12 @@ "sourceMap": true, "strict": true, "moduleResolution": "bundler", - "types": [ - "vidstack/svelte" - ] + "types": ["vidstack/svelte"] }, - "include": [ - "src/**/*.ts", - "src/**/*.d.ts" - ], - "exclude": [ - "node_modules", - "dist" - ] + "include": ["src/**/*.ts", "src/**/*.d.ts"], + "exclude": ["node_modules", "dist"] // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias // // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes // from the referenced tsconfig.json - TypeScript does not merge them in -} \ No newline at end of file +} diff --git a/materialious/vite.config.ts b/materialious/vite.config.ts index 5171386d..c774f0a2 100644 --- a/materialious/vite.config.ts +++ b/materialious/vite.config.ts @@ -9,25 +9,25 @@ export default defineConfig({ injectRegister: 'inline', manifest: { description: 'Modern material design for Invidious.', - theme_color: "#8936FF", - background_color: "#1e1b1e", + theme_color: '#8936FF', + background_color: '#1e1b1e', icons: [ { - purpose: "maskable", - sizes: "512x512", - src: "icon512_maskable.png", - type: "image/png" + purpose: 'maskable', + sizes: '512x512', + src: 'icon512_maskable.png', + type: 'image/png' }, { - purpose: "any", - sizes: "512x512", - src: "icon512_rounded.png", - type: "image/png" + purpose: 'any', + sizes: '512x512', + src: 'icon512_rounded.png', + type: 'image/png' } ], - orientation: "any", - display: "standalone", - name: "Materialious", + orientation: 'any', + display: 'standalone', + name: 'Materialious' } }), vidstack(),