Skip to content

Commit

Permalink
Open the a1111 image and display the corresponding resources of Civitai
Browse files Browse the repository at this point in the history
  • Loading branch information
hbl917070 committed Apr 2, 2024
1 parent 811fe43 commit a0c80ca
Show file tree
Hide file tree
Showing 5 changed files with 367 additions and 20 deletions.
1 change: 1 addition & 0 deletions Www/ejs/MainWindow/MainWindow.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

<script src="./js/WebAPI.js"></script>
<script src="./js/Config.js"></script>
<script src="./js/MainWindow/IndexedDBManager.js"></script>
<script src="./js/MainWindow/MainToolbar.js"></script>
<script src="./js/MainWindow/FileLoad.js"></script>
<script src="./js/MainWindow/MainFileList.js"></script>
Expand Down
11 changes: 9 additions & 2 deletions Www/ts/MainWindow/AiDrawingPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ class AiDrawingPrompt {
}
let jsonF = Lib.jsonStrFormat(text);
if (jsonF.ok) { // 如果是json (例如 Hashes
text = jsonF.jsonFormat; // 格式化json再顯示
if ("Civitai resources") {
text = text.replace(/[,]/g, `, \n`);
} else {
text = jsonF.jsonFormat; // 格式化json再顯示
}

} else {
if (title === "Tiled Diffusion" && text.startsWith('{') && text.endsWith('}')) { //格式例如 {'Method': 'MultiDiffusion', 'Tile tile width': 96}
text = text.replace(/[,][ ]/g, `, \n`);
Expand Down Expand Up @@ -241,7 +246,9 @@ class AiDrawingPrompt {
for (let i = 0; i < SEED_TYPES.length; i++) {
let text = inputs[SEED_TYPES[i]];
if (text !== undefined) {
return text.toString();
if (typeof text === "string" || typeof text === "number") {
return text.toString();
}
}
}
return undefined;
Expand Down
69 changes: 69 additions & 0 deletions Www/ts/MainWindow/IndexedDBManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* 資料表名稱
*/
var DbStoreName = {
civitaiResources: "civitaiResources",
}

class IndexedDBManager {

private storeNames: string[] = [DbStoreName.civitaiResources]; // 資料表名稱
private dbPromise: Promise<IDBDatabase>;
constructor(private dbName: string, private version: number) {
this.dbPromise = this.init();
}

private init(): Promise<IDBDatabase> {

return new Promise((resolve, reject) => {
const request = indexedDB.open(this.dbName, this.version);

request.onerror = (event) => {
reject("Error opening DB");
};

request.onupgradeneeded = (event) => {
const db = (event.target as IDBOpenDBRequest).result;
this.storeNames.forEach(storeName => {
if (!db.objectStoreNames.contains(storeName)) {
db.createObjectStore(storeName, { keyPath: "id" });
}
});
resolve(db);
};

request.onsuccess = (event) => {
resolve((event.target as IDBOpenDBRequest).result);
};
});
}

public async getData(storeName: string, id: string): Promise<any> {
const db = await this.dbPromise;
return new Promise((resolve, reject) => {
const transaction = db.transaction([storeName]);
const objectStore = transaction.objectStore(storeName);
const request = objectStore.get(id);

request.onerror = (event) => {
reject("Error getting data from DB");
};

request.onsuccess = () => {
resolve(request.result);
};
});
}

/**
*
* @param storeName 資料表名稱
* @param data 必須是物件,且有 id 屬性,例如 {id:123, name:"abc"}
*/
public async saveData(storeName: string, data: any): Promise<void> {
const db = await this.dbPromise;
const transaction = db.transaction([storeName], "readwrite");
const objectStore = transaction.objectStore(storeName);
objectStore.add(data);
}
}
Loading

0 comments on commit a0c80ca

Please sign in to comment.