patch and delete rom endpoint added
@@ -12,20 +12,28 @@ class DBHandler:
|
||||
self.session = Session()
|
||||
|
||||
|
||||
def add_platform(self, **kargs):
|
||||
def add_platform(self, **kargs) -> None:
|
||||
self.session.merge(Platform(**kargs))
|
||||
|
||||
|
||||
def get_platforms(self):
|
||||
def get_platforms(self) -> list[Platform]:
|
||||
return self.session.query(Platform).all()
|
||||
|
||||
|
||||
def add_rom(self, **kargs):
|
||||
def add_rom(self, **kargs) -> None:
|
||||
self.session.merge(Rom(**kargs))
|
||||
|
||||
|
||||
def get_roms(self, p_slug):
|
||||
def get_roms(self, p_slug: str) -> list[Rom]:
|
||||
return self.session.query(Rom).filter(Rom.p_slug == p_slug).all()
|
||||
|
||||
|
||||
def update_rom(self, p_slug: str, filename: str, data: dict) -> None:
|
||||
self.session.query(Rom).filter(Rom.p_slug==p_slug, Rom.filename==filename).update(data, synchronize_session='evaluate')
|
||||
|
||||
|
||||
def delete_rom(self, p_slug: str, filename: str) -> None:
|
||||
self.session.query(Rom).filter(Rom.p_slug==p_slug, Rom.filename==filename).delete(synchronize_session='evaluate')
|
||||
|
||||
|
||||
def commit(self):
|
||||
|
||||
@@ -105,7 +105,7 @@ class IGDBHandler():
|
||||
url_cover: str = f"https:{res_details['url']}"
|
||||
except IndexError:
|
||||
log.warning(f"{name} cover not found in igdb")
|
||||
if not name: name = filename
|
||||
if not name: name = filename_no_ext
|
||||
return (igdb_id, filename_no_ext, slug, name, summary, url_cover)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, Request
|
||||
import uvicorn
|
||||
|
||||
from logger.logger import log
|
||||
@@ -17,69 +17,71 @@ sgdbh: SGDBHandler = SGDBHandler()
|
||||
dbh: DBHandler = DBHandler()
|
||||
|
||||
|
||||
@app.patch("/platforms/{p_slug}/roms/{filename}")
|
||||
async def editRom(p_slug: str, filename: str):
|
||||
"""Edits rom details"""
|
||||
return {'msg': 'WIP'}
|
||||
|
||||
|
||||
@app.get("/platforms/{p_slug}/roms")
|
||||
async def platforms(p_slug: str):
|
||||
async def roms(p_slug: str):
|
||||
"""Returns roms data of the desired platform"""
|
||||
return {'data': dbh.get_roms(p_slug)}
|
||||
|
||||
|
||||
@app.patch("/platforms/{p_slug}/roms/{filename}")
|
||||
async def updateRom(req: Request, p_slug: str, filename: str):
|
||||
"""Updates rom details"""
|
||||
data: dict = await req.json()
|
||||
if 'filename' in data: fs.rename_rom(p_slug, filename, data)
|
||||
dbh.update_rom(p_slug, filename, data)
|
||||
dbh.commit()
|
||||
return {'msg': 'success'}
|
||||
|
||||
|
||||
@app.delete("/platforms/{p_slug}/roms/{filename}")
|
||||
async def delete_rom(p_slug: str, filename: str):
|
||||
log.info("deleting rom...")
|
||||
fs.delete_rom(p_slug, filename)
|
||||
dbh.delete_rom(p_slug, filename)
|
||||
dbh.commit()
|
||||
return {'msg': 'success'}
|
||||
|
||||
|
||||
@app.get("/platforms")
|
||||
async def platforms():
|
||||
"""Returns platforms data"""
|
||||
return {'data': dbh.get_platforms()}
|
||||
|
||||
|
||||
@app.get("/scan/rom")
|
||||
async def scan_rom(req: Request, overwrite: bool=False):
|
||||
"""Scan single rom and write it in database."""
|
||||
|
||||
log.info("scaning rom...")
|
||||
data: dict = await req.json()
|
||||
fastapi.scan_rom(overwrite, data['filename'], data['p_igdb_id'], data['p_slug'], igdbh, dbh)
|
||||
dbh.commit()
|
||||
return {'msg': 'success'}
|
||||
|
||||
|
||||
@app.get("/scan/platform")
|
||||
async def scan_platform(req: Request, overwrite: bool=False):
|
||||
"""Scan single platform and write it in database."""
|
||||
|
||||
log.info("scaning platform roms...")
|
||||
data: dict = await req.json()
|
||||
for filename in fs.get_roms(data['p_slug']):
|
||||
fastapi.scan_rom(overwrite, filename, data['p_igdb_id'], data['p_slug'], igdbh, dbh)
|
||||
dbh.commit()
|
||||
return {'msg': 'success'}
|
||||
|
||||
|
||||
@app.get("/scan")
|
||||
async def scan(overwrite: bool=False):
|
||||
"""Scan platforms and roms and write them in database."""
|
||||
|
||||
log.info("scaning...")
|
||||
|
||||
log.info("complete scaning...")
|
||||
fs.store_default_resources(overwrite)
|
||||
|
||||
for p_slug in fs.get_platforms():
|
||||
platform: dict = {}
|
||||
log.info(f"Getting {p_slug} details")
|
||||
p_igdb_id, p_name, url_logo = igdbh.get_platform_details(p_slug)
|
||||
platform['slug'] = p_slug
|
||||
platform['igdb_id'] = p_igdb_id
|
||||
platform['name'] = p_name
|
||||
|
||||
#TODO: refactor logo details logic
|
||||
if (overwrite or not fs.p_logo_exists(p_slug)) and url_logo:
|
||||
fs.store_p_logo(p_slug, url_logo)
|
||||
if fs.p_logo_exists(p_slug):
|
||||
platform['path_logo']: str = fs.get_p_path_logo(p_slug)
|
||||
|
||||
dbh.add_platform(**platform)
|
||||
|
||||
p_igdb_id: str = fastapi.scan_platform(overwrite, p_slug, igdbh, dbh)
|
||||
for filename in fs.get_roms(p_slug):
|
||||
rom: dict = {}
|
||||
log.info(f"Getting {filename} details")
|
||||
r_igdb_id, filename_no_ext, r_slug, r_name, summary, url_cover = igdbh.get_rom_details(filename, p_igdb_id)
|
||||
path_cover_s, path_cover_l, has_cover = fs.get_cover_details(overwrite, p_slug, filename_no_ext, url_cover)
|
||||
rom['filename'] = filename
|
||||
rom['filename_no_ext'] = filename_no_ext
|
||||
rom['r_igdb_id'] = r_igdb_id
|
||||
rom['p_igdb_id'] = p_igdb_id
|
||||
rom['name'] = r_name
|
||||
rom['r_slug'] = r_slug
|
||||
rom['p_slug'] = p_slug
|
||||
rom['summary'] = summary
|
||||
rom['path_cover_s'] = path_cover_s
|
||||
rom['path_cover_l'] = path_cover_l
|
||||
rom['has_cover'] = has_cover
|
||||
|
||||
dbh.add_rom(**rom)
|
||||
|
||||
fastapi.scan_rom(overwrite, filename, p_igdb_id, p_slug, igdbh, dbh)
|
||||
dbh.commit()
|
||||
|
||||
return {'msg': 'success'}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from utils import fs
|
||||
from logger.logger import log
|
||||
|
||||
|
||||
@@ -13,3 +14,38 @@ def allow_cors(app: FastAPI) -> None:
|
||||
allow_headers=["*"],
|
||||
)
|
||||
log.info("CORS enabled")
|
||||
|
||||
|
||||
def scan_platform(overwrite: bool, p_slug: str, igdbh, dbh) -> str:
|
||||
platform: dict = {}
|
||||
log.info(f"Getting {p_slug} details")
|
||||
p_igdb_id, p_name, url_logo = igdbh.get_platform_details(p_slug)
|
||||
platform['slug'] = p_slug
|
||||
platform['igdb_id'] = p_igdb_id
|
||||
platform['name'] = p_name
|
||||
#TODO: refactor logo details logic
|
||||
if (overwrite or not fs.p_logo_exists(p_slug)) and url_logo:
|
||||
fs.store_p_logo(p_slug, url_logo)
|
||||
if fs.p_logo_exists(p_slug):
|
||||
platform['path_logo']: str = fs.get_p_path_logo(p_slug)
|
||||
dbh.add_platform(**platform)
|
||||
return p_igdb_id
|
||||
|
||||
|
||||
def scan_rom(overwrite: bool, filename: str, p_igdb_id: str, p_slug: str, igdbh, dbh) -> None:
|
||||
rom: dict = {}
|
||||
log.info(f"Getting {filename} details")
|
||||
r_igdb_id, filename_no_ext, r_slug, r_name, summary, url_cover = igdbh.get_rom_details(filename, p_igdb_id)
|
||||
path_cover_s, path_cover_l, has_cover = fs.get_cover_details(overwrite, p_slug, filename_no_ext, url_cover)
|
||||
rom['filename'] = filename
|
||||
rom['filename_no_ext'] = filename_no_ext
|
||||
rom['r_igdb_id'] = r_igdb_id
|
||||
rom['p_igdb_id'] = p_igdb_id
|
||||
rom['name'] = r_name
|
||||
rom['r_slug'] = r_slug
|
||||
rom['p_slug'] = p_slug
|
||||
rom['summary'] = summary
|
||||
rom['path_cover_s'] = path_cover_s
|
||||
rom['path_cover_l'] = path_cover_l
|
||||
rom['has_cover'] = has_cover
|
||||
dbh.add_rom(**rom)
|
||||
|
||||
@@ -161,3 +161,15 @@ def get_roms(p_slug) -> list:
|
||||
log.warning(f"roms not found for {p_slug}")
|
||||
pass
|
||||
return roms
|
||||
|
||||
|
||||
def rename_rom(p_slug: str, filename: str, data: dict) -> None:
|
||||
os.rename(f"{EMULATION_BASE_PATH}/{p_slug}/roms/{filename}",
|
||||
f"{EMULATION_BASE_PATH}/{p_slug}/roms/{data['filename']}")
|
||||
|
||||
|
||||
def delete_rom(p_slug: str, filename: str) -> None:
|
||||
try:
|
||||
os.remove(f"{EMULATION_BASE_PATH}/{p_slug}/roms/{filename}")
|
||||
except FileNotFoundError:
|
||||
log.warning(f"Rom not found in filesystem: {p_slug}/{filename}")
|
||||
|
||||
0
emulation/nds/roms/pokemon black 2.nds
Normal file
0
emulation/nds/roms/pokemon black.nds
Normal file
0
emulation/nds/roms/pokemon white 2.nds
Normal file
0
emulation/nds/roms/pokemon white.nds
Normal file
BIN
emulation/resources/nds/pokemon black 2_l.png
Normal file
|
After Width: | Height: | Size: 60 KiB |
BIN
emulation/resources/nds/pokemon black 2_s.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
emulation/resources/nds/pokemon black_l.png
Normal file
|
After Width: | Height: | Size: 44 KiB |
BIN
emulation/resources/nds/pokemon black_s.png
Normal file
|
After Width: | Height: | Size: 8.3 KiB |
BIN
emulation/resources/nds/pokemon white 2_l.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
emulation/resources/nds/pokemon white 2_s.png
Normal file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
emulation/resources/nds/pokemon white_l.png
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
emulation/resources/nds/pokemon white_s.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
@@ -77,7 +77,7 @@ onMounted(() => { if(currentPlatformSlug){ getRoms(currentPlatformSlug) } })
|
||||
<v-progress-circular color="grey-lighten-4" indeterminate />
|
||||
</div>
|
||||
</template>
|
||||
<div v-if="!rom.has_cover" class="d-flex align-center text-body-1 pt-2 pr-5 pb-2 pl-5 bg-secondary rom-title" >{{ rom.name }}</div>
|
||||
<div v-if="!rom.has_cover" class="d-flex align-center text-body-1 pt-2 pr-5 pb-2 pl-5 bg-secondary rom-title" >{{ rom.filename }}</div>
|
||||
<v-btn class="d-flex align-center justify-center fill-height" @click="selectRom(rom)" color="transparent" block />
|
||||
</v-img>
|
||||
<v-card-text>
|
||||
|
||||