mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
* feat: ios widget deeplinks to asset in app * fix: casing --------- Co-authored-by: Alex <alex.tran1502@gmail.com>
60 lines
1.2 KiB
Swift
60 lines
1.2 KiB
Swift
import SwiftUI
|
|
import WidgetKit
|
|
|
|
func buildEntry(
|
|
api: ImmichAPI,
|
|
asset: Asset,
|
|
dateOffset: Int,
|
|
subtitle: String? = nil
|
|
)
|
|
async throws -> ImageEntry
|
|
{
|
|
let entryDate = Calendar.current.date(
|
|
byAdding: .minute,
|
|
value: dateOffset * 20,
|
|
to: Date.now
|
|
)!
|
|
let image = try await api.fetchImage(asset: asset)
|
|
|
|
return ImageEntry(date: entryDate, image: image, subtitle: subtitle, deepLink: asset.deepLink)
|
|
}
|
|
|
|
func generateRandomEntries(
|
|
api: ImmichAPI,
|
|
now: Date,
|
|
count: Int,
|
|
albumId: String? = nil,
|
|
subtitle: String? = nil
|
|
)
|
|
async throws -> [ImageEntry]
|
|
{
|
|
|
|
var entries: [ImageEntry] = []
|
|
let albumIds = albumId != nil ? [albumId!] : []
|
|
|
|
let randomAssets = try await api.fetchSearchResults(
|
|
with: SearchFilters(size: count, albumIds: albumIds)
|
|
)
|
|
|
|
await withTaskGroup(of: ImageEntry?.self) { group in
|
|
for (dateOffset, asset) in randomAssets.enumerated() {
|
|
group.addTask {
|
|
return try? await buildEntry(
|
|
api: api,
|
|
asset: asset,
|
|
dateOffset: dateOffset,
|
|
subtitle: subtitle
|
|
)
|
|
}
|
|
}
|
|
|
|
for await result in group {
|
|
if let entry = result {
|
|
entries.append(entry)
|
|
}
|
|
}
|
|
}
|
|
|
|
return entries
|
|
}
|