mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-23 05:33:08 +03:00
fix(server): avoid saving invalid data (#4859)
This commit is contained in:
parent
ac0a3aab3e
commit
01d7fe4597
@ -32,6 +32,14 @@ function compare(yBinary: Buffer, jwstBinary: Buffer, strict = false): boolean {
|
||||
return compare(yBinary, yBinary2, true);
|
||||
}
|
||||
|
||||
function isEmptyBuffer(buf: Buffer): boolean {
|
||||
return (
|
||||
buf.length == 0 ||
|
||||
// 0x0000
|
||||
(buf.length === 2 && buf[0] === 0 && buf[1] === 0)
|
||||
);
|
||||
}
|
||||
|
||||
const MAX_SEQ_NUM = 0x3fffffff; // u31
|
||||
|
||||
/**
|
||||
@ -377,6 +385,11 @@ export class DocManager implements OnModuleInit, OnModuleDestroy {
|
||||
) {
|
||||
const blob = Buffer.from(encodeStateAsUpdate(doc));
|
||||
const state = Buffer.from(encodeStateVector(doc));
|
||||
|
||||
if (isEmptyBuffer(blob)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.db.snapshot.upsert({
|
||||
where: {
|
||||
id_workspaceId: {
|
||||
|
Loading…
Reference in New Issue
Block a user