@capacitor/filesystem 1.0.6 → 4.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -103,6 +103,15 @@ import Foundation
103
103
  return try FileManager.default.attributesOfItem(atPath: fileUrl.path)
104
104
  }
105
105
 
106
+ func getType(from attr: [FileAttributeKey: Any]) -> String {
107
+ let fileType = attr[.type] as? String ?? ""
108
+ if fileType == "NSFileTypeDirectory" {
109
+ return "directory"
110
+ } else {
111
+ return "file"
112
+ }
113
+ }
114
+
106
115
  @objc public func rename(at srcURL: URL, to dstURL: URL) throws {
107
116
  try _copy(at: srcURL, to: dstURL, doRename: true)
108
117
  }
@@ -141,6 +150,8 @@ import Foundation
141
150
  switch directory {
142
151
  case "CACHE":
143
152
  return .cachesDirectory
153
+ case "LIBRARY":
154
+ return .libraryDirectory
144
155
  default:
145
156
  return .documentDirectory
146
157
  }
@@ -188,11 +188,29 @@ public class FilesystemPlugin: CAPPlugin {
188
188
 
189
189
  do {
190
190
  let directoryContents = try implementation.readdir(at: fileUrl)
191
- let directoryPathStrings = directoryContents.map {(url: URL) -> String in
192
- return url.lastPathComponent
191
+ let directoryContent = try directoryContents.map {(url: URL) -> [String: Any] in
192
+ let attr = try implementation.stat(at: url)
193
+ var ctime = ""
194
+ var mtime = ""
195
+
196
+ if let ctimeSeconds = (attr[.creationDate] as? Date)?.timeIntervalSince1970 {
197
+ ctime = String(format: "%.0f", ctimeSeconds * 1000)
198
+ }
199
+
200
+ if let mtimeSeconds = (attr[.modificationDate] as? Date)?.timeIntervalSince1970 {
201
+ mtime = String(format: "%.0f", mtimeSeconds * 1000)
202
+ }
203
+ return [
204
+ "name": url.lastPathComponent,
205
+ "type": implementation.getType(from: attr),
206
+ "size": attr[.size] as? UInt64 ?? 0,
207
+ "ctime": ctime,
208
+ "mtime": mtime,
209
+ "uri": fileUrl.absoluteString
210
+ ]
193
211
  }
194
212
  call.resolve([
195
- "files": directoryPathStrings
213
+ "files": directoryContent
196
214
  ])
197
215
  } catch {
198
216
  handleError(call, error.localizedDescription, error)
@@ -226,8 +244,8 @@ public class FilesystemPlugin: CAPPlugin {
226
244
  }
227
245
 
228
246
  call.resolve([
229
- "type": attr[.type] as? String ?? "",
230
- "size": attr[.size] as? UInt64 ?? "",
247
+ "type": implementation.getType(from: attr),
248
+ "size": attr[.size] as? UInt64 ?? 0,
231
249
  "ctime": ctime,
232
250
  "mtime": mtime,
233
251
  "uri": fileUrl.absoluteString
@@ -307,7 +325,9 @@ public class FilesystemPlugin: CAPPlugin {
307
325
  }
308
326
  do {
309
327
  try implementation.copy(at: fromUrl, to: toUrl)
310
- call.resolve()
328
+ call.resolve([
329
+ "uri": toUrl.absoluteString
330
+ ])
311
331
  } catch let error as NSError {
312
332
  handleError(call, error.localizedDescription, error)
313
333
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/filesystem",
3
- "version": "1.0.6",
3
+ "version": "4.0.0-beta.0",
4
4
  "description": "The Filesystem API provides a NodeJS-like API for working with files on the device.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "scripts": {
31
31
  "verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
32
- "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin && cd ..",
32
+ "verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
33
33
  "verify:android": "cd android && ./gradlew clean build test && cd ..",
34
34
  "verify:web": "npm run build",
35
35
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
@@ -45,10 +45,10 @@
45
45
  "publish:cocoapod": "pod trunk push ./CapacitorFilesystem.podspec --allow-warnings"
46
46
  },
47
47
  "devDependencies": {
48
- "@capacitor/android": "^3.0.0",
49
- "@capacitor/core": "^3.0.0",
48
+ "@capacitor/android": "next",
49
+ "@capacitor/core": "next",
50
50
  "@capacitor/docgen": "0.0.18",
51
- "@capacitor/ios": "^3.0.0",
51
+ "@capacitor/ios": "next",
52
52
  "@ionic/eslint-config": "^0.3.0",
53
53
  "@ionic/prettier-config": "~1.0.1",
54
54
  "@ionic/swiftlint-config": "^1.1.2",
@@ -61,7 +61,7 @@
61
61
  "typescript": "~4.1.5"
62
62
  },
63
63
  "peerDependencies": {
64
- "@capacitor/core": "^3.0.0"
64
+ "@capacitor/core": "next"
65
65
  },
66
66
  "prettier": "@ionic/prettier-config",
67
67
  "swiftlint": "@ionic/swiftlint-config",
@@ -79,5 +79,5 @@
79
79
  "publishConfig": {
80
80
  "access": "public"
81
81
  },
82
- "gitHead": "64df93225736e9dfad336562f5e53e5a2243052b"
82
+ "gitHead": "fd7db8285f72990522da0adc889514c9804b6dae"
83
83
  }