Skip to content

Commit 310021f

Browse files
committed
Fix searching for civitai loras
1 parent 72142e9 commit 310021f

File tree

4 files changed

+55
-14
lines changed

4 files changed

+55
-14
lines changed

src/app/home/add-loras/add-loras.component.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
pInputText
2323
[(ngModel)]="searchField"
2424
placeholder="Search LoRA by Name"
25+
(keyup.enter)="search()"
2526
/>
2627

2728
<input
@@ -30,6 +31,7 @@
3031
pInputText
3132
[(ngModel)]="searchField"
3233
placeholder="Enter LoRA Model ID"
34+
(keyup.enter)="search()"
3335
/>
3436

3537
<input
@@ -38,8 +40,16 @@
3840
pInputText
3941
[(ngModel)]="searchField"
4042
placeholder="Enter LoRA Creator's CivitAI Username"
43+
(keyup.enter)="search()"
4144
/>
4245
</div>
46+
47+
<div class="p-field d-flex justify-content-end align-items-center" style="margin-top: 8px;">
48+
<span class="d-flex align-items-center">
49+
Show NSFW results?
50+
<p-inputSwitch [(ngModel)]="showNSFWLoras" [class]="'ms-2'" (ngModelChange)="onShowNsfwChanged()"></p-inputSwitch>
51+
</span>
52+
</div>
4353
<div>
4454
<button
4555
pButton

src/app/home/add-loras/add-loras.component.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnInit } from '@angular/core';
22
import { DynamicDialogRef } from 'primeng/dynamicdialog';
33
import { DynamicDialogConfig } from 'primeng/dynamicdialog';
44
import { StableDiffusionService } from 'src/app/stable-diffusion.service';
@@ -17,6 +17,8 @@ export class AddLorasComponent {
1717
loraFile: File | null = null;
1818
searchField: string = ''; // New field for search field
1919

20+
showNSFWLoras: boolean = false;
21+
2022
searchResults: any[] = []; // Will hold the API search results
2123
selectedLoRA: any = null; // Holds the selected LoRA from the table
2224
showImageDialog: boolean = false; // Track the state of the image dialog
@@ -32,6 +34,21 @@ export class AddLorasComponent {
3234
, private sharedService: SharedService
3335
) { }
3436

37+
ngOnInit(): void {
38+
const fromParent = this.config?.data?.showNSFWLoras;
39+
if (typeof fromParent === 'boolean') {
40+
this.showNSFWLoras = fromParent;
41+
return;
42+
}
43+
44+
const stored = localStorage.getItem('showNSFWLoras');
45+
if (stored != null) this.showNSFWLoras = stored === 'true';
46+
}
47+
48+
onShowNsfwChanged(): void {
49+
localStorage.setItem('showNSFWLoras', this.showNSFWLoras.toString());
50+
}
51+
3552
selectOption(option: string) {
3653
this.selectedSearchOption = option;
3754
this.searchResults = [];
@@ -47,6 +64,8 @@ export class AddLorasComponent {
4764
}
4865

4966
search() {
67+
if (this.isLoading || !this.searchField) return;
68+
5069
if (this.selectedSearchOption === 'username') {
5170
this.searchByUsername();
5271
} else if (this.selectedSearchOption === 'lora_name') {
@@ -58,7 +77,7 @@ export class AddLorasComponent {
5877

5978
searchByUsername() {
6079
this.isLoading = true; // Start loading
61-
this.stableDiffusionService.searchByUser(this.searchField).subscribe({
80+
this.stableDiffusionService.searchByUser(this.searchField, this.showNSFWLoras).subscribe({
6281
next: (response: any) => {
6382
console.log('civitAi user search done');
6483
this.searchResults = response;
@@ -80,7 +99,7 @@ export class AddLorasComponent {
8099

81100
searchByLoRAName() {
82101
this.isLoading = true; // Start loading
83-
this.stableDiffusionService.searchByQuery(this.searchField).subscribe({
102+
this.stableDiffusionService.searchByQuery(this.searchField, this.showNSFWLoras).subscribe({
84103
next: (response: any) => {
85104
console.log('civitAi query search done');
86105
this.searchResults = response;
@@ -103,7 +122,7 @@ export class AddLorasComponent {
103122
// New method to search by Model ID
104123
searchByModelId() {
105124
this.isLoading = true; // Start loading
106-
this.stableDiffusionService.searchByID(this.searchField).subscribe({
125+
this.stableDiffusionService.searchByID(this.searchField, this.showNSFWLoras).subscribe({
107126
next: (response: any) => {
108127
this.searchResults = response;
109128

@@ -159,7 +178,7 @@ export class AddLorasComponent {
159178
}
160179
});
161180
}
162-
this.ref.close();
181+
this.ref.close({ showNSFWLoras: this.showNSFWLoras });
163182
}
164183

165184
selectLora(lora: any) {
@@ -174,7 +193,7 @@ export class AddLorasComponent {
174193

175194

176195
close() {
177-
this.ref.close();
196+
this.ref.close({ showNSFWLoras: this.showNSFWLoras });
178197
}
179198

180199
showError(error: any) {

src/app/home/options/options.component.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,9 +1914,21 @@ export class OptionsComponent implements OnInit {
19141914
}
19151915

19161916
// Open the dialog with the dynamic width
1917-
this.dialogService.open(AddLorasComponent, {
1917+
const dialogRef = this.dialogService.open(AddLorasComponent, {
19181918
header: 'Request Loras To Be Added!',
1919-
width: dialogWidth
1919+
width: dialogWidth,
1920+
data: {
1921+
showNSFWLoras: this.showNSFWLoras,
1922+
},
1923+
});
1924+
1925+
dialogRef.onClose.subscribe((result: any) => {
1926+
const next = result?.showNSFWLoras;
1927+
if (typeof next === 'boolean' && next !== this.showNSFWLoras) {
1928+
this.showNSFWLoras = next;
1929+
localStorage.setItem('showNSFWLoras', this.showNSFWLoras.toString());
1930+
this.filterLoras();
1931+
}
19201932
});
19211933
}
19221934

src/app/stable-diffusion.service.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,18 @@ export class StableDiffusionService {
138138
//#endregion
139139

140140
//#region CivitAI API calls
141-
searchByQuery(query: string): Observable<any> {
142-
const url = `${this.apiBaseUrl}/search_civitAi_loras_by_query/${query}`; // note the trailing slash
141+
searchByQuery(query: string, showNsfw: boolean = false): Observable<any> {
142+
const url = `${this.apiBaseUrl}/search_civitAi_loras_by_query/${encodeURIComponent(query)}?show_nsfw=${showNsfw}`;
143143
return this.http.get(url);
144144
}
145145

146-
searchByID(id: string): Observable<any> {
147-
const url = `${this.apiBaseUrl}/search_civitAi_loras_by_id/${id}`; // note the trailing slash
146+
searchByID(id: string, showNsfw: boolean = false): Observable<any> {
147+
const url = `${this.apiBaseUrl}/search_civitAi_loras_by_id/${encodeURIComponent(id)}?show_nsfw=${showNsfw}`;
148148
return this.http.get(url);
149149
}
150150

151-
searchByUser(username: string): Observable<any> {
152-
const url = `${this.apiBaseUrl}/search_civitAi_loras_by_user/${username}`; // note the trailing slash
151+
searchByUser(username: string, showNsfw: boolean = false): Observable<any> {
152+
const url = `${this.apiBaseUrl}/search_civitAi_loras_by_user/${encodeURIComponent(username)}?show_nsfw=${showNsfw}`;
153153
return this.http.get(url);
154154
}
155155

0 commit comments

Comments
 (0)