Skip to content

Commit

Permalink
feat: add model description and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
albertpb committed Oct 28, 2023
1 parent 14071fb commit a0f8ccb
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 26 deletions.
124 changes: 122 additions & 2 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"electron-log": "^4.4.8",
"electron-updater": "^6.1.4",
"fuse.js": "^6.6.2",
"html-react-parser": "^4.2.9",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-multi-carousel": "^2.8.4",
Expand Down
12 changes: 12 additions & 0 deletions src/main/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,17 @@ export default class SqliteDB {

version.user_version = 5;
}

if (version.user_version === 5) {
try {
await db.run(`ALTER TABLE models ADD COLUMN description TEXT`);
} catch (error) {
console.log(error);
}

await db.run(`PRAGMA user_version = 6`);

version.user_version = 6;
}
}
}
2 changes: 1 addition & 1 deletion src/main/ipc/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { checkFileExists } from '../util';

export const readImageMetadata = async (
event: IpcMainInvokeEvent,
path: string
path: string,
) => {
const fileExists = await checkFileExists(path);

Expand Down
14 changes: 14 additions & 0 deletions src/main/ipc/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type Model = {
baseModel: string | null;
modelId: number | null;
modelVersionId: number | null;
description: string;
};

export const readdirModelsIpc = async (
Expand Down Expand Up @@ -125,6 +126,7 @@ export const readdirModelsIpc = async (
baseModel: modelInfo?.baseModel || '',
modelId: modelInfo?.id || null,
modelVersionId: modelInfo?.modelId || null,
description: '',
};
}

Expand Down Expand Up @@ -205,6 +207,18 @@ export const readdirModelsIpc = async (
);
}
}

if (!modelsHashMap[fileNameNoExt].description) {
if (modelInfo) {
await db.run(
`UPDATE models SET description = $description WHERE hash = $hash`,
{
$description: modelInfo.description,
$hash: modelsHashMap[fileNameNoExt].hash,
},
);
}
}
}

return modelsHashMap;
Expand Down
2 changes: 1 addition & 1 deletion src/main/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export async function downloadModelInfoByHash(
await fs.promises.writeFile(
`${downloadDir}\\${modelName}.civitai.info`,
JSON.stringify(response.data, null, 2),
{ encoding: 'utf-8' },
{ encoding: 'utf-8', flag: 'w' },
);

return response.data;
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/pages/modelDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import classNames from 'classnames';
import { IpcRendererEvent } from 'electron';
import ReactHtmlParser from 'html-react-parser';
import { ImageRow } from 'main/ipc/organizeImages';
import { useNavigate, useParams } from 'react-router-dom';
import { ModelCivitaiInfo } from 'main/interfaces';
Expand Down Expand Up @@ -422,6 +423,7 @@ export default function ModelDetail() {
</div>
</div>
</div>
<div>{ReactHtmlParser(modelData.description || '')}</div>
{chunks.length > 0 ? (
<div className="">
<div className="flex items-center">
Expand Down
Loading

0 comments on commit a0f8ccb

Please sign in to comment.