mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 02:22:44 +01:00
review: code-review xhigh fixes
- A save's or state's download URL carries its file name, since a rename keeps updated_at and would otherwise hand a cached download back under the old name. - A name with nothing before the extension is refused, instead of moving the thumbnail to a bare ".png" that no longer binds. - The memory card editor only closes on the card it saved, and its Save stays off until the name or the visibility changes. - Comment lines this PR rewrote lose their em-dashes, new headers fit two lines, and the settings test drops its `as unknown as` fixtures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -204,6 +204,13 @@ async def rename_asset(
|
||||
) from exc
|
||||
if new_name == asset.file_name:
|
||||
return {}
|
||||
# The thumbnail follows the stem, so a bare extension would strand it.
|
||||
new_stem = compute_file_name_no_ext(new_name)
|
||||
if not new_stem:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Invalid filename: it needs a name before the extension",
|
||||
)
|
||||
|
||||
folded = new_name.casefold()
|
||||
if any(
|
||||
@@ -214,7 +221,6 @@ async def rename_asset(
|
||||
|
||||
# Thumbnails bind by stem, so taking a stem another screenshot holds would
|
||||
# show that one, and delete it along with the asset.
|
||||
new_stem = compute_file_name_no_ext(new_name)
|
||||
thumbnail = asset.screenshot
|
||||
bound = db_screenshot_handler.get_screenshot(
|
||||
rom_id=asset.rom_id,
|
||||
|
||||
@@ -2,6 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from functools import cached_property
|
||||
from typing import TYPE_CHECKING
|
||||
from urllib.parse import quote
|
||||
|
||||
from sqlalchemy import BigInteger, ForeignKey, Index, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship, validates
|
||||
@@ -61,9 +62,11 @@ class BaseAsset(BaseModel):
|
||||
|
||||
@cached_property
|
||||
def download_path(self) -> str:
|
||||
# Served by the per-type `/{id}/content` route
|
||||
# Served by the per-type `/{id}/content` route. A rename keeps
|
||||
# `updated_at`, so the name joins the cache key.
|
||||
return (
|
||||
f"/api/{self.__tablename__}/{self.id}/content?timestamp={self.updated_at}"
|
||||
f"/api/{self.__tablename__}/{self.id}/content"
|
||||
f"?timestamp={self.updated_at}&name={quote(self.file_name)}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -829,6 +829,16 @@ class TestStateRename:
|
||||
refreshed = db_state_handler.get_state_by_id(state.id)
|
||||
assert refreshed is not None and refreshed.file_name == "test_state.state"
|
||||
|
||||
def test_name_with_nothing_before_the_extension_is_rejected(
|
||||
self, client, access_token: str, state: State, state_file, thumbnail
|
||||
):
|
||||
response = self._rename(client, access_token, state.id, ".state")
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
assert state_file.exists()
|
||||
kept = db_screenshot_handler.get_screenshot_by_id(thumbnail.id)
|
||||
assert kept is not None and kept.file_name == "test_state.png"
|
||||
|
||||
def test_blank_name_is_rejected(
|
||||
self, client, access_token: str, state: State, state_file
|
||||
):
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
// Expanded: inline name input and visibility switch with Create / Cancel
|
||||
// actions.
|
||||
//
|
||||
// Stateless — the parent owns `expanded`, `name`, `isPublic` and `creating`. The
|
||||
// outer row + tile are persistent across both states so the background
|
||||
// Stateless: the parent owns `expanded`, `name`, `isPublic` and `creating`.
|
||||
// The outer row + tile are persistent across both states so the background
|
||||
// tint and tile-active swap transition smoothly instead of remounting;
|
||||
// only the middle (label vs input) and the trailing actions toggle.
|
||||
import { RBtn, RIcon } from "@v2/lib";
|
||||
|
||||
@@ -29,7 +29,7 @@ const stored = {
|
||||
user_id: 1,
|
||||
is_public: false,
|
||||
rom_ids: [1, 2],
|
||||
} as unknown as Collection;
|
||||
} as Collection;
|
||||
|
||||
// Stands in for the switch: a click asks to flip it.
|
||||
const VisibilitySwitch = {
|
||||
@@ -65,7 +65,7 @@ describe("CollectionSettingsTab visibility", () => {
|
||||
storeAuth().setCurrentUser({
|
||||
id: 1,
|
||||
oauth_scopes: ["collections.write"],
|
||||
} as unknown as User);
|
||||
} as User);
|
||||
});
|
||||
|
||||
it("saves as soon as it is switched, keeping a name draft out", async () => {
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
//
|
||||
// Per-item affordances are driven by the item fields + props (the parent,
|
||||
// MediaTab, performs the actions):
|
||||
// * edit — when `editable` and owned: opens its visibility (top-right)
|
||||
// * delete — when `deletable` and the item is owned (top-right, hover)
|
||||
// * username — community items (others' public shots) show an owner chip
|
||||
// * edit: when `editable` and owned, opens its visibility (top-right)
|
||||
// * delete: when `deletable` and the item is owned (top-right, hover)
|
||||
// * username: community items (others' public shots) show an owner chip
|
||||
import { RAvatar, RBtn, RCarousel } from "@v2/lib";
|
||||
import { computed, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
@@ -54,6 +54,14 @@ describe("MemoryCardDialog", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps Save off until the name or the visibility changes", async () => {
|
||||
const wrapper = mountDialog({ initialName: "Main" });
|
||||
expect(wrapper.get(".confirm").attributes("disabled")).toBeDefined();
|
||||
|
||||
await wrapper.get(".public").setValue(true);
|
||||
expect(wrapper.get(".confirm").attributes("disabled")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("submits the trimmed name with the visibility", async () => {
|
||||
const wrapper = mountDialog();
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// same fields, the same validation and the same footer, so they are one
|
||||
// dialog with a different title and confirm label.
|
||||
import { RBtn, RDialog, RForm, RTextField } from "@v2/lib";
|
||||
import { ref, watch } from "vue";
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import VisibilitySwitch from "@/v2/components/shared/VisibilitySwitch.vue";
|
||||
import { required } from "@/v2/utils/validation";
|
||||
@@ -46,6 +46,13 @@ const name = ref(props.initialName);
|
||||
const isPublic = ref(props.initialPublic);
|
||||
const valid = ref(true);
|
||||
const rules = [required(t("common.required"))];
|
||||
const canSubmit = computed(
|
||||
() =>
|
||||
!!name.value.trim() &&
|
||||
(name.value.trim() !== props.initialName ||
|
||||
isPublic.value !== props.initialPublic) &&
|
||||
!props.busy,
|
||||
);
|
||||
|
||||
// Reopening is what resets the fields, so a cancelled edit does not carry
|
||||
// into the next one.
|
||||
@@ -64,9 +71,8 @@ function close(): void {
|
||||
}
|
||||
|
||||
function submit(): void {
|
||||
const trimmed = name.value.trim();
|
||||
if (!trimmed || props.busy) return;
|
||||
emit("submit", { name: trimmed, isPublic: isPublic.value });
|
||||
if (!canSubmit.value) return;
|
||||
emit("submit", { name: name.value.trim(), isPublic: isPublic.value });
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -115,7 +121,7 @@ function submit(): void {
|
||||
variant="flat"
|
||||
color="primary"
|
||||
:prepend-icon="confirmIcon"
|
||||
:disabled="!name.trim() || busy"
|
||||
:disabled="!canSubmit"
|
||||
:loading="busy"
|
||||
@click="submit"
|
||||
>
|
||||
|
||||
@@ -115,7 +115,7 @@ async function submitEdit({ name, isPublic }: MemoryCardFields): Promise<void> {
|
||||
}));
|
||||
}
|
||||
cards.value = cards.value.map((c) => (c.id === updated.id ? updated : c));
|
||||
editTarget.value = null;
|
||||
if (editTarget.value === card) editTarget.value = null;
|
||||
emit("changed");
|
||||
snackbar.success(t("play.memory-card-edited"), { icon: "mdi-check-bold" });
|
||||
} catch (err) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
// The round globe on something the user shared: on a scrim over a thumbnail,
|
||||
// or on a faint surface of its own (`inline`) beside a title. Private things
|
||||
// carry no mark.
|
||||
// The globe on something the user shared: on a scrim over a thumbnail, or on
|
||||
// a faint surface of its own (`inline`) beside a title.
|
||||
import { RIcon, RTooltip } from "@v2/lib";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
// The public/private switch every edit and create form carries, labelled with
|
||||
// the state it is in. Both labels hold the space, so flipping it never moves
|
||||
// what sits beside it.
|
||||
// The public/private switch of every edit and create form. Both labels hold
|
||||
// the space, so flipping it never moves what sits beside it.
|
||||
import { RSwitch } from "@v2/lib";
|
||||
import { computed } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
// with a visible footprint of exactly 36×20.
|
||||
//
|
||||
// Optional `label` (or the `label` slot, for richer text) renders to the
|
||||
// right of the switch (clicking the label toggles too). Without a label, only the switch paints — useful
|
||||
// inside table cells / dense rows. `SettingsToggleRow` is a separate
|
||||
// right of the switch (clicking the label toggles too). Without a label,
|
||||
// only the switch paints, which suits table cells and dense rows. `SettingsToggleRow` is a separate
|
||||
// composite that wraps RSwitch with a full-row label + description
|
||||
// click target.
|
||||
import { computed } from "vue";
|
||||
|
||||
Reference in New Issue
Block a user