Skip to content

Commit

Permalink
added renaming message on match
Browse files Browse the repository at this point in the history
  • Loading branch information
zurdi15 committed Jun 20, 2024
1 parent 752e146 commit 749f1bc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
8 changes: 4 additions & 4 deletions backend/endpoints/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def contents(f):
async def update_rom(
request: Request,
id: int,
rename_as_igdb: bool = False,
rename_as_source: bool = False,
remove_cover: bool = False,
artwork: UploadFile | None = None,
) -> DetailedRomSchema:
Expand All @@ -261,11 +261,11 @@ async def update_rom(
Args:
request (Request): Fastapi Request object
id (Rom): Rom internal id
rename_as_igdb (bool, optional): Flag to rename rom file as matched IGDB game. Defaults to False.
rename_as_source (bool, optional): Flag to rename rom file as matched IGDB game. Defaults to False.
artwork (UploadFile, optional): Custom artork to set as cover. Defaults to File(None).
Raises:
HTTPException: If a rom already have that name when enabling the rename_as_igdb flag
HTTPException: If a rom already have that name when enabling the rename_as_source flag
Returns:
DetailedRomSchema: Rom stored in the database
Expand Down Expand Up @@ -299,7 +299,7 @@ async def update_rom(
)
fs_safe_name = cleaned_data["name"].strip().replace("/", "-")

if rename_as_igdb:
if rename_as_source:
fs_safe_file_name = db_rom.file_name.replace(
db_rom.file_name_no_tags or db_rom.file_name_no_ext, fs_safe_name
)
Expand Down
2 changes: 1 addition & 1 deletion backend/endpoints/tests/test_rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_update_rom(rename_file_mock, get_rom_by_id_mock, access_token, rom):
response = client.put(
f"/roms/{rom.id}",
headers={"Authorization": f"Bearer {access_token}"},
params={"rename_as_igdb": True},
params={"rename_as_source": True},
data={
"igdb_id": "236663",
"name": "Metroid Prime Remastered",
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/components/common/Game/Dialog/MatchRom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async function updateRom(selectedRom: SearchRomSchema) {
}
await romApi
.updateRom({ rom: rom.value, renameAsIGDB: renameAsSource.value })
.updateRom({ rom: rom.value, renameAsSource: renameAsSource.value })
.then(({ data }) => {
emitter?.emit("snackbarShow", {
msg: "Rom updated successfully!",
Expand Down Expand Up @@ -403,6 +403,16 @@ onBeforeUnmount(() => {
<v-col cols="12">
<v-row class="mt-4 text-center" no-gutters>
<v-col>
<v-list-item v-if="renameAsSource">
The file will be renamed from
<span class="text-romm-accent-1">{{
rom?.file_name
}}</span>
to
<span class="text-romm-accent-2">
{{ selectedMatchRom?.name }}.{{ rom?.file_extension }}</span
>
</v-list-item>
<v-chip
@click="toggleRenameAsSource"
:variant="renameAsSource ? 'flat' : 'outlined'"
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/services/api/rom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ export type UpdateRom = SimpleRom & {

async function updateRom({
rom,
renameAsIGDB = false,
renameAsSource = false,
removeCover = false,
}: {
rom: UpdateRom;
renameAsIGDB?: boolean;
renameAsSource?: boolean;
removeCover?: boolean;
}): Promise<{ data: DetailedRom }> {
const formData = new FormData();
Expand All @@ -140,7 +140,7 @@ async function updateRom({
if (rom.artwork) formData.append("artwork", rom.artwork);

return api.put(`/roms/${rom.id}`, formData, {
params: { rename_as_igdb: renameAsIGDB, remove_cover: removeCover },
params: { rename_as_source: renameAsSource, remove_cover: removeCover },
});
}

Expand Down

0 comments on commit 749f1bc

Please sign in to comment.