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

Function uploadableNoteMedia

app/src/sqlite/util.ts:311–355  ·  view source on GitHub ↗
(
	torn: boolean,
	noteId: TId = undefined as TId,
	count: TCount = undefined as TCount,
)

Source from the content-addressed store, hash-verified

309}
310
311export async function uploadableNoteMedia<
312 TId extends NoteId | undefined = undefined,
313 TCount extends true | undefined = undefined,
314>(
315 torn: boolean,
316 noteId: TId = undefined as TId,
317 count: TCount = undefined as TCount,
318) {
319 const r = await ky
320 .selectFrom('remoteMedia')
321 .innerJoin('media', 'remoteMedia.localMediaId', 'media.id')
322 .innerJoin('noteBase', 'remoteMedia.localEntityId', 'noteBase.id')
323 .leftJoin('remoteNote', 'remoteNote.localId', 'noteBase.id')
324 .$if(count === true, (qb) =>
325 qb.select(
326 ky.fn.count<SqliteCount>('remoteMedia.localEntityId').as('count'),
327 ),
328 )
329 .$if(count === undefined, (qb) =>
330 qb.select([
331 'remoteMedia.localMediaId',
332 'media.data',
333 'remoteMedia.localEntityId',
334 'remoteMedia.remoteMediaId',
335 'remoteNote.remoteId',
336 ]),
337 )
338 .$if(noteId != null, (qb) => qb.where('noteBase.id', '=', toLDbId(noteId!)))
339 .$if(torn, (qb) => qb.where('remoteMedia.remoteMediaId', 'is not', null))
340 .where((eb) =>
341 eb.or([
342 eb('remoteMedia.uploadDate', 'is', null),
343 eb('media.edited', '>', eb.ref('remoteMedia.uploadDate')),
344 ]),
345 )
346 .execute()
347 type SqlRow = (typeof r)[0]
348 type R = TCount extends true
349 ? number
350 : Array<Rasterize<Required<Omit<SqlRow, 'count'>>>>
351 if (count) {
352 return r[0]!.count as R
353 }
354 return r as R
355}
356
357export async function uploadableTemplateMedia<
358 TId extends TemplateId | undefined = undefined,

Callers 3

ResumeUploadFunction · 0.90
SyncFunction · 0.90
getMediaToUploadFunction · 0.85

Calls 1

toLDbIdFunction · 0.90

Tested by

no test coverage detected