Skip to content

Commit

Permalink
Merge pull request #76 from fishshi/main
Browse files Browse the repository at this point in the history
Many fixes
  • Loading branch information
ximu3 authored Oct 30, 2024
2 parents 1b450ac + 6368003 commit ccd03d0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions src/renderer/src/components/AddGame.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ function Info() {
let navigate = useNavigate();
const { gameName, gid, vid, setGameName, setGID, setVID, setAlert, setGameList, isLoading, setIsLoading } = useAddGame();
async function submitInfo() {
setIsLoading(true);
if (gameName === '' && gid === '') {
setAlert('请填写游戏原名!');
setTimeout(() => { setAlert(''); }, 3000);
return
}
setIsLoading(true);
if (gid) {
if (String(gid).toLowerCase().startsWith('ga')) {
try {
Expand Down Expand Up @@ -219,7 +219,19 @@ function GameList() {
</table>
</div>
<div className='flex flex-row-reverse items-end gap-5 pt-3'>
<button className='transition-all btn bg-custom-stress text-custom-text-light hover:brightness-125' onClick={() => { next() }}>下一步</button>
<button className='transition-all btn bg-custom-stress text-custom-text-light hover:brightness-125' onClick={() => {
if (gid === '') {
if (gameList.length === 1) {
setGID(gameList[0]["id"])
setGameName(gameList[0]["name"])
} else {
setAlert("请选择游戏!")
setTimeout(() => { setAlert(''); }, 3000);
return;
}
}
next()
}}>下一步</button>
<button className='transition-all btn bg-custom-stress text-custom-text-light hover:brightness-125' onClick={() => { navigate(-1) }}>上一步</button>
</div>
</div>
Expand Down Expand Up @@ -337,7 +349,7 @@ function GamePath() {
}

function GameBg() {
const { gameBgList, gameName, savePath, isLoading, gamePath, setGameBg, gameBg, gid, setIsLoading, vid } = useAddGame();
const { gameBgList, gameName, savePath, isLoading, setAlert, gamePath, setGameBg, gameBg, gid, setIsLoading, vid } = useAddGame();
let navigate = useNavigate();
async function submitAllData() {
if (gameBg === '' && gameBgList.length !== 0) {
Expand Down
23 changes: 13 additions & 10 deletions src/renderer/src/components/scraper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -688,10 +688,11 @@ async function queryVNDB(filters, fields) {
// 获取游戏截图
async function getScreenshotsByTitle(title) {
try {
const data = await queryVNDB(["search", "=", title], "title, screenshots{url}");
const data = await queryVNDB(["search", "=", title], "titles.title, screenshots{url}");
if (data.results.length > 0) {
const vn = data.results[0];
console.log(`获取到 "${vn.title}" 的截图:`);
let vn = data.results.find(vn => vn.titles.some(titleJson => titleJson.title === title));
vn = vn ? vn : data.results[0]; // 不确定会不会找不到对应名称,目前没有测试到这种情况
console.log(`获取到 "${title}" 的截图:`);
return vn.screenshots.map(screenshot => screenshot.url);
} else {
console.log(`未找到标题为 "${title}" 的视觉小说。`);
Expand Down Expand Up @@ -757,14 +758,15 @@ async function getCoverByVID(vid) {
// 获取游戏封面
async function getCoverByTitle(title) {
try {
const data = await queryVNDB(["search", "=", title], "title, image{url}");
const data = await queryVNDB(["search", "=", title], "titles.title, image{url}");
if (data.results.length > 0) {
const vn = data.results[0];
let vn = data.results.find(vn => vn.titles.some(titleJson => titleJson.title === title));
vn = vn ? vn : data.results[0]; // 不确定会不会找不到对应名称,目前没有测试到这种情况
if (vn.image) {
console.log(`获取到 "${vn.title}" 的封面:`);
console.log(`获取到 "${title}" 的封面:`);
return vn.image.url;
} else {
console.log(`"${vn.title}" 没有封面图片。`);
console.log(`"${title}" 没有封面图片。`);
return '';
}
} else {
Expand All @@ -783,10 +785,11 @@ async function getCoverByTitle(title) {

async function getVIDByTitle(title) {
try {
const data = await queryVNDB(["search", "=", title], "id, title");
const data = await queryVNDB(["search", "=", title], "id, titles.title");
if (data.results.length > 0) {
const vn = data.results[0];
console.log(`获取到 "${vn.title}" 的ID:`);
let vn = data.results.find(vn => vn.titles.some(titleJson => titleJson.title === title));
vn = vn ? vn : data.results[0]; // 不确定会不会找不到对应名称,目前没有测试到这种情况
console.log(`获取到 "${title}" 的ID:`);
return vn.id;
} else {
console.log(`未找到标题为 "${title}" 的视觉小说。`);
Expand Down

0 comments on commit ccd03d0

Please sign in to comment.