mirror of
https://github.com/rommapp/romm.git
synced 2026-02-19 07:50:57 +01:00
scan endpoints unified
This commit is contained in:
@@ -70,38 +70,19 @@ async def platforms():
|
||||
return {'data': dbh.get_platforms()}
|
||||
|
||||
|
||||
@app.put("/scan/rom")
|
||||
async def scan_rom(req: Request, overwrite: bool=False):
|
||||
"""Scan single rom and write it in database."""
|
||||
|
||||
data: dict = await req.json()
|
||||
log.info(f"scaning {data['filename']} rom...")
|
||||
fastapi.scan_rom(overwrite, data['filename'], data['p_igdb_id'], data['p_slug'], igdbh, dbh)
|
||||
return {'msg': 'success'}
|
||||
|
||||
|
||||
@app.put("/scan/platform")
|
||||
async def scan_platform(req: Request, overwrite: bool=False):
|
||||
"""Scan single platform and write it in database."""
|
||||
|
||||
data: dict = await req.json()
|
||||
log.info(f"scaning {data['p_slug']} roms...")
|
||||
for filename in fs.get_roms(data['p_slug']):
|
||||
fastapi.scan_rom(overwrite, filename, data['p_igdb_id'], data['p_slug'], igdbh, dbh)
|
||||
fastapi.purge(dbh, p_slug=data['p_slug'])
|
||||
return {'msg': 'success'}
|
||||
|
||||
|
||||
@app.get("/scan")
|
||||
async def scan(overwrite: bool=False):
|
||||
@app.put("/scan")
|
||||
async def scan(req: Request, overwrite: bool=False):
|
||||
"""Scan platforms and roms and write them in database."""
|
||||
|
||||
log.info("complete scaning...")
|
||||
fs.store_default_resources(overwrite)
|
||||
for p_slug in fs.get_platforms():
|
||||
data: dict = await req.json()
|
||||
platforms = data['platforms'] if data['platforms'] else fs.get_platforms()
|
||||
for p_slug in platforms:
|
||||
p_igdb_id: str = fastapi.scan_platform(overwrite, p_slug, igdbh, dbh)
|
||||
for filename in fs.get_roms(p_slug):
|
||||
fastapi.scan_rom(overwrite, filename, p_igdb_id, p_slug, igdbh, dbh)
|
||||
fastapi.purge(dbh, p_slug=p_slug)
|
||||
fastapi.purge(dbh)
|
||||
return {'msg': 'success'}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup>
|
||||
import { ref, inject, toRaw } from "vue"
|
||||
import { useTheme } from "vuetify";
|
||||
import { ref, inject } from "vue"
|
||||
import { useTheme } from "vuetify"
|
||||
import Navigation from '@/components/Navigation.vue'
|
||||
|
||||
// Props
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import axios from "axios"
|
||||
import { ref, inject, toRaw } from "vue"
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useTheme } from "vuetify";
|
||||
import { useTheme } from "vuetify"
|
||||
|
||||
// Props
|
||||
const platforms = ref([])
|
||||
@@ -54,45 +54,25 @@ function toggleRail(){
|
||||
}
|
||||
|
||||
async function scan() {
|
||||
// Complete scan of by platform
|
||||
// Complete scan or by platform
|
||||
console.log("scanning...")
|
||||
scanning.value = true
|
||||
const platforms = []
|
||||
toRaw(platformsToScan)._rawValue.forEach(p => {
|
||||
platforms.push(toRaw(p))
|
||||
})
|
||||
toRaw(platformsToScan)._rawValue.forEach(p => {platforms.push(toRaw(p.slug))})
|
||||
console.log(platforms)
|
||||
if (!platforms.length){
|
||||
console.log("scanning all platforms")
|
||||
await axios.get('/api/scan?overwrite='+scanOverwrite.value).then((response) => {
|
||||
console.log("scan completed")
|
||||
console.log(response.data)
|
||||
emitter.emit('snackbarScan', {'msg': 'Scan completed successfully!', 'icon': 'mdi-check-bold', 'color': 'green'})
|
||||
}).catch((error) => {
|
||||
console.log(error)
|
||||
emitter.emit('snackbarScan', {'msg': "Couldn't complete scan. Something went wrong...", 'icon': 'mdi-close-circle', 'color': 'red'})
|
||||
})
|
||||
scanning.value = false
|
||||
emitter.emit('refresh')
|
||||
}
|
||||
else{
|
||||
platforms.forEach(async p => {
|
||||
console.log("scanning: "+p.name)
|
||||
await axios.put('/api/scan/platform?overwrite='+scanOverwrite.value, {
|
||||
p_slug: p.slug,
|
||||
p_igdb_id: p.igdb_id
|
||||
}).then((response) => {
|
||||
console.log("scan "+p.name+" completed")
|
||||
console.log(response.data)
|
||||
emitter.emit('snackbarScan', {'msg': p.name+' scan completed successfully!', 'icon': 'mdi-check-bold', 'color': 'green'})
|
||||
}).catch((error) => {
|
||||
console.log(error)
|
||||
emitter.emit('snackbarScan', {'msg': "Couldn't complete "+p.name+" scan. Something went wrong...", 'icon': 'mdi-close-circle', 'color': 'red'})
|
||||
})
|
||||
scanning.value = false
|
||||
emitter.emit('refreshRoms')
|
||||
});
|
||||
}
|
||||
|
||||
await axios.put('/api/scan?overwrite='+scanOverwrite.value,{
|
||||
platforms: platforms
|
||||
}).then((response) => {
|
||||
console.log("scan completed")
|
||||
console.log(response.data)
|
||||
emitter.emit('snackbarScan', {'msg': 'Scan completed successfully!', 'icon': 'mdi-check-bold', 'color': 'green'})
|
||||
}).catch((error) => {
|
||||
console.log(error)
|
||||
emitter.emit('snackbarScan', {'msg': "Couldn't complete scan. Something went wrong...", 'icon': 'mdi-close-circle', 'color': 'red'})
|
||||
})
|
||||
scanning.value = false
|
||||
if (!platforms.length){emitter.emit('refresh')}else{emitter.emit('refreshRoms')}
|
||||
}
|
||||
|
||||
function toggleTheme() {
|
||||
|
||||
Reference in New Issue
Block a user