Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions docs/changelog/2026-11-27-chart-upload-format.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 上传页:手机端选背景图改走「文件」,且不再要求用户文件名

日期:2026-11-27
分支:`main`

## 背景

谱面上传有四个槽位:`maidata.txt`、`bg.png / bg.jpg`、`track.mp3`、`bg.mp4 / pv.mp4`。
原来有三个问题叠在一起:

1. **手机端点「选择」背景图会先进相册**。`accept="image/png,image/jpeg"` 是 MIME 类型,
iOS 看到图片类型会先弹「照片图库 / 拍照 / 选择文件」菜单;`maidata.txt` 用的是
`.txt` 扩展名,所以能直接打开「文件」App。同一张谱面文件夹里的东西,两边体验不一致。
2. **文件名被要求得死死的**。校验只认 `bg.png`、`bg.jpg`、`track.mp3`、`pv.mp4` 这些
精确名字(区分大小写)。手机相册导出的 `IMG_0001.JPG`、网盘下载的 `封面.jpg` 全被判
成非法,用户得先改名才能上传。
3. **接口靠标准文件名认文件**。`formfiles` 里的每个 part 用 `maidata.txt` / `bg.jpg` /
`track.mp3` / `pv.mp4` 区分用途,不能直接把用户的原始文件名发过去。

## 前端改动

| 位置 | 改动 |
| --- | --- |
| `src/utils/chartUploadValidation.ts` | 改为「格式规则表」:每个槽位声明允许的扩展名、是否必填、扩展名 → 标准文件名的映射。新增 `isChartUploadFileFormatAccepted`(只按扩展名判断)、`getChartUploadAccept`(只用扩展名拼 `accept`)、`toStandardChartUploadFile`(改写成标准文件名并补正 MIME)、`buildChartUploadFormData`(按槽位顺序组装 FormData) |
| `src/components/user/ChartUploader.tsx` | 选择文件时只提示格式不对,不再提示文件名;提交时从 `picked` 状态组装 FormData,用户文件名不参与上报。背景图按扩展名映射 `bg.png` / `bg.jpg`(`.jpeg` 也算 jpg),视频统一 `pv.mp4`,音频统一 `track.mp3`,谱面统一 `maidata.txt` |
| `src/locales/{zh,en,ja,ko}.json` | `InvalidFileName` 改为 `InvalidFileFormat`,用 `{{formats}}` 显示该槽位接受的扩展名 |

`accept` 全部改成扩展名形式:`.txt` / `.png,.jpg,.jpeg` / `.mp3` / `.mp4`。WebKit 对只含
扩展名的 accept 会直接打开文件选择器,不再先给相册菜单;桌面端同样按扩展名过滤。

## 验证

- `test/utils/chartUploadValidation.test.ts` 重写(37 个用例):任意文件名只要扩展名对就
接受、大小写不敏感;`.gif` / `.webp` / `.wav` / `.mov` / 无扩展名 / `xxx.png.bak` 被拒;
`accept` 不含任何 MIME(防止手机端退回相册);标准名映射(含 `.jpeg` → `bg.jpg`)和
FormData 的顺序、跳过空槽位、可选视频都覆盖。
- `pnpm test`(60 个文件、489 个用例)、`pnpm lint`、`tsc -p tsconfig.app.json --noEmit`
/ `tsc -p tsconfig.node.json --noEmit`、`pnpm i18n:check` 通过。
- 手机端行为依赖浏览器对 accept 的处理,无法在单元测试里模拟;用 iOS Safari 从「文件」
App 选 `IMG_0001.JPG` 后,请求里的 part 名应为 `bg.jpg`,槽位显示仍是原文件名。

## 注意

- 只改文件名,不改文件内容;格式仍按扩展名判断,HEIC 之类后端不存的格式会被拒绝。
- 视频接口同时接受 `bg.mp4` 和 `pv.mp4`,这里统一用 `pv.mp4`(下载 zip 和编辑器查找
视频时也是 `pv.mp4` 优先)。
- FormData 不再给未选中的槽位塞空 `File`,只按槽位顺序放已选文件;接口按文件名识别,
不依赖 part 个数。
40 changes: 40 additions & 0 deletions docs/changelog/2026-11-28-loading-spinner-size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 修掉偶发的超大加载转圈

