( torn: boolean, noteId: TId = undefined as TId, count: TCount = undefined as TCount, )
| 309 | } |
| 310 | |
| 311 | export 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 | |
| 357 | export async function uploadableTemplateMedia< |
| 358 | TId extends TemplateId | undefined = undefined, |
no test coverage detected