mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
feat(mobile): ios widget deeplink to asset in app (#19510)
* feat: ios widget deeplinks to asset in app * fix: casing --------- Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
parent
5f89c2d111
commit
64cc7239fe
@ -3,7 +3,7 @@ import WidgetKit
|
|||||||
|
|
||||||
func buildEntry(
|
func buildEntry(
|
||||||
api: ImmichAPI,
|
api: ImmichAPI,
|
||||||
asset: SearchResult,
|
asset: Asset,
|
||||||
dateOffset: Int,
|
dateOffset: Int,
|
||||||
subtitle: String? = nil
|
subtitle: String? = nil
|
||||||
)
|
)
|
||||||
@ -15,7 +15,8 @@ func buildEntry(
|
|||||||
to: Date.now
|
to: Date.now
|
||||||
)!
|
)!
|
||||||
let image = try await api.fetchImage(asset: asset)
|
let image = try await api.fetchImage(asset: asset)
|
||||||
return ImageEntry(date: entryDate, image: image, subtitle: subtitle)
|
|
||||||
|
return ImageEntry(date: entryDate, image: image, subtitle: subtitle, deepLink: asset.deepLink)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRandomEntries(
|
func generateRandomEntries(
|
||||||
|
@ -6,6 +6,7 @@ struct ImageEntry: TimelineEntry {
|
|||||||
var image: UIImage?
|
var image: UIImage?
|
||||||
var subtitle: String? = nil
|
var subtitle: String? = nil
|
||||||
var error: WidgetError? = nil
|
var error: WidgetError? = nil
|
||||||
|
var deepLink: URL? = nil
|
||||||
|
|
||||||
// Resizes the stored image to a maximum width of 450 pixels
|
// Resizes the stored image to a maximum width of 450 pixels
|
||||||
mutating func resize() {
|
mutating func resize() {
|
||||||
@ -54,6 +55,7 @@ struct ImmichWidgetView: View {
|
|||||||
}
|
}
|
||||||
.padding(16)
|
.padding(16)
|
||||||
}
|
}
|
||||||
|
.widgetURL(entry.deepLink)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,9 +43,13 @@ enum AssetType: String, Codable {
|
|||||||
case other = "OTHER"
|
case other = "OTHER"
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SearchResult: Codable {
|
struct Asset: Codable {
|
||||||
let id: String
|
let id: String
|
||||||
let type: AssetType
|
let type: AssetType
|
||||||
|
|
||||||
|
var deepLink: URL? {
|
||||||
|
return URL(string: "immich://asset?id=\(id)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SearchFilters: Codable {
|
struct SearchFilters: Codable {
|
||||||
@ -56,7 +60,7 @@ struct SearchFilters: Codable {
|
|||||||
|
|
||||||
struct MemoryResult: Codable {
|
struct MemoryResult: Codable {
|
||||||
let id: String
|
let id: String
|
||||||
var assets: [SearchResult]
|
var assets: [Asset]
|
||||||
let type: String
|
let type: String
|
||||||
|
|
||||||
struct MemoryData: Codable {
|
struct MemoryData: Codable {
|
||||||
@ -127,7 +131,7 @@ class ImmichAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fetchSearchResults(with filters: SearchFilters) async throws
|
func fetchSearchResults(with filters: SearchFilters) async throws
|
||||||
-> [SearchResult]
|
-> [Asset]
|
||||||
{
|
{
|
||||||
// get URL
|
// get URL
|
||||||
guard
|
guard
|
||||||
@ -147,7 +151,7 @@ class ImmichAPI {
|
|||||||
let (data, _) = try await URLSession.shared.data(for: request)
|
let (data, _) = try await URLSession.shared.data(for: request)
|
||||||
|
|
||||||
// decode data
|
// decode data
|
||||||
return try JSONDecoder().decode([SearchResult].self, from: data)
|
return try JSONDecoder().decode([Asset].self, from: data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchMemory(for date: Date) async throws -> [MemoryResult] {
|
func fetchMemory(for date: Date) async throws -> [MemoryResult] {
|
||||||
@ -172,7 +176,7 @@ class ImmichAPI {
|
|||||||
return try JSONDecoder().decode([MemoryResult].self, from: data)
|
return try JSONDecoder().decode([MemoryResult].self, from: data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fetchImage(asset: SearchResult) async throws(WidgetError) -> UIImage {
|
func fetchImage(asset: Asset) async throws(WidgetError) -> UIImage {
|
||||||
let thumbnailParams = [URLQueryItem(name: "size", value: "preview")]
|
let thumbnailParams = [URLQueryItem(name: "size", value: "preview")]
|
||||||
let assetEndpoint = "/assets/" + asset.id + "/thumbnail"
|
let assetEndpoint = "/assets/" + asset.id + "/thumbnail"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user