From 9fecf5bbfa4aa983289e2300b0ca51914c273494 Mon Sep 17 00:00:00 2001 From: Gnarwhal Date: Wed, 18 Sep 2024 15:39:27 +0000 Subject: [PATCH] A bajillion type errors --- .eslintrc.json | 5 ++++- next.config.mjs | 4 +++- src/app/[...file]/content.tsx | 23 +++++++++++------------ src/app/[...file]/download_tty.tsx | 10 +++++----- src/app/[...file]/page.css.ts | 1 - src/app/[...file]/page.tsx | 7 +++---- src/app/[...file]/types/terminal.css.ts | 3 --- src/app/[...file]/types/terminal.tsx | 14 +++++++------- src/app/[...file]/types/text.tsx | 13 ++----------- tsconfig.json | 1 + 10 files changed, 36 insertions(+), 45 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 3722418..82fbe15 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,3 +1,6 @@ { - "extends": ["next/core-web-vitals", "next/typescript"] + "extends": ["next/core-web-vitals", "next/typescript"], + "rules": { + "@typescript-eslint/no-explicit-any": "off" + } } diff --git a/next.config.mjs b/next.config.mjs index 5dd825b..0c3c06c 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,7 +1,9 @@ import { createVanillaExtractPlugin } from '@vanilla-extract/next-plugin' /** @type {import('next').NextConfig} */ -const nextConfig = {} +const nextConfig = { + output: "standalone", +} const withVanillaExtract = createVanillaExtractPlugin() diff --git a/src/app/[...file]/content.tsx b/src/app/[...file]/content.tsx index d70df99..003ecf9 100644 --- a/src/app/[...file]/content.tsx +++ b/src/app/[...file]/content.tsx @@ -4,14 +4,14 @@ import { useState, useEffect } from 'react' import NetworkError from './types/error/network'; import ContentTypeError from './types/error/content_type'; -import Image from './types/image'; +import ImageContent from './types/image'; import Terminal from './types/terminal'; import Text from './types/text'; type ContentType = { content_type: RegExp, - extension: RegExp, - emit: () => undefined | Processor, + path?: RegExp, + emit: () => void | Processor, }; type Processor = { process: (response: Response) => Promise, @@ -22,8 +22,8 @@ function not_match(regex: RegExp | undefined, str: string) { return !(regex ?? /(?:)/).test(str); } -function is_type(response: Response, type: ContentType) { - if (not_match(type.content_type, response.headers.get('Content-Type').split(';')[0])) { +function is_type(response: Response, type: ContentType) { + if (not_match(type.content_type, response.headers.get('Content-Type')!.split(';')[0])) { return false; } else if (not_match(type.path, window.location.pathname)) { return false; @@ -32,12 +32,12 @@ function is_type(response: Response, type: ContentType) { } export default function Content({ src }: { src: string}) { - const [content, set_content] = useState(); + const [content, set_content] = useState(); - const recognized_types: ContentType[] = [{ + const recognized_types: ContentType[] = [{ content_type: /image\/\w+/, emit: () => { - set_content(); + set_content(); }, }, { content_type: /application\/octet-stream/, @@ -70,9 +70,8 @@ export default function Content({ src }: { src: string}) { if (content == undefined) { const result = fetch(src) .then(response => { - const content_type = response.headers.get('Content-Type').split(';')[0]; for (const type of recognized_types) { - if (type.content_type.test(content_type)) { + if (is_type(response, type)) { const emitted = type.emit(); if (emitted != undefined) { result.then(emitted.postprocess); @@ -81,13 +80,13 @@ export default function Content({ src }: { src: string}) { return; } } - set_content(); + set_content(); }) .catch(err => { set_content(); }); } - }, []); + }); return content ??

Loading...

; } diff --git a/src/app/[...file]/download_tty.tsx b/src/app/[...file]/download_tty.tsx index 93fbb27..80a4a53 100644 --- a/src/app/[...file]/download_tty.tsx +++ b/src/app/[...file]/download_tty.tsx @@ -1,15 +1,15 @@ 'use client' -import { useState } from 'react'; +// import { useState } from 'react'; import * as style from './download_tty.css'; export default function DownloadTTY({ text }: { text: string }) { - const [copied, set_copied] = useState(false); - function make_copy_text(text) { - return (event) => { + // const [copied, set_copied] = useState(false); + function make_copy_text(text: string) { + return () => { navigator.clipboard.writeText(text); - set_copied(true); + // set_copied(true); // setTimeout(() => { set_copied(false); }, 5000); }; } diff --git a/src/app/[...file]/page.css.ts b/src/app/[...file]/page.css.ts index f4b11f2..060cbb8 100644 --- a/src/app/[...file]/page.css.ts +++ b/src/app/[...file]/page.css.ts @@ -61,7 +61,6 @@ export const download_button = style({ width: 'auto', height: '100%', marginLeft: '2em', - border: 0, padding: 0, border: `1px solid ${colors.background2}`, backgroundColor: colors.background, diff --git a/src/app/[...file]/page.tsx b/src/app/[...file]/page.tsx index 24e3c69..ecd9095 100644 --- a/src/app/[...file]/page.tsx +++ b/src/app/[...file]/page.tsx @@ -1,4 +1,4 @@ -import type { Metadata, ResolvingMetadata } from 'next'; +import type { Metadata } from 'next'; import Image from 'next/image'; import DownloadTTY from './download_tty'; @@ -10,7 +10,7 @@ import download_image_light from './download_light.svg'; type SearchParams = { [key: string]: string | string[] | undefined }; type Props = { - params: { file: string }, + params: { file: string[] }, searchParams: SearchParams, }; @@ -24,7 +24,6 @@ function get_root(search_params: SearchParams) { export async function generateMetadata( { params, searchParams }: Props, - parent: ResolvingMetadata, ): Promise { return { title: `${get_path(params.file)} | ${get_root(searchParams)}`, @@ -52,7 +51,7 @@ export default async function Page({

{path}