MCPcopy Create free account
hub / github.com/AlexErrant/Pentive / makeNoteUploadable

Function makeNoteUploadable

app/src/sqlite/note.ts:391–443  ·  view source on GitHub ↗
(
		remoteNote: Override<
			InsertObject<DB, 'remoteNote'>,
			{ localId: RemoteNote['localId'] }
		> & { note: Note },
	)

Source from the content-addressed store, hash-verified

389 },
390 getMediaToUpload,
391 async makeNoteUploadable(
392 remoteNote: Override<
393 InsertObject<DB, 'remoteNote'>,
394 { localId: RemoteNote['localId'] }
395 > & { note: Note },
396 ) {
397 const { hashByLocal } = await remotifyNote(
398 domainToCreateRemote(remoteNote.note, [
399 /* this doesn't need any real values */
400 ]),
401 )
402 // @ts-expect-error kysley doesn't use note - it's only used by the above
403 delete remoteNote.note
404 await tx(async (db) => {
405 await db
406 .insertInto('remoteNote')
407 .values(remoteNote)
408 .onConflict((db) => db.doNothing())
409 .execute()
410 const srcs = new Set(hashByLocal.keys())
411 const mediaBinaries = await db
412 .selectFrom('media')
413 .select(['id', 'data'])
414 .where('id', 'in', Array.from(srcs))
415 .execute()
416 if (mediaBinaries.length !== srcs.size)
417 C.toastFatal("You're missing a media.") // medTODO better error message
418 // await db // F19F2731-BA29-406F-8F35-4E399CB40242
419 // .deleteFrom('remoteMedia')
420 // .where('localEntityId', '=', remoteNote.localId)
421 // .where('localMediaId', 'in', Array.from(srcs))
422 // .execute()
423 if (hashByLocal.size !== 0) {
424 await db
425 .insertInto('remoteMedia')
426 .values(
427 Array.from(hashByLocal).map(
428 ([localMediaId]) =>
429 ({
430 localEntityId: remoteNote.localId,
431 localMediaId,
432 }) satisfies InsertObject<DB, 'remoteMedia'>,
433 ),
434 )
435 .onConflict((db) =>
436 db.doUpdateSet({
437 localMediaId: (x) => x.ref('excluded.localMediaId'),
438 }),
439 )
440 .execute()
441 }
442 })
443 },
444 async makeNoteNotUploadable(noteId: NoteId, nook: NookId) {
445 const noteDbId = toLDbId(noteId)
446 await tx(async (db) => {

Callers

nothing calls this directly

Calls 2

remotifyNoteFunction · 0.85
domainToCreateRemoteFunction · 0.70

Tested by

no test coverage detected