fix: notification system
This commit is contained in:
@@ -39,6 +39,8 @@ export const Notifications = (onCompleteImage: () => void) => {
|
||||
const [accessToken] = createResource(getAccessToken);
|
||||
|
||||
const dataEventListener = (e: MessageEvent<unknown>) => {
|
||||
debugger;
|
||||
|
||||
if (typeof e.data !== "string") {
|
||||
console.error("Error type is not string");
|
||||
return;
|
||||
@@ -98,7 +100,7 @@ export const Notifications = (onCompleteImage: () => void) => {
|
||||
|
||||
upsertImageProcessing(
|
||||
Object.fromEntries(
|
||||
images.filter(i => i.Status !== 'complete').map((i) => [
|
||||
images.filter(i => i.Status === 'complete').map((i) => [
|
||||
i.ID,
|
||||
{
|
||||
Type: "image",
|
||||
|
||||
@@ -78,17 +78,10 @@ const getBaseAuthorizedRequest = async ({
|
||||
method,
|
||||
});
|
||||
};
|
||||
const sendImageResponseValidator = strictObject({
|
||||
ID: pipe(string(), uuid()),
|
||||
ImageID: pipe(string(), uuid()),
|
||||
UserID: pipe(string(), uuid()),
|
||||
Status: string(),
|
||||
});
|
||||
|
||||
export const sendImageFile = async (
|
||||
imageName: string,
|
||||
file: File,
|
||||
): Promise<InferOutput<typeof sendImageResponseValidator>> => {
|
||||
): Promise<InferOutput<typeof imageValidator>> => {
|
||||
const request = await getBaseAuthorizedRequest({
|
||||
path: `images/${imageName}`,
|
||||
body: file,
|
||||
@@ -98,7 +91,7 @@ export const sendImageFile = async (
|
||||
request.headers.set("Content-Type", "application/oclet-stream");
|
||||
|
||||
const res = await fetch(request).then((res) => res.json());
|
||||
const parsedRes = safeParse(sendImageResponseValidator, res);
|
||||
const parsedRes = safeParse(imageValidator, res);
|
||||
|
||||
if (!parsedRes.success) {
|
||||
console.log(parsedRes.issues)
|
||||
@@ -146,7 +139,7 @@ export class ImageLimitReached extends Error {
|
||||
export const sendImage = async (
|
||||
imageName: string,
|
||||
base64Image: string,
|
||||
): Promise<InferOutput<typeof sendImageResponseValidator>> => {
|
||||
): Promise<InferOutput<typeof imageValidator>> => {
|
||||
const request = await getBaseAuthorizedRequest({
|
||||
path: `images/${imageName}`,
|
||||
body: base64Image,
|
||||
@@ -162,16 +155,16 @@ export const sendImage = async (
|
||||
|
||||
const res = await rawRes.json();
|
||||
|
||||
const parsedRes = safeParse(sendImageResponseValidator, res);
|
||||
const parsedRes = safeParse(imageValidator, res);
|
||||
if (!parsedRes.success) {
|
||||
console.log(parsedRes.issues)
|
||||
console.log("Parsing issues: ", parsedRes.issues)
|
||||
throw new Error(JSON.stringify(parsedRes.issues));
|
||||
}
|
||||
|
||||
return parsedRes.output;
|
||||
};
|
||||
|
||||
const userImageValidator = strictObject({
|
||||
const imageValidator = strictObject({
|
||||
ID: pipe(string(), uuid()),
|
||||
CreatedAt: string(),
|
||||
UserID: pipe(string(), uuid()),
|
||||
@@ -181,7 +174,10 @@ const userImageValidator = strictObject({
|
||||
ImageName: string(),
|
||||
|
||||
Status: union([literal('not-started'), literal('in-progress'), literal('complete')]),
|
||||
})
|
||||
|
||||
const userImageValidator = strictObject({
|
||||
...imageValidator.entries,
|
||||
ImageStacks: pipe(nullable(array(
|
||||
strictObject({
|
||||
ID: pipe(string(), uuid()),
|
||||
|
||||
Reference in New Issue
Block a user