Skip to content

Commit

Permalink
🐛 fix: fix the batch import error (lobehub#2671)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx authored May 26, 2024
1 parent 0b9be47 commit db8f2c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/database/client/core/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,18 @@ export class BaseModel<N extends keyof BrowserDBSchema = any, T = BrowserDBSchem
continue;
}

const getTime = (time?: string | number) => {
if (!time) return Date.now();
if (typeof time === 'number') return time;

return new Date(time).valueOf();
};

validatedData.push({
...item,
createdAt: item.createdAt ?? Date.now(),
createdAt: getTime(item.createdAt as string),
id,
updatedAt: item.updatedAt ?? Date.now(),
updatedAt: getTime(item.updatedAt as string),
});
} else {
errors.push(result.error);
Expand Down
4 changes: 2 additions & 2 deletions src/database/client/core/types/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export type DBModel<T> = T & {
};

export const DBBaseFieldsSchema = z.object({
createdAt: z.number(),
createdAt: z.number().or(z.string()),
id: z.string(),
updatedAt: z.number(),
updatedAt: z.number().or(z.string()),
});

export const LOBE_CHAT_LOCAL_DB_NAME = 'LOBE_CHAT_DB';

0 comments on commit db8f2c6

Please sign in to comment.