mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 02:22:44 +01:00
code base refactor
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""empty message
|
||||
"""add size units
|
||||
|
||||
Revision ID: 1.7.1
|
||||
Revises: 1.6.3
|
||||
|
||||
32
backend/src/alembic/versions/1.7.2_.py
Normal file
32
backend/src/alembic/versions/1.7.2_.py
Normal file
@@ -0,0 +1,32 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 1.7.2
|
||||
Revises: 1.7.1
|
||||
Create Date: 2023-04-17 12:03:19.163501
|
||||
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '1.7.2'
|
||||
down_revision = '1.7.1'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('roms', sa.Column('p_name', sa.String(length=150), nullable=True))
|
||||
op.add_column('roms', sa.Column('url_cover', sa.Text(), nullable=True))
|
||||
op.alter_column('roms', 'name', new_column_name='r_name')
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('roms', 'p_name')
|
||||
op.drop_column('roms', 'url_cover')
|
||||
op.alter_column('roms', 'r_name', new_column_name='name')
|
||||
# ### end Alembic commands ###
|
||||
@@ -11,10 +11,7 @@ router = APIRouter()
|
||||
def rom(p_slug: str, file_name: str) -> dict:
|
||||
"""Returns one rom data of the desired platform"""
|
||||
|
||||
return {'data': {
|
||||
**dbh.get_rom(p_slug, file_name).__dict__,
|
||||
'platform': dbh.get_platform(p_slug)
|
||||
}}
|
||||
return {'data': dbh.get_rom(p_slug, file_name)}
|
||||
|
||||
|
||||
@router.get("/platforms/{p_slug}/roms")
|
||||
@@ -32,25 +29,16 @@ async def updateRom(req: Request, p_slug: str) -> dict:
|
||||
rom: dict = data['rom']
|
||||
updatedRom: dict = data['updatedRom']
|
||||
log.info(f"Updating {COLORS['orange']}{updatedRom['file_name']}{COLORS['reset']} details")
|
||||
r_igdb_id, file_name_no_tags, r_slug, r_name, summary, url_cover = igdbh.get_rom_details(updatedRom['file_name'], rom['p_igdb_id'], updatedRom['r_igdb_id'])
|
||||
path_cover_s, path_cover_l, has_cover = fs.get_cover_details(True, p_slug, updatedRom['file_name'], url_cover)
|
||||
updatedRom['file_name_no_tags'] = file_name_no_tags
|
||||
updatedRom['r_igdb_id'] = r_igdb_id
|
||||
updatedRom.update(igdbh.get_rom_details(updatedRom['file_name'], rom['p_igdb_id'], updatedRom['r_igdb_id']))
|
||||
updatedRom.update(fs.get_cover_details(True, p_slug, updatedRom['file_name'], updatedRom['url_cover']))
|
||||
updatedRom['p_igdb_id'] = rom['p_igdb_id']
|
||||
updatedRom['r_slug'] = r_slug
|
||||
updatedRom['p_slug'] = p_slug
|
||||
updatedRom['name'] = r_name
|
||||
updatedRom['summary'] = summary
|
||||
updatedRom['path_cover_s'] = path_cover_s
|
||||
updatedRom['path_cover_l'] = path_cover_l
|
||||
updatedRom['has_cover'] = has_cover
|
||||
updatedRom['file_path'] = rom['file_path']
|
||||
updatedRom['file_size'] = rom['file_size']
|
||||
updatedRom['multi'] = rom['multi']
|
||||
updatedRom['file_extension'] = fs.get_file_extension(updatedRom)
|
||||
reg, rev, other_tags = fs.parse_tags(updatedRom['file_name'])
|
||||
updatedRom.update({'region': reg, 'revision': rev, 'tags': other_tags})
|
||||
if 'url_cover' in updatedRom.keys(): del updatedRom['url_cover']
|
||||
fs.rename_rom(p_slug, rom['file_name'], updatedRom['file_name'])
|
||||
dbh.update_rom(p_slug, rom['file_name'], updatedRom)
|
||||
return {'data': updatedRom}
|
||||
|
||||
@@ -8,7 +8,7 @@ router = APIRouter()
|
||||
|
||||
|
||||
@router.put("/search/roms/igdb")
|
||||
async def search_rom_igdb(req: Request, igdb_id: str=None) -> dict:
|
||||
async def search_rom_igdb(req: Request, igdb_id: str = None) -> dict:
|
||||
"""Get all the roms matched from igdb."""
|
||||
|
||||
data: dict = await req.json()
|
||||
@@ -20,5 +20,5 @@ async def search_rom_igdb(req: Request, igdb_id: str=None) -> dict:
|
||||
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("Results:")
|
||||
[log.info(f"\t - {COLORS['blue']}{rom['name']}{COLORS['reset']}") for rom in matched_roms]
|
||||
[log.info(f"\t - {COLORS['blue']}{rom['r_name']}{COLORS['reset']}") for rom in matched_roms]
|
||||
return {'data': matched_roms}
|
||||
|
||||
@@ -48,8 +48,8 @@ class IGDBHandler():
|
||||
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])
|
||||
r_igdb_id: str = ""
|
||||
slug: str = ""
|
||||
name: str = ""
|
||||
r_slug: str = ""
|
||||
r_name: str = ""
|
||||
summary: str = ""
|
||||
url_cover: str = ""
|
||||
|
||||
@@ -57,8 +57,8 @@ class IGDBHandler():
|
||||
res_details: dict = requests.post("https://api.igdb.com/v4/games/", headers=self.headers,
|
||||
data=f"fields id, slug, name, summary; where id={r_igdb_id_search};").json()[0]
|
||||
r_igdb_id = res_details['id']
|
||||
slug = res_details['slug']
|
||||
name = res_details['name']
|
||||
r_slug = res_details['slug']
|
||||
r_name = res_details['name']
|
||||
try:
|
||||
summary = res_details['summary']
|
||||
except KeyError:
|
||||
@@ -72,8 +72,8 @@ class IGDBHandler():
|
||||
res_details: dict = requests.post("https://api.igdb.com/v4/games/", headers=self.headers,
|
||||
data=f"search \"{search_term}\";fields id, slug, name, summary; where platforms=[{p_igdb_id}] & category=0;").json()[0]
|
||||
r_igdb_id = res_details['id']
|
||||
slug = res_details['slug']
|
||||
name = res_details['name']
|
||||
r_slug = res_details['slug']
|
||||
r_name = res_details['name']
|
||||
try:
|
||||
summary = res_details['summary']
|
||||
except KeyError:
|
||||
@@ -83,8 +83,8 @@ class IGDBHandler():
|
||||
res_details: dict = requests.post("https://api.igdb.com/v4/games/", headers=self.headers,
|
||||
data=f"search \"{search_term}\";fields name, id, slug, summary; where platforms=[{p_igdb_id}] & category=10;").json()[0]
|
||||
r_igdb_id = res_details['id']
|
||||
slug = res_details['slug']
|
||||
name = res_details['name']
|
||||
r_slug = res_details['slug']
|
||||
r_name = res_details['name']
|
||||
try:
|
||||
summary = res_details['summary']
|
||||
except KeyError:
|
||||
@@ -94,8 +94,8 @@ class IGDBHandler():
|
||||
res_details: dict = requests.post("https://api.igdb.com/v4/games/", headers=self.headers,
|
||||
data=f"search \"{search_term}\";fields name, id, slug, summary; where platforms=[{p_igdb_id}];").json()[0]
|
||||
r_igdb_id = res_details['id']
|
||||
slug = res_details['slug']
|
||||
name = res_details['name']
|
||||
r_slug = res_details['slug']
|
||||
r_name = res_details['name']
|
||||
try:
|
||||
summary = res_details['summary']
|
||||
except KeyError:
|
||||
@@ -108,9 +108,9 @@ class IGDBHandler():
|
||||
data=f"fields url; where game={r_igdb_id};").json()[0]
|
||||
url_cover: str = f"https:{res_details['url']}"
|
||||
except IndexError:
|
||||
log.warning(f"{name} cover not found in IGDB")
|
||||
if not name: name = file_name_no_tags
|
||||
return (r_igdb_id, file_name_no_tags, slug, name, summary, url_cover)
|
||||
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}
|
||||
|
||||
|
||||
@check_twitch_token
|
||||
@@ -129,23 +129,28 @@ class IGDBHandler():
|
||||
rom['url_cover'] = DEFAULT_URL_COVER_L
|
||||
rom['r_igdb_id'] = rom.pop('id')
|
||||
rom['r_slug'] = rom.pop('slug')
|
||||
rom['r_name'] = rom.pop('name')
|
||||
else:
|
||||
log.warning(f"{p_slug} is not supported!")
|
||||
return matched_roms
|
||||
|
||||
def get_matched_roms_by_id(self, igdb_id: str) -> list:
|
||||
matched_roms: list[dict] = []
|
||||
matched_roms: list = requests.post("https://api.igdb.com/v4/games/", headers=self.headers,
|
||||
data=f"fields name, id, slug, summary; where id={igdb_id};").json()
|
||||
for rom in matched_roms:
|
||||
try:
|
||||
res_details: dict = requests.post("https://api.igdb.com/v4/covers/", headers=self.headers,
|
||||
data=f"fields url; where game={rom['id']};").json()[0]
|
||||
rom['url_cover'] = f"https:{res_details['url']}".replace('t_thumb', f't_cover_big')
|
||||
except IndexError:
|
||||
rom['url_cover'] = DEFAULT_URL_COVER_L
|
||||
rom['r_igdb_id'] = rom.pop('id')
|
||||
rom['r_slug'] = rom.pop('slug')
|
||||
res: list = requests.post("https://api.igdb.com/v4/games/", headers=self.headers,
|
||||
data=f"fields name, id, slug, summary; where id={igdb_id};")
|
||||
if res.status_code == 200:
|
||||
matched_roms = res.json()
|
||||
for rom in matched_roms:
|
||||
try:
|
||||
res_details: dict = requests.post("https://api.igdb.com/v4/covers/", headers=self.headers,
|
||||
data=f"fields url; where game={rom['id']};").json()[0]
|
||||
rom['url_cover'] = f"https:{res_details['url']}".replace('t_thumb', f't_cover_big')
|
||||
except IndexError:
|
||||
rom['url_cover'] = DEFAULT_URL_COVER_L
|
||||
rom['r_igdb_id'] = rom.pop('id')
|
||||
rom['r_slug'] = rom.pop('slug')
|
||||
rom['r_name'] = rom.pop('name')
|
||||
else:
|
||||
matched_roms: list = []
|
||||
return matched_roms
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ class Rom(BaseModel):
|
||||
p_sgdb_id = Column(String(length=10), default="")
|
||||
|
||||
p_slug = Column(String(length=50), primary_key=True)
|
||||
p_name = Column(String(length=150))
|
||||
|
||||
file_name = Column(String(length=450), primary_key=True)
|
||||
file_name_no_tags = Column(String(length=450), default="")
|
||||
@@ -20,7 +21,7 @@ class Rom(BaseModel):
|
||||
file_size = Column(Float, default=0.0)
|
||||
file_size_units = Column(String(length=10), default="")
|
||||
|
||||
name = Column(String(length=350), default="")
|
||||
r_name = Column(String(length=350), default="")
|
||||
r_slug = Column(String(length=100), default="")
|
||||
|
||||
summary = Column(Text, default="")
|
||||
@@ -28,6 +29,7 @@ class Rom(BaseModel):
|
||||
path_cover_s = Column(Text, default=DEFAULT_PATH_COVER_S)
|
||||
path_cover_l = Column(Text, default=DEFAULT_PATH_COVER_L)
|
||||
has_cover = Column(Boolean, default=False)
|
||||
url_cover = Column(Text, default=DEFAULT_PATH_COVER_L)
|
||||
|
||||
region = Column(String(20), default="")
|
||||
revision = Column(String(20), default="")
|
||||
|
||||
@@ -19,17 +19,10 @@ def scan_platform(p_slug: str) -> Platform:
|
||||
|
||||
|
||||
def scan_rom(platform: Platform, rom: dict, r_igbd_id_search: str = '', overwrite: bool = False) -> None:
|
||||
r_igdb_id, file_name_no_tags, r_slug, r_name, summary, url_cover = igdbh.get_rom_details(rom['file_name'], platform.igdb_id, r_igbd_id_search)
|
||||
path_cover_s, path_cover_l, has_cover = fs.get_cover_details(overwrite, platform.slug, rom['file_name'], url_cover)
|
||||
rom['file_name_no_tags'] = file_name_no_tags
|
||||
rom['r_igdb_id'] = r_igdb_id
|
||||
rom.update(igdbh.get_rom_details(rom['file_name'], platform.igdb_id, r_igbd_id_search))
|
||||
rom.update(fs.get_cover_details(overwrite, platform.slug, rom['file_name'], rom['url_cover']))
|
||||
rom['p_igdb_id'] = platform.igdb_id
|
||||
rom['r_slug'] = r_slug
|
||||
rom['p_slug'] = platform.slug
|
||||
rom['name'] = r_name
|
||||
rom['summary'] = summary
|
||||
rom['path_cover_s'] = path_cover_s
|
||||
rom['path_cover_l'] = path_cover_l
|
||||
rom['has_cover'] = has_cover
|
||||
rom['p_name'] = platform.name
|
||||
rom = Rom(**rom)
|
||||
return rom
|
||||
|
||||
@@ -278,4 +278,4 @@ def get_cover_details(overwrite: bool, p_slug: str, file_name: str, url_cover: s
|
||||
if _cover_exists(p_slug, file_name, 'l'):
|
||||
path_cover_l = _get_cover_path(p_slug, file_name, 'l')
|
||||
has_cover = 1
|
||||
return path_cover_s, path_cover_l, has_cover
|
||||
return {'path_cover_s': path_cover_s, 'path_cover_l': path_cover_l, 'has_cover': has_cover}
|
||||
|
||||
@@ -18,7 +18,7 @@ const forceImgReload = Date.now()
|
||||
cover>
|
||||
<template v-slot:placeholder>
|
||||
<div class="d-flex align-center justify-center fill-height">
|
||||
<v-progress-circular color="secondary" indeterminate/>
|
||||
<v-progress-circular color="rommAccent1" indeterminate/>
|
||||
</div>
|
||||
</template>
|
||||
<v-expand-transition>
|
||||
|
||||
@@ -18,7 +18,7 @@ const emitter = inject('emitter')
|
||||
:key="rom.file_name"
|
||||
class="pa-2">
|
||||
<v-row class="text-subtitle-2">
|
||||
<v-col md="3" lg="3"><p>{{ rom.name }}</p></v-col>
|
||||
<v-col md="3" lg="3"><p>{{ rom.r_name }}</p></v-col>
|
||||
<v-col md="3" lg="4" class="hidden-sm-and-down"><p>{{ rom.file_name }}</p></v-col>
|
||||
<v-col class="hidden-sm-and-down"><p>{{ rom.p_slug }}</p></v-col>
|
||||
<v-col class="hidden-sm-and-down"><p>{{ rom.file_size }} {{ rom.file_size_units }}</p></v-col>
|
||||
|
||||
@@ -24,11 +24,13 @@ const dialogSearchRom = ref(false)
|
||||
const dialogEditRom = ref(false)
|
||||
const dialogDeleteRom = ref(false)
|
||||
const deleteFromFs = ref(false)
|
||||
|
||||
const filesToDownload = ref([])
|
||||
const tab = ref('info')
|
||||
const { xs, sm, mdAndUp } = useDisplay()
|
||||
|
||||
// Event listeners bus
|
||||
const emitter = inject('emitter')
|
||||
|
||||
// Functions
|
||||
async function searchRomIGDB() {
|
||||
searching.value = true
|
||||
@@ -45,7 +47,7 @@ async function updateRom(updatedRom=Object.assign({},rom.value), newName=rom.val
|
||||
updating.value = true
|
||||
dialogSearchRom.value = false
|
||||
if (renameAsIGDB.value) {
|
||||
updatedRom.file_name = rom.value.file_name.replace(rom.value.file_name_no_tags.trim(), updatedRom.name)
|
||||
updatedRom.file_name = rom.value.file_name.replace(rom.value.file_name_no_tags.trim(), updatedRom.r_name)
|
||||
editedRomName.value = updatedRom.file_name
|
||||
renameAsIGDB.value = false
|
||||
}
|
||||
@@ -58,6 +60,7 @@ async function updateRom(updatedRom=Object.assign({},rom.value), newName=rom.val
|
||||
}).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)
|
||||
}).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'})
|
||||
@@ -153,14 +156,14 @@ onMounted(() => {
|
||||
<v-col class="mt-10" :class="{'info': mdAndUp, 'info-tablet': sm, 'info-mobile': xs}">
|
||||
<div class="info-header text-white">
|
||||
<v-row no-gutters>
|
||||
<p class="text-h4 font-weight-bold rom-name">{{ rom.name }}</p>
|
||||
<p class="text-h4 font-weight-bold rom-name">{{ rom.r_name }}</p>
|
||||
<v-chip-group class="ml-3 mt-1 hidden-xs">
|
||||
<v-chip v-show="rom.region" size="x-small" class="bg-chip" label>{{ rom.region }}</v-chip>
|
||||
<v-chip v-show="rom.revision" size="x-small" class="bg-chip" label>{{ rom.revision }}</v-chip>
|
||||
</v-chip-group>
|
||||
</v-row>
|
||||
<v-row no-gutters class="align-center">
|
||||
<p class="font-italic mt-1 rom-platform">{{ rom.platform.name }}</p>
|
||||
<p class="font-italic mt-1 rom-platform">{{ rom.p_name }}</p>
|
||||
<v-chip-group class="ml-3 mt-1 hidden-sm-and-up">
|
||||
<v-chip v-show="rom.region" size="x-small" class="bg-chip" label>{{ rom.region }}</v-chip>
|
||||
<v-chip v-show="rom.revision" size="x-small" class="bg-chip" label>{{ rom.revision }}</v-chip>
|
||||
@@ -252,7 +255,7 @@ onMounted(() => {
|
||||
<v-img v-bind="props" :src="rom.url_cover" cover/>
|
||||
<v-card-text>
|
||||
<v-row class="pa-2">
|
||||
<span class="d-inline-block text-truncate">{{ rom.name }}</span>
|
||||
<span class="d-inline-block text-truncate">{{ rom.r_name }}</span>
|
||||
</v-row>
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
@@ -320,7 +323,7 @@ onMounted(() => {
|
||||
</v-dialog>
|
||||
|
||||
<v-dialog :model-value="updating || loading" scroll-strategy="none" width="auto" :scrim="updating" persistent>
|
||||
<v-progress-circular :width="3" :size="70" color="secondary" indeterminate/>
|
||||
<v-progress-circular :width="3" :size="70" color="rommAccent1" indeterminate/>
|
||||
</v-dialog>
|
||||
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user