Move image cache break to backend

This commit is contained in:
Georges-Antoine Assi
2023-06-08 21:23:44 -04:00
parent 3f0fbe0d36
commit 659ddd815b
9 changed files with 37 additions and 35 deletions

View File

@@ -74,7 +74,7 @@ def roms(
if search_term:
return paginate(
session,
qq.filter(Rom.file_name.ilike(f'%{search_term}%')),
qq.filter(Rom.file_name.ilike(f"%{search_term}%")),
cursor_params,
)
@@ -90,28 +90,27 @@ async def updateRom(req: Request, p_slug: str, id: int) -> dict:
db_rom: Rom = dbh.get_rom(id)
platform: Platform = dbh.get_platform(p_slug)
file_name = updated_rom.get("file_name", db_rom.file_name)
try:
fs.rename_rom(platform.fs_slug, db_rom.file_name, updated_rom["file_name"])
if file_name != db_rom.file_name:
fs.rename_rom(platform.fs_slug, db_rom.file_name, file_name)
except RomAlreadyExistsException as e:
log.error(str(e))
raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e)
)
updated_rom["file_name_no_tags"] = get_file_name_with_no_tags(
updated_rom["file_name"]
)
updated_rom["file_name_no_tags"] = get_file_name_with_no_tags(file_name)
updated_rom.update(fs.get_cover(True, p_slug, file_name, updated_rom["url_cover"]))
updated_rom.update(
fs.get_cover(True, p_slug, updated_rom["file_name"], updated_rom["url_cover"]),
fs.get_screenshots(
p_slug, updated_rom["file_name"], updated_rom["url_screenshots"]
),
fs.get_screenshots(p_slug, file_name, updated_rom["url_screenshots"]),
)
dbh.update_rom(id, updated_rom)
return {
"rom": dbh.get_rom(id),
"msg": f"{updated_rom['file_name']} updated successfully!",
"msg": f"{file_name} updated successfully!",
}

View File

