-
-
Notifications
You must be signed in to change notification settings - Fork 890
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added tableDownloadLimit entity to app database. - Extended capability query to also consider download limit app. - Extended capabilities list view for display of download limit availability. - Extended share detail user interface to mimic the web user interface for managing download limits. - Every time WebDAV properties of a file are retrieved, its associated download limits are removed and recreated. Housekeeping: - Outsourced NCShareDateCell into dedicated source code file. - Outsourced NCShareToggleCell into dedicated source code file. Notes: - In my first attempt I had a detail view in the download limit row of the advanced share options showing the remaining number of downloads. However, that required to inject and retain the download limit entity object into the complicated share table configuration object. That, in turn, results in inconsistent data state due to invalid and outdated references. To resolve those issues, the assembly of the advanced share options user interface needs some refactoring which appears to expansive at this point and I prefer to leave it as it is for now. Signed-off-by: Iva Horn <[email protected]>
- Loading branch information
Showing
19 changed files
with
781 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// SPDX-FileCopyrightText: Nextcloud GmbH | ||
// SPDX-FileCopyrightText: 2024 Iva Horn | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
import Foundation | ||
import NextcloudKit | ||
import RealmSwift | ||
|
||
/// | ||
/// Data model for storing information about download limits of shares. | ||
/// | ||
class tableDownloadLimit: Object { | ||
/// | ||
/// The number of downloads which already happened. | ||
/// | ||
@Persisted | ||
@objc dynamic var count: Int = 0 | ||
|
||
/// | ||
/// Total number of allowed downloas. | ||
/// | ||
@Persisted | ||
@objc dynamic var limit: Int = 0 | ||
|
||
/// | ||
/// The token identifying the related share. | ||
/// | ||
@Persisted(primaryKey: true) | ||
@objc dynamic var token: String = "" | ||
} | ||
|
||
extension NCManageDatabase { | ||
/// | ||
/// Create a new download limit object in the database. | ||
/// | ||
@discardableResult | ||
func createDownloadLimit(count: Int, limit: Int, token: String) throws -> tableDownloadLimit? { | ||
let downloadLimit = tableDownloadLimit() | ||
downloadLimit.count = count | ||
downloadLimit.limit = limit | ||
downloadLimit.token = token | ||
|
||
do { | ||
let realm = try Realm() | ||
|
||
try realm.write { | ||
realm.add(downloadLimit, update: .all) | ||
} | ||
} catch let error as NSError { | ||
NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not write to database: \(error)") | ||
} | ||
|
||
return downloadLimit | ||
} | ||
|
||
/// | ||
/// Delete an existing download limit object identified by the token of its related share. | ||
/// | ||
/// - Parameter token: The `token` of the associated ``Nextcloud/tableShare/token``. | ||
/// | ||
func deleteDownloadLimit(byShareToken token: String) throws { | ||
do { | ||
let realm = try Realm() | ||
|
||
try realm.write { | ||
let result = realm.objects(tableDownloadLimit.self).filter("token == %@", token) | ||
realm.delete(result) | ||
} | ||
} catch let error as NSError { | ||
NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not write to database: \(error)") | ||
} | ||
} | ||
|
||
/// | ||
/// Retrieve a download limit by the token of the associated ``Nextcloud/tableShare/token``. | ||
/// | ||
/// - Parameter token: The `token` of the associated ``tableShare``. | ||
/// | ||
func getDownloadLimit(byShareToken token: String) throws -> tableDownloadLimit? { | ||
do { | ||
let realm = try Realm() | ||
let predicate = NSPredicate(format: "token == %@", token) | ||
|
||
guard let result = realm.objects(tableDownloadLimit.self).filter(predicate).first else { | ||
return nil | ||
} | ||
|
||
return result | ||
} catch let error as NSError { | ||
NextcloudKit.shared.nkCommonInstance.writeLog("[ERROR] Could not access database: \(error)") | ||
} | ||
|
||
return nil | ||
} | ||
} |
Oops, something went wrong.