本地保存上次关键词、将报错中的NovelAI改为Naifu

master
落雨楓 2 years ago
parent ab52deffb4
commit 3166357069

@ -54,7 +54,7 @@ function formatRequestError(error: string): string {
`${error}`.toLowerCase() === 'timeout' || `${error}`.toLowerCase() === 'timeout' ||
`${error}`.toLowerCase().includes('timeout fetching') `${error}`.toLowerCase().includes('timeout fetching')
) { ) {
return 'Error: Timeout - Unable to reach NovelAI servers. Please wait for a moment and try again' return 'Error: Timeout - Unable to reach Naifu servers. Please wait for a moment and try again'
} }
if (`${error}`.toLowerCase().includes('worker timeout')) { if (`${error}`.toLowerCase().includes('worker timeout')) {
return `${error} - Please try again, or if this issue persists, \ return `${error} - Please try again, or if this issue persists, \

@ -744,7 +744,7 @@ const help_tips = [
[ [
'Privacy', 'Privacy',
'Encryption', 'Encryption',
'AES-256 is used to encrypt your Stories before being sent to the NovelAI servers. No one can access them without your encryption key.', 'AES-256 is used to encrypt your Stories before being sent to the Naifu servers. No one can access them without your encryption key.',
], ],
*/ */
[ [
@ -969,7 +969,7 @@ const help_tips = [
[ [
'Settings', 'Settings',
'Default Storage Location', 'Default Storage Location',
'Choose to keep your Stories on your device, or upload them to the NovelAI servers. Local stories rely on your browser cache, which can be cleared on occasion. All Stories on the NovelAI servers are specially encrypted so only you can view them.', 'Choose to keep your Stories on your device, or upload them to the Naifu servers. Local stories rely on your browser cache, which can be cleared on occasion. All Stories on the Naifu servers are specially encrypted so only you can view them.',
], ],
[ [
'Settings', 'Settings',

@ -510,7 +510,7 @@ export class RemoteGenerationRequest implements IGenerationRequest {
onError({ onError({
status: 408, status: 408,
message: message:
'Error: Timeout - Unable to reach NovelAI servers. Please wait for a moment and try again', 'Error: Timeout - Unable to reach Naifu servers. Please wait for a moment and try again',
}) })
}, 3600 * 1000) }, 3600 * 1000)
@ -1164,10 +1164,10 @@ export class RemoteImageGenerationRequest {
status: bind.status ?? 500, status: bind.status ?? 500,
message: errorData.error, message: errorData.error,
}) })
} catch(err) { } catch (err) {
onError({ onError({
status: bind.status ?? 500, status: bind.status ?? 500,
message: `Error: HTTP ${bind.status} - Unable to reach NovelAI servers. Please wait for a moment and try again`, message: `Error: HTTP ${bind.status} - Unable to reach Naifu servers. Please wait for a moment and try again`,
}) })
} }
return return
@ -1191,11 +1191,12 @@ export class RemoteImageGenerationRequest {
}), }),
} }
let res: any = {};
try {
const bind = await fetchWithTimeout(BackendURLGetTaskInfo, requestGetTask) const bind = await fetchWithTimeout(BackendURLGetTaskInfo, requestGetTask)
if (!bind.ok) { if (!bind.ok) {
logError(bind, false) logError(bind, false)
try {
let errorData = await bind.json() let errorData = await bind.json()
onError({ onError({
@ -1203,11 +1204,11 @@ export class RemoteImageGenerationRequest {
message: errorData.error, message: errorData.error,
}) })
return return
} catch(err) {
// don't stop generate when http error
} }
res = await bind.json()
} catch (err) {
// don't stop generate when http error
} }
let res = await bind.json()
// console.log('task info', res) // console.log('task info', res)
let progress = 0; let progress = 0;
@ -1236,7 +1237,7 @@ export class RemoteImageGenerationRequest {
onError({ onError({
status: 408, status: 408,
message: message:
'Error: Timeout - Unable to reach NovelAI servers. Please wait for a moment and try again', 'Error: Timeout - Unable to reach Naifu servers. Please wait for a moment and try again',
}) })
}, 30 * 1000) }, 30 * 1000)