@@ -1,5 +1,5 @@
from fastapi import APIRouter, Request
import emoji
from fastapi import APIRouter
from logger.logger import log, COLORS
from handler import igdbh
@@ -7,10 +7,14 @@ from handler import igdbh
router = APIRouter()
@router.get("/search/roms/igdb", status_code=200)
async def search_rom_igdb(rom: str, search_term: str = "", search_by: str = "") -> dict:
@router.put("/search/roms/igdb", status_code=200)
async def search_rom_igdb(
req: Request, search_term: str = "", search_by: str = ""
) -> dict:
"""Get all the roms matched from igdb."""
data: dict = await req.json()
rom: dict = data["rom"]
log.info(emoji.emojize(":magnifying_glass_tilted_right: IGDB Searching"))
matched_roms: list = []
@@ -31,6 +35,7 @@ async def search_rom_igdb(rom: str, search_term: str = "", search_by: str = "")
)
log.info("Results:")
[
log.info(f"\t - {COLORS['blue']}{rom['r_name']}{COLORS['reset']}")
for rom in matched_roms

View File

@@ -1,15 +1,14 @@
import os
import shutil
from pathlib import Path
import datetime
import requests
from pathlib import Path
from config import LIBRARY_BASE_PATH, HIGH_PRIO_STRUCTURE_PATH, \
RESOURCES_BASE_PATH, DEFAULT_URL_COVER_L, DEFAULT_PATH_COVER_L, DEFAULT_URL_COVER_S, DEFAULT_PATH_COVER_S
from config.config_loader import ConfigLoader
cl = ConfigLoader()
from logger.logger import log
from utils.exceptions import PlatformsNotFoundException, RomsNotFoundException, RomNotFoundError, RomAlreadyExistsException
cl = ConfigLoader()
# ========= Resources utils =========
@@ -53,7 +52,7 @@ def _get_cover_path(p_slug: str, file_name: str, size: str) -> str:
file_name: name of rom file
size: size of the cover -> big | small
"""
return f"{p_slug}/{file_name}/cover/{size}.png"
return f"{p_slug}/{file_name}/cover/{size}.png?timestamp={str(datetime.datetime.now().timestamp())}"
def get_cover(overwrite: bool, p_slug: str, file_name: str, url_cover: str) -> tuple:

View File

@@ -4,11 +4,11 @@ const props = defineProps(['rom'])
<template>
<v-card class="header-background" position="absolute" rounded="0" flat>
<v-img :src="`/assets/romm/resources/${rom.path_cover_s}?reload=${Date.now()}`" class="header-background-img" cover/>
<v-img :src="`/assets/romm/resources/${rom.path_cover_s}`" class="header-background-img" cover/>
</v-card>
</template>
<style scoped>
.header-background { top: 0px; left: 0px; width: 100%; max-height: 330px; }
.header-background-img { -webkit-filter: blur(15px); filter: blur(15px); }
</style>
</style>

View File

@@ -12,8 +12,8 @@ const forceImgReload = Date.now()
:value="rom.id"
:key="rom.id"
v-bind="hoverProps"
:src="`/assets/romm/resources/${rom.path_cover_l}?reload=${forceImgReload}`"
:lazy-src="`/assets/romm/resources/${rom.path_cover_s}?reload=${forceImgReload}`"
:src="`/assets/romm/resources/${rom.path_cover_l}`"
:lazy-src="`/assets/romm/resources/${rom.path_cover_s}`"
class="cover"
cover>
<template v-slot:placeholder>

View File

@@ -5,7 +5,6 @@ import { storeDownloading } from '@/stores/downloading.js'
// Props
const props = defineProps(['rom'])
const forceImgReload = Date.now()
const saveFiles = ref(false)
const downloading = storeDownloading()
@@ -33,8 +32,8 @@ const emitter = inject('emitter')
<v-avatar :rounded="0">
<v-progress-linear color="rommAccent1" :active="downloading.value.includes(rom.file_name)" :indeterminate="true" absolute/>
<v-img
:src="`/assets/romm/resources/${rom.path_cover_s}?reload=${forceImgReload}`"
:lazy-src="`/assets/romm/resources/${rom.path_cover_s}?reload=${forceImgReload}`"
:src="`/assets/romm/resources/${rom.path_cover_s}`"
:lazy-src="`/assets/romm/resources/${rom.path_cover_s}`"
min-height="150"/>
</v-avatar>
</template>
@@ -78,4 +77,4 @@ const emitter = inject('emitter')
</v-menu>
</v-col>
</v-row>
</template>
</template>

View File

@@ -4,7 +4,7 @@ import { setupCache } from "axios-cache-interceptor";
const axios = setupCache(Axios); // axios instance with cache
export async function fetchPlatformsApi() {
return axios.get("/api/platforms");
return axios.get("/api/platforms", { cache: false });
}
export async function fetchRomsApi({
@@ -19,7 +19,7 @@ export async function fetchRomsApi({
}
export async function fetchRomApi(platform, rom) {
return axios.get(`/api/platforms/${platform}/roms/${rom}`);
return axios.get(`/api/platforms/${platform}/roms/${rom}`, { cache: false });
}
export async function updateRomApi(rom, updatedRom) {
@@ -35,7 +35,8 @@ export async function deleteRomApi(rom, deleteFromFs) {
}
export async function searchRomIGDBApi(searchTerm, searchBy, rom) {
return axios.get(
`/api/search/roms/igdb/?search_term=${searchTerm}&search_by=${searchBy}&rom=${rom}`
return axios.put(
`/api/search/roms/igdb?search_term=${searchTerm}&search_by=${searchBy}`,
{ rom: rom }
);
}

View File

@@ -106,7 +106,7 @@ onMounted(() => {
<v-row>
<v-col>
<v-card elevation="2" :loading="downloading.value.includes(rom.file_name) ? 'rommAccent1': null">
<v-img :src="`/assets/romm/resources/${rom.path_cover_l}?reload=${Date.now()}`" :lazy-src="`/assets/romm/resources/${rom.path_cover_s}?reload=${Date.now()}`" cover>
<v-img :src="`/assets/romm/resources/${rom.path_cover_l}`" :lazy-src="`/assets/romm/resources/${rom.path_cover_s}`" cover>
<template v-slot:placeholder>
<div class="d-flex align-center justify-center fill-height">
<v-progress-circular color="rommAccent1" :width="2" :size="20" indeterminate/>

View File

@@ -113,7 +113,6 @@ onMounted(async () => {
onBeforeRouteUpdate(async (to, _) => {
cursor.value = "";
roms.value = [];
filteredRoms.value = [];
fetchMoreRoms(to.params.platform);
});
</script>
@@ -126,9 +125,9 @@ onBeforeRouteUpdate(async (to, _) => {
<v-btn @click="scan" rounded="0" variant="text" class="mr-0" icon="mdi-magnify-scan" />
</v-app-bar>
<template v-if="roms.length > 0 || gettingRoms">
<template v-if="filteredRoms.length > 0 || gettingRoms">
<v-row v-show="galleryView.value != 2" id="card-view" no-gutters>
<v-col v-for="rom in filteredRoms" class="pa-1" :key="rom.file_name" :cols="views[galleryView.value]['size-cols']"
<v-col v-for="rom in filteredRoms" class="pa-1" :key="rom.id" :cols="views[galleryView.value]['size-cols']"
:xs="views[galleryView.value]['size-xs']" :sm="views[galleryView.value]['size-sm']"
:md="views[galleryView.value]['size-md']" :lg="views[galleryView.value]['size-lg']">
<game-card :rom="rom" />
@@ -143,7 +142,7 @@ onBeforeRouteUpdate(async (to, _) => {
<game-list-header />
<v-divider class="border-opacity-100 mb-4 ml-2 mr-2" color="rommAccent1" :thickness="1" />
<tbody>
<game-list-item v-for="rom in filteredRoms" :key="rom.file_name" :rom="rom" />
<game-list-item v-for="rom in filteredRoms" :key="rom.id" :rom="rom" />
</tbody>
</v-table>
</v-col>