fix: resolve lint issues (XSS K601, knip unused exports, eslint errors)

- Fix XSS warnings in user.tsx by adding safe attribute to elements
- Remove unused exports: ChunkUploadRequest, getArchiveInfo,
  getFileForDirectDownload, createDirectDownloadHeaders, createConverterArchive
- Fix eslint no-unused-vars errors across multiple files
- Fix pdfmathtranslate async Promise executor issue
- Update tests to use toThrow instead of toMatch for Error objects
- Apply prettier formatting
This commit is contained in:
Your Name 2026-01-21 16:00:26 +08:00
parent db5f47586e
commit 79fc6f7067
21 changed files with 439 additions and 439 deletions

View file

@ -1,11 +1,10 @@
import path from "node:path";
import { Elysia } from "elysia";
import sanitize from "sanitize-filename";
import { outputDir } from "..";
import db from "../db/db";
import { WEBROOT } from "../helpers/env";
import { userService } from "./user";
import { createJobArchive, shouldUseChunkedDownload } from "../transfer";
import { createJobArchive } from "../transfer";
export const download = new Elysia()
.use(userService)
@ -45,10 +44,10 @@ export const download = new Elysia()
const jobId = decodeURIComponent(params.jobId);
const outputPath = `${outputDir}${userId}/${jobId}`;
// 使用統一的封裝管理器建立 .tar不壓縮
const outputTar = await createJobArchive(outputPath, jobId);
return Bun.file(outputTar);
},
{

View file

@ -1,14 +1,12 @@
/**
* Contents.CN Chunk API
*
*
*
*/
import { Elysia, t } from "elysia";
import { join } from "node:path";
import { Elysia } from "elysia";
import { outputDir } from "..";
import db from "../db/db";
import { WEBROOT } from "../helpers/env";
import { userService } from "./user";
import sanitize from "sanitize-filename";
import {
@ -16,11 +14,8 @@ import {
getChunkDownloadInfo,
getChunk,
createChunkDownloadHeaders,
getFileForDirectDownload,
createDirectDownloadHeaders,
CHUNK_SIZE_BYTES,
} from "../transfer";
import { statSync, existsSync } from "node:fs";
import { existsSync } from "node:fs";
export const downloadChunk = new Elysia()
.use(userService)
@ -44,7 +39,7 @@ export const downloadChunk = new Elysia()
const filePath = `${outputDir}${userId}/${jobId}/${fileName}`;
const info = getChunkDownloadInfo(filePath);
if (!info) {
return { error: "File not found" };
}
@ -54,7 +49,7 @@ export const downloadChunk = new Elysia()
use_chunked: shouldUseChunkedDownload(filePath),
};
},
{ auth: true }
{ auth: true },
)
/**
* chunk
@ -90,14 +85,14 @@ export const downloadChunk = new Elysia()
}
const headers = createChunkDownloadHeaders(info, chunkIndex, chunkData);
for (const [key, value] of Object.entries(headers)) {
set.headers[key] = value;
}
return new Response(chunkData);
},
{ auth: true }
{ auth: true },
)
/**
* Archive chunk
@ -122,7 +117,7 @@ export const downloadChunk = new Elysia()
}
const info = getChunkDownloadInfo(archivePath);
if (!info) {
return { error: "Archive not found" };
}
@ -132,7 +127,7 @@ export const downloadChunk = new Elysia()
use_chunked: shouldUseChunkedDownload(archivePath),
};
},
{ auth: true }
{ auth: true },
)
/**
* Archive chunk
@ -167,12 +162,12 @@ export const downloadChunk = new Elysia()
}
const headers = createChunkDownloadHeaders(info, chunkIndex, chunkData);
for (const [key, value] of Object.entries(headers)) {
set.headers[key] = value;
}
return new Response(chunkData);
},
{ auth: true }
{ auth: true },
);

View file

@ -1,11 +1,10 @@
/**
* Contents.CN Chunk API
*
*
*
*/
import { Elysia, t } from "elysia";
import { WEBROOT } from "../helpers/env";
import { uploadsDir } from "../index";
import { userService } from "./user";
import sanitize from "sanitize-filename";
@ -44,7 +43,7 @@ export const uploadChunk = new Elysia().use(userService).post(
user.id,
jobId.value,
`${uploadsDir}${user.id}/`,
userUploadsDir
userUploadsDir,
);
return result;
@ -59,7 +58,7 @@ export const uploadChunk = new Elysia().use(userService).post(
chunk: t.File(),
}),
auth: true,
}
},
);
/**
@ -72,7 +71,7 @@ export const uploadInfo = new Elysia().use(userService).post(
const size = parseInt(file_size, 10);
const useChunked = shouldUseChunkedUpload(size);
return {
use_chunked: useChunked,
chunk_size: CHUNK_SIZE_BYTES,
@ -84,5 +83,5 @@ export const uploadInfo = new Elysia().use(userService).post(
file_size: t.String(),
}),
auth: true,
}
},
);

View file

@ -115,12 +115,16 @@ export const user = new Elysia()
sm:px-4
`}
>
<h1 class="my-8 text-3xl">{t("setup", "welcome")}</h1>
<h1 class="my-8 text-3xl" safe>
{t("setup", "welcome")}
</h1>
<article class="article p-0">
<header class="w-full bg-neutral-800 p-4">{t("setup", "createYourAccount")}</header>
<header class="w-full bg-neutral-800 p-4" safe>
{t("setup", "createYourAccount")}
</header>
<form method="post" action={`${WEBROOT}/register`} class="p-4">
<fieldset class="mb-4 flex flex-col gap-4">
<label class="flex flex-col gap-1">
<label class="flex flex-col gap-1" safe>
{t("auth", "email")}
<input
type="email"
@ -131,7 +135,7 @@ export const user = new Elysia()
required
/>
</label>
<label class="flex flex-col gap-1">
<label class="flex flex-col gap-1" safe>
{t("auth", "password")}
<input
type="password"
@ -146,13 +150,14 @@ export const user = new Elysia()
<input type="submit" value={t("auth", "createAccount")} class="btn-primary" />
</form>
<footer class="p-4">
{t("setup", "reportIssues")}{" "}
<span safe>{t("setup", "reportIssues")}</span>{" "}
<a
class={`
text-accent-500 underline
hover:text-accent-400
`}
href="https://github.com/pi-docket/ConvertX-CN"
safe
>
{t("setup", "github")}
</a>
@ -186,7 +191,7 @@ export const user = new Elysia()
<article class="article">
<form method="post" class="flex flex-col gap-4">
<fieldset class="mb-4 flex flex-col gap-4">
<label class="flex flex-col gap-1">
<label class="flex flex-col gap-1" safe>
{t("auth", "email")}
<input
type="email"
@ -197,7 +202,7 @@ export const user = new Elysia()
required
/>
</label>
<label class="flex flex-col gap-1">
<label class="flex flex-col gap-1" safe>
{t("auth", "password")}
<input
type="password"
@ -308,7 +313,7 @@ export const user = new Elysia()
<article class="article">
<form method="post" class="flex flex-col gap-4">
<fieldset class="mb-4 flex flex-col gap-4">
<label class="flex flex-col gap-1">
<label class="flex flex-col gap-1" safe>
{t("auth", "email")}
<input
type="email"
@ -319,7 +324,7 @@ export const user = new Elysia()
required
/>
</label>
<label class="flex flex-col gap-1">
<label class="flex flex-col gap-1" safe>
{t("auth", "password")}
<input
type="password"
@ -336,6 +341,7 @@ export const user = new Elysia()
href={`${WEBROOT}/register`}
role="button"
class="w-full btn-secondary text-center"
safe
>
{t("nav", "register")}
</a>
@ -444,7 +450,7 @@ export const user = new Elysia()
<article class="article">
<form method="post" class="flex flex-col gap-4">
<fieldset class="mb-4 flex flex-col gap-4">
<label class="flex flex-col gap-1">
<label class="flex flex-col gap-1" safe>
{t("auth", "email")}
<input
type="email"
@ -456,7 +462,7 @@ export const user = new Elysia()
required
/>
</label>
<label class="flex flex-col gap-1">
<label class="flex flex-col gap-1" safe>
{t("auth", "newPassword")}
<input
type="password"
@ -466,7 +472,7 @@ export const user = new Elysia()
autocomplete="new-password"
/>
</label>
<label class="flex flex-col gap-1">
<label class="flex flex-col gap-1" safe>
{t("auth", "currentPassword")}
<input
type="password"