日期:2026-11-28
分支:`main`

## 背景

`LoadingSpinner` 的宽高是内联样式(`style={{ width, height }}`),默认 `size = 48`。
几个调用方按 Tailwind 的写法传了 `className="w-4 h-4"`,以为能缩到 16px,但内联样式优先级
更高,实际仍然是 **48px**。结果在这些地方转圈会突然变得很大:

- 上传弹窗里「正在查询这个谱面是否已存在…」那一行;
- 上传按钮的 loading 状态(按钮本身才 44px 高);
- 确认弹窗的「确定」按钮(按钮 40px 高,转圈 48px)。

搜索页、列表里走 `SectionLoading` 的地方尺寸一直是 32px,看起来正常,所以问题显得「有时候」才出现。

## 前端改动

| 位置 | 改动 |
| --- | --- |
| `src/components/ui/LoadingSpinner.tsx` | 补清楚 props 注释:`className` 只用于颜色/动画,尺寸必须用 `size`(内联宽高会盖过 `w-`/`h-`) |
| `src/components/user/ChartUploader.tsx` | 哈希检查行、上传按钮里的转圈改为 `size={16}` |
| `src/components/ui/ConfirmDialog.tsx` | 确认按钮里的转圈改为 `size={16}` |
| `src/pages/QRAuthPage.tsx` | 去掉无效的 `className="w-4 h-4"`,只留 `size={16}` |

现在仓库里所有 `<LoadingSpinner>` 都用 `size` 指定尺寸,没有再用 `w-`/`h-` 工具类控制。

## 验证

- 全仓库检索 `<LoadingSpinner … className="… w-/h-">` 已无匹配。
- `pnpm test`(61 个文件、490 个用例)、`pnpm lint`、`tsc -p tsconfig.app.json --noEmit`、
`pnpm build` 通过。
- 上传弹窗需要登录才能打开,本次没有在浏览器里截图核对;按代码,三处转圈从 48px 变为 16px,
其余位置尺寸不变。

## 注意

- `LoadingSpinner` 的接口没有改,仍可用字符串尺寸(如 `"18px"`);只是不要再通过 className 改宽高。
- 默认尺寸仍是 48px,只有明确需要 48px 的地方(目前没有直接使用默认值的调用方)才会用到。
40 changes: 40 additions & 0 deletions docs/changelog/2026-11-28-space-uploaded-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 个人空间「上传的谱面」加排序

日期:2026-11-28
分支:`main`

## 背景

个人空间的「上传的谱面」页签只有页内搜索,没有排序:列表固定在接口默认的「最近活跃」,
搜出结果后也只能按这个顺序看。搜索页和歌单页早就有一排排序选项(活跃 / 热门 / 分数 /
评论 / 播放 / 上传时间),这里缺一组。

## 前端改动

| 位置 | 改动 |
| --- | --- |
| `src/components/user/UploadedCharts.tsx` | 搜索框右边加 `SortMenu`,和搜索页共用 `SORT_WORDS`、`useSortOptions`、`parseIndexParam`;排序下标写进网址 `?sort=`(默认 0 不落参数)。第一屏 `SongList` 的两个接口页和搜索模式的全量拉取都带上排序词 |
| `test/components/user/UploadedCharts.test.tsx` | 新增组件测试:选中「上传时间」后列表接口变成 `sort=timep`,网址变成 `sort=5` |

排序参数和搜索词、页签一起放在地址栏里,刷新/分享/浏览器回退都能还原。搜索模式下
`collectAllPages` 本来就按接口顺序合并,带排序拉回来后前端过滤不会打乱顺序,所以过滤结果
也是全局排序后的顺序。

## 验证

