fixed some updated rom fields

This commit is contained in:
zurdi zurdo
2023-04-19 19:27:12 +02:00
parent fef1c5cee4
commit 3dd3b970b0
6 changed files with 22 additions and 19 deletions

View File

@@ -28,6 +28,7 @@ def upgrade() -> None:
batch_op.alter_column('name', new_column_name='r_name', type_=sa.String(length=150), existing_type=sa.String(length=150))
batch_op.alter_column('p_slug', existing_type=sa.String(length=50), nullable=False)
batch_op.alter_column('file_name', existing_type=sa.String(length=450), nullable=False)
batch_op.drop_column('file_name_no_tags')
with op.batch_alter_table("roms") as batch_op:
if os.getenv('ROMM_DB_DRIVER') == 'mariadb':
batch_op.execute("ALTER TABLE roms ADD COLUMN id INTEGER UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT")
@@ -42,7 +43,6 @@ def upgrade() -> None:
sa.Column('p_slug', sa.String(length=50), nullable=False),
sa.Column('p_name', sa.String(length=150), nullable=True),
sa.Column('file_name', sa.String(length=450), nullable=False),
sa.Column('file_name_no_tags', sa.String(length=450), nullable=True),
sa.Column('file_extension', sa.String(length=10), nullable=True),
sa.Column('file_path', sa.String(length=1000), nullable=True),
sa.Column('file_size', sa.Float(), nullable=True),
@@ -63,12 +63,12 @@ def upgrade() -> None:
)
batch_op.execute("INSERT INTO roms(\
r_igdb_id, p_igdb_id, r_sgdb_id, p_sgdb_id, p_slug, p_name, \
file_name, file_name_no_tags, file_extension, file_path, file_size, \
file_name, file_extension, file_path, file_size, \
file_size_units, r_name, r_slug, summary, path_cover_s, path_cover_l, has_cover, \
region, revision, tags, multi, files, url_cover) \
SELECT \
r_igdb_id, p_igdb_id, r_sgdb_id, p_sgdb_id, p_slug, p_name, \
file_name, file_name_no_tags, file_extension, file_path, file_size, \
file_name, file_extension, file_path, file_size, \
file_size_units, r_name, r_slug, summary, path_cover_s, path_cover_l, has_cover, \
region, revision, tags, multi, files, url_cover \
FROM old_roms")

View File

@@ -1,8 +1,9 @@
from fastapi import APIRouter, Request
from logger.logger import log, COLORS
from handler import igdbh, dbh
from logger.logger import log
from handler import dbh
from utils import fs
from models.rom import Rom
router = APIRouter()
@@ -22,12 +23,16 @@ def roms(p_slug: str) -> dict:
@router.patch("/platforms/{p_slug}/roms/{id}")
async def updateRom(req: Request, id: int) -> dict:
async def updateRom(req: Request, p_slug: str, id: int) -> dict:
"""Updates rom details"""
data: dict = await req.json()
updated_rom: dict = data['updatedRom']
return {'data': updated_rom}
updated_rom.update(fs.get_cover_details(True, p_slug, updated_rom['file_name'], updated_rom['url_cover']))
db_rom: Rom = dbh.get_rom(id)
dbh.update_rom(id, updated_rom)
fs.rename_rom(p_slug, db_rom.file_name, updated_rom['file_name'])
return {'data': dbh.get_rom(id)}
@router.delete("/platforms/{p_slug}/roms/{id}")

View File

@@ -12,13 +12,14 @@ async def search_rom_igdb(req: Request, igdb_id: str = None) -> 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"))
if igdb_id:
log.info(f"Searching by id: {igdb_id}")
matched_roms = igdbh.get_matched_roms_by_id(igdb_id)
else:
log.info(emoji.emojize(f":video_game: {data['rom']['p_slug']}: {COLORS['orange']}{data['rom']['file_name']}{COLORS['reset']}"))
matched_roms = igdbh.get_matched_roms(data['rom']['file_name'], data['rom']['p_igdb_id'], data['rom']['p_slug'])
log.info(emoji.emojize(f":video_game: {rom['p_slug']}: {COLORS['orange']}{rom['file_name']}{COLORS['reset']}"))
matched_roms = igdbh.get_matched_roms(rom['file_name'], rom['p_igdb_id'], rom['p_slug'])
log.info("Results:")
[log.info(f"\t - {COLORS['blue']}{rom['r_name']}{COLORS['reset']}") for rom in matched_roms]
return {'data': matched_roms}

View File

@@ -46,7 +46,7 @@ class IGDBHandler():
@check_twitch_token
def get_rom_details(self, file_name: str, p_igdb_id: int, r_igdb_id_search: str) -> dict:
file_name_no_tags: str = re.sub('[\(\[].*?[\)\]]', '', file_name.split('.')[0])
search_term: str = unidecode.unidecode(re.sub('[\(\[].*?[\)\]]', '', file_name.split('.')[0]))
r_igdb_id: str = ""
r_slug: str = ""
r_name: str = ""
@@ -65,7 +65,6 @@ class IGDBHandler():
pass
else: #TODO: improve API calls to make only one
search_term: str = unidecode.unidecode(file_name_no_tags)
if p_igdb_id:
try:
@@ -109,8 +108,8 @@ class IGDBHandler():
url_cover: str = f"https:{res_details['url']}"
except IndexError:
log.warning(f"{r_name} cover not found in IGDB")
if not r_name: r_name = file_name_no_tags
return {'r_igdb_id': r_igdb_id, 'file_name_no_tags': file_name_no_tags, 'r_slug': r_slug, 'r_name': r_name, 'summary': summary, 'url_cover': url_cover}
if not r_name: r_name = search_term
return {'r_igdb_id': r_igdb_id, 'r_slug': r_slug, 'r_name': r_name, 'summary': summary, 'url_cover': url_cover}
@check_twitch_token

View File

@@ -17,7 +17,6 @@ class Rom(BaseModel):
p_name = Column(String(length=150), default="")
file_name = Column(String(length=450))
file_name_no_tags = Column(String(length=450), default="")
file_extension = Column(String(length=10), default="")
file_path = Column(String(length=1000), default="")
file_size = Column(Float, default=0.0)

View File

@@ -46,9 +46,8 @@ async function updateRom(updatedRom=Object.assign({},rom.value), newName=rom.val
dialogSearchRom.value = false
updating.value = true
if (renameAsIGDB.value) {
updatedRom.file_name = rom.value.file_name.replace(rom.value.file_name_no_tags.trim(), updatedRom.r_name)
updatedRom.file_name = updatedRom.r_name
editedRomName.value = updatedRom.file_name
renameAsIGDB.value = false
}
else{ updatedRom.file_name = newName }
@@ -56,13 +55,13 @@ async function updateRom(updatedRom=Object.assign({},rom.value), newName=rom.val
updatedRom: updatedRom
}).then((response) => {
emitter.emit('snackbarScan', {'msg': rom.value.file_name+" updated successfully!", 'icon': 'mdi-check-bold', 'color': 'green'})
// rom.value = response.data.data
router.push('/'+rom.value.p_slug+'/roms/'+rom.value.file_name)
rom.value = response.data.data
router.push('/'+rom.value.p_slug+'/roms/'+rom.value.id)
}).catch((error) => {
console.log(error)
emitter.emit('snackbarScan', {'msg': "Couldn't updated "+rom.value.file_name+". Something went wrong...", 'icon': 'mdi-close-circle', 'color': 'red'})
})
renameAsIGDB.value = false
updating.value = false
dialogEditRom.value = false
}