Skip to content

Commit

Permalink
Sync with cloud changes
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed Nov 14, 2023
1 parent b1771f7 commit 562978e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/backend/Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class HandlerConnection implements Connection {
const toApply = await pending.pendingSince(meta.commitHash, this.ctx)
if (!toApply) return meta
await db.applyMutations(toApply.mutations, toApply.toCommitHash)
return await db.meta()
return db.meta()
}

async syncRequired(contentHash: string): Promise<boolean> {
Expand Down
23 changes: 15 additions & 8 deletions src/cloud/server/CloudHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export class CloudApi implements Media, Target, History, Pending, Drafts {
constructor(private config: Config) {}

mutate(params: Connection.MutateParams, ctx: Connection.Context) {
console.log(params)
return fetch(
cloudConfig.mutate,
withAuth(
Expand Down Expand Up @@ -160,7 +161,7 @@ export class CloudApi implements Media, Target, History, Pending, Drafts {
withAuth(
ctx,
asJson({
method: 'POST',
method: 'PUT',
body: JSON.stringify(body)
})
)
Expand All @@ -175,14 +176,20 @@ export class CloudApi implements Media, Target, History, Pending, Drafts {
): Promise<Draft | undefined> {
return fetch(cloudConfig.drafts + '/' + entryId, withAuth(ctx))
.then(failOnHttpError)
.then<OutcomeJSON<{fileHash: string; update: string}>>(json)
.then<Outcome<{fileHash: string; update: string}>>(Outcome.fromJSON)
.then<OutcomeJSON<{fileHash: string; update: string} | null>>(json)
.then<Outcome<{fileHash: string; update: string} | null>>(
Outcome.fromJSON
)
.then(Outcome.unpack)
.then(({fileHash, update}) => ({
entryId,
fileHash,
draft: base64.parse(update)
}))
.then(data => {
return data
? {
entryId,
fileHash: data.fileHash,
draft: base64.parse(data.update)
}
: undefined
})
}
}

Expand Down

0 comments on commit 562978e

Please sign in to comment.