fix(sse): some bugs
This commit is contained in:
@ -43,6 +43,8 @@ func ListenNewImageEvents(db *sql.DB, eventManager *EventManager) {
|
|||||||
|
|
||||||
databaseEventLog.Debug("Starting processing image", "ImageID", imageId)
|
databaseEventLog.Debug("Starting processing image", "ImageID", imageId)
|
||||||
|
|
||||||
|
time.Sleep(5 * time.Second)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -254,10 +254,15 @@ func main() {
|
|||||||
|
|
||||||
id := r.PathValue("id")
|
id := r.PathValue("id")
|
||||||
|
|
||||||
|
// TODO: get the current status of the image and send it across.
|
||||||
|
ctx, cancel := context.WithCancel(r.Context())
|
||||||
|
|
||||||
imageNotifier, exists := eventManager.listeners[id]
|
imageNotifier, exists := eventManager.listeners[id]
|
||||||
if !exists {
|
if !exists {
|
||||||
fmt.Println("Not found!")
|
fmt.Println("Not found!")
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
|
w.(http.Flusher).Flush()
|
||||||
|
cancel()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,10 +271,6 @@ func main() {
|
|||||||
w.Header().Set("Connection", "keep-alive")
|
w.Header().Set("Connection", "keep-alive")
|
||||||
w.(http.Flusher).Flush()
|
w.(http.Flusher).Flush()
|
||||||
|
|
||||||
// TODO: get the current status of the image and send it across.
|
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(r.Context())
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
@ -62,7 +62,10 @@ export const App = () => {
|
|||||||
Take Screenshot [wayland :(]
|
Take Screenshot [wayland :(]
|
||||||
</button>
|
</button>
|
||||||
<ImageViewer onSendImage={setProcessingImage} />
|
<ImageViewer onSendImage={setProcessingImage} />
|
||||||
<ImageStatus processingImage={processingImage} />
|
<ImageStatus
|
||||||
|
processingImage={processingImage}
|
||||||
|
onSetProcessingImage={setProcessingImage}
|
||||||
|
/>
|
||||||
<Router>
|
<Router>
|
||||||
<Route path="/login" component={Login} />
|
<Route path="/login" component={Login} />
|
||||||
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import { createEffect, Show, type Accessor, type Component } from "solid-js";
|
import { createEffect, Show, type Accessor, type Component } from "solid-js";
|
||||||
import type { sendImage } from "../../network";
|
import { base, type sendImage } from "../../network";
|
||||||
import { useSearchImageContext } from "../../contexts/SearchImageContext";
|
import { useSearchImageContext } from "../../contexts/SearchImageContext";
|
||||||
|
|
||||||
type ImageStatusProps = {
|
type ImageStatusProps = {
|
||||||
|
onSetProcessingImage: (
|
||||||
|
image: Awaited<ReturnType<typeof sendImage>> | undefined,
|
||||||
|
) => void;
|
||||||
processingImage: Accessor<
|
processingImage: Accessor<
|
||||||
Awaited<ReturnType<typeof sendImage>> | undefined
|
Awaited<ReturnType<typeof sendImage>> | undefined
|
||||||
>;
|
>;
|
||||||
@ -16,10 +19,21 @@ export const ImageStatus: Component<ImageStatusProps> = (props) => {
|
|||||||
const onEvent = (e: MessageEvent<EventData>) => {
|
const onEvent = (e: MessageEvent<EventData>) => {
|
||||||
console.log(e.data);
|
console.log(e.data);
|
||||||
|
|
||||||
|
const processingImage = props.processingImage();
|
||||||
|
if (processingImage == null) {
|
||||||
|
throw new Error("Processing Image should not be null");
|
||||||
|
}
|
||||||
|
|
||||||
if (e.data !== "complete") {
|
if (e.data !== "complete") {
|
||||||
|
props.onSetProcessingImage({
|
||||||
|
...processingImage,
|
||||||
|
Status: e.data,
|
||||||
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
props.onSetProcessingImage(undefined);
|
||||||
onRefetchImages();
|
onRefetchImages();
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -29,9 +43,10 @@ export const ImageStatus: Component<ImageStatusProps> = (props) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const eventSource = new EventSource(
|
const eventSourceUrl = `${base}/image-events/${image.ID}`;
|
||||||
`http://192.168.1.199:3040/image-events/${image.ID}`,
|
|
||||||
);
|
const eventSource = new EventSource(eventSourceUrl);
|
||||||
|
console.log("URL: ", eventSourceUrl);
|
||||||
|
|
||||||
eventSource.addEventListener("data", onEvent);
|
eventSource.addEventListener("data", onEvent);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user