- 开发服务器(`pnpm dev`,http://localhost:3000)真实数据,LSP2 的空间:
- 默认「活跃」:`/space?id=LSP2&tab=uploaded`,列表首项 `Doki Doki Forever`;
- 切「上传时间」:网址变为 `...&sort=5`,Network 里两页列表请求都带 `sort=timep`,
首项变成最新上传的 `一冊のアロー`;切回「活跃」参数消失、顺序恢复;
- 搜索 + 排序:`?q=Doki&sort=5` 下仍显示「找到 1 张谱面 / Doki Doki Forever」,
全量拉取的第 0–5 页也都带 `sort=timep`;
- 390×844 手机视口:搜索框和排序按钮同一行,排序按钮不挤压输入框。
- `test/components/user/UploadedCharts.test.tsx` 通过;`pnpm test` 共 61 个文件、
490 个用例全部通过;`pnpm lint`、`pnpm i18n:check`、`pnpm build` 通过。

## 注意

- 默认排序保持接口原来的「最近活跃」,没有把「上传时间」设成默认,行为和搜索页一致。
- 搜索模式改变排序会重新拉一遍这个用户的全部上传(按新排序分页),期间显示加载态;
用户上传很多时这一步会比第一屏慢,和原来首次聚焦搜索框的代价一样。
- 排序菜单只复用现有文案,没有新增 i18n key。
2 changes: 1 addition & 1 deletion src/components/ui/ConfirmDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function ConfirmDialog({ open, title, message, confirmLabel, dang
disabled={busy}
className={`inline-flex items-center gap-2 disabled:opacity-60 px-4 border-none rounded-xl h-10 font-semibold text-white text-sm transition-colors cursor-pointer disabled:cursor-not-allowed ${danger ? 'bg-red-500 hover:bg-red-400' : 'bg-blue-500 hover:bg-blue-400'}`}
>
{busy && <LoadingSpinner className="w-4 h-4" />}
{busy && <LoadingSpinner size={16} />}
{confirmLabel}
</button>
</div>
Expand Down
6 changes: 4 additions & 2 deletions src/components/ui/LoadingSpinner.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { useState } from 'react';

interface LoadingSpinnerProps {
className?: string; // Additional classes for the spinner container
size?: number | string; // Size of the spinner (e.g. 24 or "1.5rem")
/** 只放颜色、动画之类的附加类;尺寸请用 `size`(宽高是内联样式,会盖过 w-/h- 工具类) */
className?: string;
/** 转圈的直径,数字按 px 处理(例如 16 或 "1.5rem") */
size?: number | string;
}

/** 转一圈的时长 */
Expand Down
69 changes: 30 additions & 39 deletions src/components/user/ChartUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import { endpoints } from '@/config/api';
import { useUserContext } from '@/hooks';
import { getDisplayMessage, sleep } from '@/utils';
import { getFileKey, hashCandidatesFromBytes } from '@/utils/maidataHash';
import { getExpectedChartUploadFileNames, isValidChartUploadFileName } from '@/utils/chartUploadValidation';
import {
buildChartUploadFormData,
CHART_UPLOAD_FILE_RULES,
getChartUploadAccept,
getChartUploadFormatHint,
isChartUploadFileFormatAccepted,
} from '@/utils/chartUploadValidation';
import { LuFileAudio, LuFileText, LuFileVideo, LuImage, LuUpload } from 'react-icons/lu';
import { LoadingSpinner } from '@/components';
import type { Song } from '@/types';
Expand Down Expand Up @@ -36,7 +42,7 @@ export default function ChartUploader() {
const [hashLookup, setHashLookup] = useState<HashLookupState>({ status: 'idle' });
const hashLookupSeq = useRef(0);
const hashLookupAbort = useRef<AbortController | null>(null);
/** 每个槽位当前选中的文件(只用于显示;提交时仍从表单里的 input 读取) */
/** 每个槽位当前选中的文件;提交时按槽位顺序改写文件名后放进 FormData */
const [picked, setPicked] = useState<(File | null)[]>([null, null, null, null]);
const inputRefs = useRef<(HTMLInputElement | null)[]>([]);
const setPickedAt = (index: number, file: File | null) => setPicked((prev) => prev.map((value, i) => (i === index ? file : value)));
Expand Down Expand Up @@ -151,10 +157,9 @@ export default function ChartUploader() {
return;
}

if (!isValidChartUploadFileName(index, file.name)) {
if (!isChartUploadFileFormatAccepted(index, file.name)) {
toast.error(
t("user/ChartUploader.InvalidFileName")
+ getExpectedChartUploadFileNames(index),
t("user/ChartUploader.InvalidFileFormat", { formats: getChartUploadFormatHint(index) }),
);
event.currentTarget.value = '';
if (index === 0) {
Expand All @@ -172,23 +177,10 @@ export default function ChartUploader() {
async function onSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();

const formData = new FormData(event.currentTarget);
const filesNecessary = formData.getAll('formfiles');

const fileChecks = [
{ file: filesNecessary[0], name: 'maidata.txt' },
{ file: filesNecessary[1], name: 'bg.png/bg.jpg' },
{ file: filesNecessary[2], name: 'track' },
];

const missedFiles: string[] = [];

for (const { file, name } of fileChecks) {
const fileObj = file as File;
if (!fileObj || fileObj.name === '' || fileObj.size === 0) {
missedFiles.push(name);
}
}
const isMissing = (file: File | null) => !file || file.size === 0;
const missedFiles = CHART_UPLOAD_FILE_RULES
.filter((rule, index) => rule.required && isMissing(picked[index]))
.map((rule) => rule.label);

if (missedFiles.length > 0) {
for (const file of missedFiles) {
Expand All @@ -197,22 +189,20 @@ export default function ChartUploader() {
return;
}

for (let index = 0; index < filesNecessary.length; index += 1) {
const file = filesNecessary[index] as File;
// The fourth file is optional; an empty file input can appear as an empty File.
if (!file || file.name === '' || file.size === 0) {
continue;
}
for (const [index, file] of picked.entries()) {
if (!file || isMissing(file)) continue;

if (!isValidChartUploadFileName(index, file.name)) {
if (!isChartUploadFileFormatAccepted(index, file.name)) {
toast.error(
t("user/ChartUploader.InvalidFileName")
+ getExpectedChartUploadFileNames(index),
t("user/ChartUploader.InvalidFileFormat", { formats: getChartUploadFormatHint(index) }),
);
return;
}
}

// 用户文件名不参与上传:这里统一改写成接口约定的标准文件名
const formData = buildChartUploadFormData(picked);

if (hashLookup.status === 'exists') {
toast.error(t("user/ChartUploader.MaidataAlreadyExists"), { autoClose: false });
return;
Expand Down Expand Up @@ -254,12 +244,13 @@ export default function ChartUploader() {
}
}

const uploadFields = [
{ label: 'maidata.txt', Icon: LuFileText, accept: '.txt' },
{ label: 'bg.png / bg.jpg', Icon: LuImage, accept: 'image/png,image/jpeg' },
{ label: 'track.mp3', Icon: LuFileAudio, accept: 'audio/mpeg,.mp3' },
{ label: 'bg.mp4 / pv.mp4', Icon: LuFileVideo, accept: 'video/mp4', hint: t("user/ChartUploader.VideoHint") },
];
const uploadFieldIcons = [LuFileText, LuImage, LuFileAudio, LuFileVideo];
const uploadFields = CHART_UPLOAD_FILE_RULES.map((rule, index) => ({
label: rule.label,
Icon: uploadFieldIcons[index],
accept: getChartUploadAccept(index),
hint: index === 3 ? t("user/ChartUploader.VideoHint") : undefined,
}));
const hashLookupStatusText: Record<HashLookupStatus, string> = {
idle: '',
checking: t("user/ChartUploader.MaidataHashChecking"),
Expand Down Expand Up @@ -329,7 +320,7 @@ export default function ChartUploader() {

{hashLookup.status !== 'idle' && (
<div className={`flex items-center gap-2 bg-white/[0.03] px-3 py-2 rounded-lg text-xs ${hashLookupStatusClass[hashLookup.status]}`}>
{hashLookup.status === 'checking' && <LoadingSpinner className="w-4 h-4" />}
{hashLookup.status === 'checking' && <LoadingSpinner size={16} />}
<span className="min-w-0">{hashLookupStatusText[hashLookup.status]}</span>
{hashLookup.status === 'exists' && hashLookup.chart && (
<Link
Expand All @@ -349,7 +340,7 @@ export default function ChartUploader() {
>
{isUploading ? (
<>
<LoadingSpinner className="w-4 h-4" />
<LoadingSpinner size={16} />
{t("user/ChartUploader.UploadingPlzWait")}
</>
) : (
Expand Down
Loading
Loading