Skip to content

Open source CapCut alternative.

TypeScript

fix(ios): send the inspiration item's id with its link import

David Le1d76f96edddf
diff --git a/apps/ios/Donkey/Controllers/CutCloudClient.swift b/apps/ios/Donkey/Controllers/CutCloudClient.swift
index 07489fe0..556cb7f6 100644
--- a/apps/ios/Donkey/Controllers/CutCloudClient.swift
+++ b/apps/ios/Donkey/Controllers/CutCloudClient.swift
@@ -366,13 +366,13 @@ extension CutCloudClient: CloudSyncServicing {
)
}
- func importInspirationLink(_ url: URL) async throws -> String {
+ func importInspirationLink(_ url: URL, key: String) async throws -> String {
struct QueuedJob: Decodable { var jobId: String }
let data = try await send(
try request(
"POST",
"/api/cut-cloud/library/import-url",
- body: ["url": url.absoluteString, "origin": "inspiration"]
+ body: ["url": url.absoluteString, "origin": "inspiration", "key": key]
)
)
return try decode(QueuedJob.self, from: data).jobId
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CloudSync.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CloudSync.swift
index 6f248b0b..e8fb0e79 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CloudSync.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/CloudSync.swift
@@ -304,7 +304,10 @@ public protocol CloudSyncServicing: AnyObject {
/// Queue a cloud-side import of an inspiration link (the render worker
/// fetches the media into the Inspiration folder). Returns the job id the
/// phone follows to bring the media down.
- func importInspirationLink(_ url: URL) async throws -> String
+ /// Hand a link to the cloud worker. `key` is the item's own id: a link
+ /// posted again — the first answer never arrived — gets the job it already
+ /// has, so the media lands once.
+ func importInspirationLink(_ url: URL, key: String) async throws -> String
/// Where an import job stands.
func importedLink(jobId: String) async throws -> LinkImport
/// Download one library media file to a local URL. Posters only: a link's
diff --git a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/SyncEngine.swift b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/SyncEngine.swift
index e16ea426..ec234b01 100644
--- a/apps/ios/DonkeyKit/Sources/DonkeyKitModels/SyncEngine.swift
+++ b/apps/ios/DonkeyKit/Sources/DonkeyKitModels/SyncEngine.swift
@@ -700,7 +700,7 @@ public final class SyncEngine {
guard online else { continue }
if ((try? journal.isInspirationLinkSynced(item.id)) ?? true) == false {
do {
- let jobId = try await service.importInspirationLink(url)
+ let jobId = try await service.importInspirationLink(url, key: item.id.uuidString)
try? journal.markInspirationLinkSynced(item.id, jobId: jobId)
landed = true
} catch CloudSyncError.unauthorized {
diff --git a/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift b/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift
index 8d295be4..7720e9a2 100644
--- a/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift
+++ b/apps/ios/DonkeyKit/Tests/DonkeyKitModelsTests/DonkeyKitModelsTests.swift
@@ -215,6 +215,7 @@ import Testing
var deletedLibraryIds: Set<String> = []
var deletedNotes: [UUID] = []
var links: [URL] = []
+ var linkKeys: [String] = []
var polled: [String] = []
var downloads: [String] = []
var folders: [UUID: RemoteNoteFolder] = [:]
@@ -270,9 +271,10 @@ import Testing
/// does.
var importFailure: CloudSyncError?
- func importInspirationLink(_ url: URL) async throws -> String {
+ func importInspirationLink(_ url: URL, key: String) async throws -> String {
if let importFailure { throw importFailure }
links.append(url)
+ linkKeys.append(key)
return "job-\(links.count)"
}
@@ -614,6 +616,9 @@ import Testing
await rig.engine.run()
await rig.engine.run()
#expect(rig.cloud.links.count == 2)
+ // Both posts name the same item, so the cloud can tell a repeat from
+ // a new link.
+ #expect(rig.cloud.linkKeys == [item.id.uuidString, item.id.uuidString])
#expect(try #require(rig.ideas.inspiration.first).cloud?.fileName == "reel.mp4")
}