@ -462,9 +462,29 @@ function ImageGenContent(): JSX.Element {
const [params, actualSetParams] = useState<any>( const [params, actualSetParams] = useState<any>(
getModelDefaultParams(ImageGenerationModels.stableDiffusion) getModelDefaultParams(ImageGenerationModels.stableDiffusion)
) )
const [initialized, setInitialized] = useState(false)
const [prompt, setPrompt] = useState([''] as string[]) const [prompt, setPrompt] = useState([''] as string[])
const [promptLines, setPromptLines] = useState([1] as number[]) const [promptLines, setPromptLines] = useState([1] as number[])
const [savedPrompt, setSavedPrompt] = useRememberedValue('imagegen-prompt', [''] as string[])
const [negPrompt, setNegPrompt] = useRememberedValue('imagegen-negativeprompt', '') const [negPrompt, setNegPrompt] = useRememberedValue('imagegen-negativeprompt', '')
const [notiEnabled, setNotiEnabled] = useRememberedValue<boolean>('imagegen-enable-notification', false)
// Sync prompt and savedPrompt
useEffect(() => {
if (!initialized) {
setInitialized(true)
return // Ignore default value
}
if (prompt != savedPrompt) {
setSavedPrompt(prompt)
}
}, [prompt])
useEffect(() => {
if (savedPrompt != prompt) {
setPrompt(savedPrompt)
}
}, [savedPrompt])
// Queue remaining toast // Queue remaining toast
const queueToastId = React.useRef<any>(null); const queueToastId = React.useRef<any>(null);
@ -675,7 +695,7 @@ function ImageGenContent(): JSX.Element {
}) })
.catch((error) => { .catch((error) => {
logError(error) logError(error)
toast.error(`Error: ${error.message} - Unable to reach NovelAI servers. Please wait for a moment and try again`, { toast.error(`Error: ${error.message} - Unable to reach Naifu servers. Please wait for a moment and try again`, {
toastId: 'promptSuggesionError' toastId: 'promptSuggesionError'
}) })
}) })
@ -1049,6 +1069,18 @@ function ImageGenContent(): JSX.Element {
setImages([newImages, ...images]) setImages([newImages, ...images])
} }
lastGenerationParams = paramString lastGenerationParams = paramString
if (notiEnabled) {
const notification = new Notification('Naifu', {
body: 'Image generation completed',
icon: newImages[0].url,
image: newImages[0].url,
tag: 'imagegen-complete'
})
notification.onclick = () => {
window.focus()
}
}
} }
} }
) )
@ -1136,6 +1168,18 @@ function ImageGenContent(): JSX.Element {
setImages([newImages, ...images]) setImages([newImages, ...images])
setRerollImageInfo(newImages[0]) setRerollImageInfo(newImages[0])
lastGenerationParams = paramString lastGenerationParams = paramString
if (notiEnabled) {
const notification = new Notification('Naifu', {
body: 'Image generation completed',
icon: newImages[0].url,
image: newImages[0].url,
tag: 'imagegen-complete'
})
notification.onclick = () => {
window.focus()
}
}
} }
resolve({ images: newImages, seeds: masks.map((m) => m.seed) }) resolve({ images: newImages, seeds: masks.map((m) => m.seed) })
} }
@ -2596,6 +2640,8 @@ function ImageGenContent(): JSX.Element {
params={params} params={params}
setParams={setParams} setParams={setParams}
model={selectedModel} model={selectedModel}
notiEnabled={notiEnabled}
setNotiEnabled={setNotiEnabled}
initImage={initImage} initImage={initImage}
setInitImage={setInitImage} setInitImage={setInitImage}
negPrompt={negPrompt} negPrompt={negPrompt}
@ -3234,6 +3280,8 @@ function GenerationOptions(props: {
params: any params: any
setParams: React.Dispatch<React.SetStateAction<any>> setParams: React.Dispatch<React.SetStateAction<any>>
children?: JSX.Element | JSX.Element[] children?: JSX.Element | JSX.Element[]
notiEnabled: boolean
setNotiEnabled: (b: boolean) => void
initImage: Buffer | undefined initImage: Buffer | undefined
setInitImage: React.Dispatch<React.SetStateAction<Buffer | undefined>> setInitImage: React.Dispatch<React.SetStateAction<Buffer | undefined>>
negPrompt: string negPrompt: string
@ -3243,6 +3291,31 @@ function GenerationOptions(props: {
}): JSX.Element { }): JSX.Element {
const [selectedResolution, setSelectedResolution] = useState(0) const [selectedResolution, setSelectedResolution] = useState(0)
const siteTheme = useRecoilValue(SiteTheme) const siteTheme = useRecoilValue(SiteTheme)
const [notiEnabled, setLocalNotiEnabled] = useState(false)
useEffect(() => {
setLocalNotiEnabled(props.notiEnabled)
}, [props.notiEnabled])
const setNotiEnabled = useCallback((b: boolean) => {
if (typeof window !== "undefined") {
if (window.Notification.permission === 'denied') {
toast.warn("You've disabled Notification in browser settings.")
} else {
if (window.Notification.permission !== 'granted' && b) {
window.Notification.requestPermission().then((res) => {
if (res === 'granted') {
props.setNotiEnabled(true)
} else {
props.setNotiEnabled(false)
}
})
} else {
props.setNotiEnabled(b)
}
}
}
}, [])
useEffect(() => { useEffect(() => {
if (props.params.width && props.params.height) { if (props.params.width && props.params.height) {
@ -3267,6 +3340,21 @@ function GenerationOptions(props: {
const stableDiffusionSettings = ( const stableDiffusionSettings = (
<> <>
<BorderBox>
<FlexRow>
<Title>Notification</Title>
</FlexRow>
<Checkbox
label={'Enable Notification'}
checkedText={'Notification will be displayed when image generation is completed.'}
uncheckedText={'Notification will be displayed when image generation is completed.'}
value={notiEnabled}
setValue={setNotiEnabled}
alternate
/>
</BorderBox>
<FlexColSpacer min={20} max={20} />
<BorderBox> <BorderBox>
<FlexRow> <FlexRow>
<Title>Image Resolution</Title> <Title>Image Resolution</Title>

Loading…
Cancel
Save