Skip to content

Commit

Permalink
Merge pull request #908 from rommapp/master
Browse files Browse the repository at this point in the history
v3.2.0 [hotfixed]
  • Loading branch information
zurdi15 authored May 31, 2024
2 parents 685f9c6 + fef7899 commit 633a2c6
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 101 deletions.
30 changes: 15 additions & 15 deletions backend/endpoints/rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
from exceptions.fs_exceptions import RomAlreadyExistsException
from fastapi import APIRouter, File, HTTPException, Query, Request, UploadFile, status
from fastapi.responses import FileResponse
from fastapi_pagination.cursor import CursorPage, CursorParams
from fastapi_pagination.ext.sqlalchemy import paginate
from handler.database import db_platform_handler, db_rom_handler
from handler.filesystem import fs_resource_handler, fs_rom_handler
from handler.filesystem.base_handler import CoverSize
from handler.metadata import meta_igdb_handler, meta_moby_handler
from logger.logger import log
from stream_zip import ZIP_AUTO, stream_zip # type: ignore[import]
from urllib.parse import quote

router = APIRouter()


Expand Down Expand Up @@ -88,31 +87,30 @@ def add_roms(
def get_roms(
request: Request,
platform_id: int = None,
size: int = 60,
cursor: str = "",
search_term: str = "",
limit: int = None,
order_by: str = "name",
order_dir: str = "asc",
) -> CursorPage[RomSchema]:
) -> list[RomSchema]:
"""Get roms endpoint
Args:
request (Request): Fastapi Request object
id (int, optional): Rom internal id
Returns:
RomSchema: Rom stored in the database
list[RomSchema]: List of roms stored in the database
"""

with db_rom_handler.session.begin() as session:
cursor_params = CursorParams(size=size, cursor=cursor)
qq = db_rom_handler.get_roms(
platform_id=platform_id,
search_term=search_term.lower(),
order_by=order_by.lower(),
order_dir=order_dir.lower(),
)
return paginate(session, qq, cursor_params)
return session.scalars(
db_rom_handler.get_roms(
platform_id=platform_id,
search_term=search_term.lower(),
order_by=order_by.lower(),
order_dir=order_dir.lower(),
).limit(limit)
).all()


@protected_route(
Expand Down Expand Up @@ -237,7 +235,9 @@ def contents(f):
return CustomStreamingResponse(
zipped_chunks,
media_type="application/zip",
headers={"Content-Disposition": f'attachment; filename="{quote(file_name)}.zip"'},
headers={
"Content-Disposition": f'attachment; filename="{quote(file_name)}.zip"'
},
emit_body={"id": rom.id},
)

Expand Down
4 changes: 2 additions & 2 deletions backend/endpoints/tests/test_rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def test_get_all_roms(access_token, rom, platform):
assert response.status_code == 200

body = response.json()
assert len(body["items"]) == 1
assert body["items"][0]["id"] == rom.id
assert len(body) == 1
assert body[0]["id"] == rom.id


@patch("endpoints.rom.fs_rom_handler.rename_file")
Expand Down
2 changes: 0 additions & 2 deletions backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import endpoints.sockets.scan # noqa
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi_pagination import add_pagination
from handler.database import db_user_handler
from handler.socket_handler import socket_handler
from handler.auth import auth_handler
Expand Down Expand Up @@ -95,7 +94,6 @@ async def lifespan(app: FastAPI):
app.include_router(screenshots.router)
app.include_router(firmware.router)

add_pagination(app)
app.mount("/ws", socket_handler.socket_app)


Expand Down
1 change: 0 additions & 1 deletion frontend/src/__generated__/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 0 additions & 31 deletions frontend/src/__generated__/models/CursorPage_RomSchema_.ts

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/src/components/Dashboard/Recent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ onMounted(() => {
romApi
.getRecentRoms()
.then(({ data: recentData }) => {
romsStore.setRecentRoms(recentData.items);
romsStore.setRecentRoms(recentData);
})
.catch((error) => {
console.error(error);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Dialog/Rom/SearchRom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ async function searchRoms() {
inputElement?.blur();
searching.value = true;
searchedRoms.value = (
await romApi.getRoms({ searchTerm: searchValue.value, size: 250 })
).data.items.sort((a, b) => {
await romApi.getRoms({ searchTerm: searchValue.value })
).data.sort((a, b) => {
return a.platform_name.localeCompare(b.platform_name);
});
platforms.value = [
Expand Down
14 changes: 4 additions & 10 deletions frontend/src/services/api/rom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
AddRomsResponse,
CursorPage_RomSchema_,
MessageResponse,
RomSchema,
SearchRomSchema,
} from "@/__generated__";
import api from "@/services/api/index";
Expand Down Expand Up @@ -32,34 +32,28 @@ async function uploadRoms({

async function getRoms({
platformId = null,
size = 5000,
cursor = "",
searchTerm = "",
orderBy = "name",
orderDir = "asc",
}: {
platformId?: number | null;
size?: number | null;
cursor?: string | null;
searchTerm?: string | null;
orderBy?: string | null;
orderDir?: string | null;
}): Promise<{ data: CursorPage_RomSchema_ }> {
}): Promise<{ data: SimpleRom[] }> {
return api.get(`/roms`, {
params: {
platform_id: platformId,
size: size,
cursor: cursor,
search_term: searchTerm,
order_by: orderBy,
order_dir: orderDir,
},
});
}

async function getRecentRoms(): Promise<{ data: CursorPage_RomSchema_ }> {
async function getRecentRoms(): Promise<{ data: SimpleRom[] }> {
return api.get("/roms", {
params: { size: 15, order_by: "id", order_dir: "desc" },
params: { order_by: "id", order_dir: "desc", limit: 15 },
});
}

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/Gallery/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ async function fetchRoms() {
})
.then(({ data }) => {
// Add any new roms to the store
const allRomsSet = [...allRoms.value, ...data.items];
const allRomsSet = [...allRoms.value, ...data];
romsStore.set(allRomsSet);
romsStore.setFiltered(allRomsSet, galleryFilterStore);
if (galleryFilterStore.isFiltered()) {
const serchedRomsSet = [...searchRoms.value, ...data.items];
const serchedRomsSet = [...searchRoms.value, ...data];
romsStore.setSearch(serchedRomsSet);
romsStore.setFiltered(serchedRomsSet, galleryFilterStore);
}
Expand Down
35 changes: 1 addition & 34 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ PyYAML = "6.0.1"
Unidecode = "1.3.8"
emoji = "2.10.1"
python-dotenv = "1.0.1"
fastapi-pagination = "^0.12.19"
sqlakeyset = "^2.0.1708907391"
pydash = "^7.0.7"
mariadb = "1.1.10"
Expand Down

0 comments on commit 633a2c6

Please sign in to comment.